Rectify now accepts str and HDUList + stop mangling METISLMSSPectralTrace params dict - #985
Open
astronomyk wants to merge 3 commits into
Open
Rectify now accepts str and HDUList + stop mangling METISLMSSPectralTrace params dict#985astronomyk wants to merge 3 commits into
str and HDUList + stop mangling METISLMSSPectralTrace params dict#985astronomyk wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #985 +/- ##
==========================================
+ Coverage 76.46% 77.09% +0.62%
==========================================
Files 69 69
Lines 9025 9027 +2
==========================================
+ Hits 6901 6959 +58
+ Misses 2124 2068 -56 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
str and HDUList + stop mangling 'METISLMSSPectralTrace' params dict
str and HDUList + stop mangling 'METISLMSSPectralTrace' params dictstr and HDUList + stop mangling METISLMSSPectralTrace params dict
astronomyk
marked this pull request as ready for review
August 24, 2026 13:44
Contributor
|
What practical issues did this cause? |
oczoske
reviewed
Aug 24, 2026
| self._xilamimg = xilam # ..todo: remove or make available with a debug flag? | ||
| except ValueError: | ||
| logger.warning(" ---> %s gave ValueError", self.trace_id) | ||
| return None |
Collaborator
There was a problem hiding this comment.
I think this was a debugging thing. The idea was to see all cases where a trace gave a ValueError. If we want to finish on the first one, we can simply remove the try...except.
Collaborator
Author
There was a problem hiding this comment.
I'd be happy with simply removing the try/except, as that forces it to fail loudly... right?
Both methods accept a filename or an HDUList and open the file into inhdul, but then handed the original argument to make_image_interpolations and SpectralTrace.rectify. With a filename this crashed (a str cannot be indexed as an HDUList); with an in-memory HDUList it happened to work, masking the bug. Use inhdul consistently after opening. Adds a regression test that feeds a filename through rectify_traces and asserts the traces receive the opened HDUList.
A ValueError raised while building the XiLamImage was caught and logged, but execution then continued with the unbound local variable, turning the handled error into a NameError. Return None instead, which callers already handle (the same contract as the footprint-outside-FoV and empty-footprint paths). Adds a unit test that simulates the failure.
MetisLMSSpectralTraceList passes params=self.meta by reference; each trace then updated that dict with its slice-specific values (slice, aperture_id, plus any construction kwargs). After building 28 traces the list's own meta carried the values of whichever slice was built last, and traces could see each other's entries. Copy the dict at the constructor boundary. Adds a regression test asserting the caller's dict is unchanged.
astronomyk
force-pushed
the
fix/spectral-trace-robustness
branch
from
August 24, 2026 14:46
000aad3 to
ae14246
Compare
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.
Human-readbale summary:
Bug 1:
rectify_cube()andtraces()ignore their own checks forfilenameorHDUListat the top of the functions.Bug 2:
map_spectra_to_focal_planecontinues even when chucking an error on aXiLamImagecall. Fails again two lines later (line 235) onxilam_wcs = xilam.wcsBug 3: Copy of params dict, to avoid altering the original contents of the dict being passed to the function
For more information, see the toaster's explanation below the line. But I think the code changes are more informative anyway
Three independent, few-line fixes, kept as separate commits for review:
1.
rectify_traces/rectify_cubecrash when given a filenameBoth methods document accepting "str or fits.HDUList" and open the file into
inhdul— but then passed the original argument on tomake_image_interpolations()andSpectralTrace.rectify(). With a filename this raisedAttributeError: 'str' object has no attribute 'header'; with an in-memory HDUList it happened to work, masking the bug. Nowinhdulis used consistently after opening.2.
map_spectra_to_focal_planeturned a handled error into a NameErrorA
ValueErrorraised while building theXiLamImagewas caught and logged, but execution then continued with the unbound local variable:The method now returns
None— the same "no contribution from this trace" contract as the footprint-outside-FoV and empty-footprint paths, which all callers already handle.3.
MetisLMSSpectralTracewrote into the trace list's meta dictMetisLMSSpectralTraceList.make_spectral_tracespassesparams=self.metaby reference to each of the 28 slice traces; each trace then updated that shared dict with its slice-specific values (slice,aperture_id, plus construction kwargs). After building all traces the list's meta carried whichever slice came last. The constructor now copies the dict at the boundary.Testing
One regression test per fix:
TestRectifyTracesInput::test_rectify_traces_opens_filename_before_useTestMapSpectraErrorPath::test_returns_none_when_xilamimage_failsTestMetisLMSSpectralTraceInit::test_does_not_mutate_caller_paramsNotebooks demonstrating each fix on the METIS IRDB (including the full LSS observe→readout→rectify-from-file chain for fix 1) are attached below.