Skip to content

Fix fractional scatter height with duplicated traces; re-enable scatter for HARPSPOL - #40

Open
astro-alexis wants to merge 3 commits into
ivh:masterfrom
astro-alexis:scatter-spacing-distinct-traces
Open

Fix fractional scatter height with duplicated traces; re-enable scatter for HARPSPOL#40
astro-alexis wants to merge 3 commits into
ivh:masterfrom
astro-alexis:scatter-spacing-distinct-traces

Conversation

@astro-alexis

Copy link
Copy Markdown
Contributor

Follow-up to #38 and the scatter work on master. Short version: the #39 conclusion that scatter is unusable for HARPSPOL reproduces exactly, but the cause was neither the method nor extraction_height — it was a spacing defect that silently disabled trace masking. With it fixed, the step lands where scatter.md says it should.

The defect

estimate_background_scatter resolves a fractional extraction_height against the median separation between adjacent traces. Trace.run stores grouped + raw_traces (steps/trace.py:135), so on an instrument with a fibers block every trace appears twice — and where a group holds a single fiber, the merged and raw polynomials are identical. HARPSPOL blue: 90 physical traces, 180 stored.

Half the adjacent separations are then exactly 0, so the median is 0, xwd becomes 0, half = 0, height = 0, and the aperture masks nothing. The polynomial is fitted to the order flux itself.

HARPS, UVES, XSHOOTER and LICK_APF have no fibers block, so they never duplicate traces — which is why the four-instrument validation didn't surface this.

Evidence

γ Equ (HD 201601), 2012-07-16, BLUE, one frame, 90 traces. Mid-gap diagnostic from scatter.md (model ÷ the frame's own inter-order floor):

extraction_height before after (blue) after (red)
0.2 8.89x 7.11x 5.32x
0.5 8.89x 1.28x 1.14x
0.7 8.89x 1.18x 1.02x
1.0 8.89x 1.35x 0.95x

The flatness before the fix is the signature — height had no effect because masking never happened. End-to-end:

median flux negative points
no scatter 2027.8 0.13%
scatter, before 621.8 27.30%
scatter, after 1988.5 0.41%

That first row pair is the #39 symptom: 69% of the flux gone, a quarter of points negative, insensitive to height.

Changes

  • estimate_background_scatter: measure spacing from non-zero separations; warn instead of silently using the 10 px fallback.
  • test_scatter.py: regression test, verified to fail without the fix (28.0 vs 10.0).
  • HARPSPOL: scatter restored to get_expected_values and settings.json at extraction_height: 0.7.

Full unit suite passes (748, 1 skip for numba).

Note

The duplication is general, not HARPSpol-specific — any fiber instrument whose groups hold a single fiber will store every trace twice. This PR makes the scatter fit robust to it rather than changing what Trace.run saves, since the concatenation is deliberate and other steps rely on _select_traces. Worth a separate look at whether ANDES/MOSAIC hit anything else through the same path.

🤖 Generated with Claude Code

alexis and others added 2 commits August 5, 2026 09:48
A fractional extraction_height is resolved against the median separation
between adjacent traces. Trace.run stores `grouped + raw_traces`, so on an
instrument with a fibers block every trace appears twice, and where a group
holds a single fiber the two copies carry identical polynomials. Half the
adjacent separations are then exactly 0, so the median is 0 and the aperture
collapses to zero height: no trace is masked, and the polynomial is fitted to
the order flux itself.

On HARPSPOL blue this put the model 8.9x above the frame's own inter-order
floor, identically at every extraction_height from 0.2 to 1.0 -- the
insensitivity to height being the visible symptom. Extracted flux came out at
621.8 against 2027.8 uncorrected, with 27.3% of points negative; after the fix,
1988.5 and 0.41%.

Ignore zero separations, and warn rather than silently falling back to a 10 px
aperture. HARPS, UVES, XSHOOTER and LICK_APF have no fibers block, so they
never duplicate traces and none of them were affected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ivh#38 dropped the scatter block and the scatter entry in get_expected_values, on
the evidence that the step removed most of the stellar flux at every height
tried. That measurement was taken with the pre-b6258b2 method (model fitted on
LAMP,LAMP,TUN and subtracted unscaled) and with the spacing defect fixed in the
previous commit, which disabled trace masking altogether.

With both addressed, the mid-gap diagnostic from scatter.md gives model/floor
of 1.18x on blue and 1.02x on red at 0.7 of the order spacing, from a sweep
over 0.2 to 1.0 on gamma Equ (HD 201601, 2012-07-16). HARPS lands at 1.33x for
comparison.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@07dcb47). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pyreduce/estimate_background_scatter.py 80.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff            @@
##             master      #40   +/-   ##
=========================================
  Coverage          ?   57.66%           
=========================================
  Files             ?       58           
  Lines             ?     8991           
  Branches          ?        0           
=========================================
  Hits              ?     5185           
  Misses            ?     3806           
  Partials          ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The [Unreleased] entry still said the HARPSPOL scatter step was withdrawn,
which the previous two commits reverse.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants