Single shared mask-condition grammar (masks.py + cosmo_inference)#230
Open
cailmdaley wants to merge 2 commits into
Open
Single shared mask-condition grammar (masks.py + cosmo_inference)#230cailmdaley wants to merge 2 commits into
cailmdaley wants to merge 2 commits into
Conversation
…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
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GPnbTHcheLscjVjnPdC6AH
LisaGoh
approved these changes
Jul 8, 2026
LisaGoh
left a comment
Member
There was a problem hiding this comment.
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #181 (as rescoped in this comment).
The object-selection
Maskclass and Lisa's cosmo_inference footprint builder parse the same YAML mask-config format through two independently-written condition evaluators whosekindvocabularies had diverged (smaller_equalvsless_equal;greater/lessonly 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 bothkindvocabularies, withsmaller_equalkept as an alias forless_equalso all existing configs (config/calibration/mask_v1.X.{3,9,10,11}.yamlare 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 (numexprremoved frompyproject.toml; it had no other consumers).cosmo_inference/scripts/masking.pyimports the shared evaluator; its local copy is deleted.src/sp_validation/tests/test_masks.py: all 7 kinds, the alias, unknown-kindValueError, and aMask-vs-apply_conditionequivalence 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