trace: add max_error to reject fused double-order clusters#37
Closed
nikolai-piskunov wants to merge 1 commit into
Closed
trace: add max_error to reject fused double-order clusters#37nikolai-piskunov wants to merge 1 commit into
nikolai-piskunov wants to merge 1 commit into
Conversation
Adds an optional `max_error` parameter to `trace()`: after the final polynomial fit, clusters whose residual RMS (in pixels) exceeds the threshold are discarded. A cluster that accidentally spans two separate orders cannot be followed by a single polynomial, so its RMS is large (~half the order separation) compared to a genuine trace (sub-pixel); this rejects such fused clusters. Ports the MAX_ERR keyword from the IDL REDUCE mark_orders, where it was introduced to handle closely-packed detectors (e.g. MOSAIC NIR) on which adjacent orders can merge into a single cluster at detector edges. - trace.trace(): new `max_error=None` parameter (disabled by default) - reduce.py Trace step: read `max_error` from config and pass through - schema.json / default settings.json: add `max_error` (default null) - tests: TestMaxError covering disabled, generous, tiny, and a fused high-RMS cluster being dropped while a clean order survives Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This comment was marked as spam.
This comment was marked as spam.
Owner
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.
Summary
Adds an optional
max_errorparameter totrace(). After the final polynomial fit, any cluster whose residual RMS (in pixels) exceedsmax_erroris discarded.The motivation is closely-packed detectors where two adjacent spectral orders can be merged into a single cluster (typically at detector edges, where the gap between orders closes up). Such a fused cluster cannot be followed by a single polynomial, so its fit RMS is large — on the order of half the order separation — whereas a genuine single-order trace fits to sub-pixel RMS. Thresholding on the fit RMS cleanly rejects the fused clusters while leaving real orders untouched.
This ports the
MAX_ERRkeyword from the IDL REDUCEmark_orders, where it was added for exactly this case (e.g. MOSAIC NIR, ~5 px median order spacing).It is disabled by default (
max_error=None), so existing reductions are unaffected.Changes
trace.trace(): newmax_error=Noneparameter; reject clusters with fit RMS above it (logged when any are dropped).reduce.pyTracestep: readmax_errorfrom config (defaults toNone) and pass it through.instruments/defaults/schema.jsonanddefaults/settings.json: addmax_error(defaultnull).test/test_trace.py:TestMaxError— disabled / generous / tiny thresholds, plus a fused high-RMS cluster being dropped while a clean order survives.Notes
While porting I checked the other order-tracing improvements from the IDL side and found PyReduce already covers them: the 90 % overlap auto-merge guard (
auto_merge_threshold), degree-2 fitting before merge (degree_before_merge), and gap handling indetermine_overlap_rating. numpy's SVD-basedlstsqis also robust to the polynomial conditioning that needed an explicit basis rescale in IDL — verified noRankWarningand identical coefficients at degree 4 over 4096 columns. Somax_erroris the one genuinely new piece.Testing
pytest test/test_trace.pyandtest/test_configuration.pypass (66 trace tests including the 4 new ones; config tests confirm the default settings still validate against the schema).🤖 Generated with Claude Code