Skip to content

Single shared mask-condition grammar (masks.py + cosmo_inference)#230

Open
cailmdaley wants to merge 2 commits into
developfrom
refactor/shared-mask-condition-grammar
Open

Single shared mask-condition grammar (masks.py + cosmo_inference)#230
cailmdaley wants to merge 2 commits into
developfrom
refactor/shared-mask-condition-grammar

Conversation

@cailmdaley

Copy link
Copy Markdown
Collaborator

Closes #181 (as rescoped in this comment).

The object-selection Mask class and Lisa's cosmo_inference footprint builder parse the same YAML mask-config format through two independently-written condition evaluators whose kind vocabularies had diverged (smaller_equal vs less_equal; greater/less only in cosmo_inference). This PR gives them one grammar, leaving the object-space vs pixel-space split alone.

Changes

  • sp_validation.masks.apply_condition(array, kind, value) — single evaluator, union of both kind vocabularies, with smaller_equal kept as an alias for less_equal so all existing configs (config/calibration/mask_v1.X.{3,9,10,11}.yaml are the only users of the old spelling) keep working unchanged.
  • Mask.apply() delegates to it. Plain numpy instead of numexpr — single-comparison numexpr gains are marginal, and this drops a dependency (numexpr removed from pyproject.toml; it had no other consumers).
  • cosmo_inference/scripts/masking.py imports the shared evaluator; its local copy is deleted.
  • New src/sp_validation/tests/test_masks.py: all 7 kinds, the alias, unknown-kind ValueError, and a Mask-vs-apply_condition equivalence check (10 tests, pass in the container).

No config files were touched; no behavior change for any existing YAML.

— Fable on behalf of Cail

🤖 Generated with Claude Code

https://claude.ai/code/session_01GPnbTHcheLscjVjnPdC6AH

cailmdaley and others added 2 commits July 6, 2026 17:39
…ope)

Two independently-written YAML mask-condition evaluators had diverged:
Mask.apply() (numexpr, kinds equal/not_equal/greater_equal/smaller_equal/
range) and cosmo_inference/scripts/masking.py's local apply_condition
(plain numpy, kinds equal/not_equal/greater_equal/greater/less_equal/
less/range). Unify to one grammar in sp_validation.masks.apply_condition,
plain numpy (single-comparison numexpr gains are marginal; this drops a
dependency from the shared path). Mask.apply() now delegates to it.
cosmo_inference/scripts/masking.py imports the shared function instead of
carrying its own copy. "smaller_equal" is kept as an alias for
"less_equal" so existing calibration configs (mask_v1.X.{3,9,10,11}.yaml)
keep working unchanged.

Add src/sp_validation/tests/test_masks.py covering every kind, the
smaller_equal alias, the ValueError on unknown kind, and an equivalence
check between Mask.apply() and calling apply_condition directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GPnbTHcheLscjVjnPdC6AH

@LisaGoh LisaGoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for this! Just a suggestion, maybe masking.py should live in sp_validation/scripts instead, since it has a general use beyond purely for inference!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate masking

2 participants