-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix METIS IFU mode #391
base: main
Are you sure you want to change the base?
Fix METIS IFU mode #391
Conversation
I recently got an error from an ID that was 1.0 (float). Not sure where it came from, but this will catch it.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev_master #391 +/- ##
===========================================
Coverage 74.92% 74.92%
===========================================
Files 56 56
Lines 7777 7781 +4
===========================================
+ Hits 5827 5830 +3
- Misses 1950 1951 +1 ☔ View full report in Codecov by Sentry. |
Requires AstarVienna/irdb#165 to fully work... |
Coverage is complaining, because many of the changes here only happen in non-ordinary (mostly untested) conditions... |
@@ -307,8 +315,7 @@ def fov_grid(self): | |||
y_min = aperture["bottom"] | |||
y_max = aperture["top"] | |||
|
|||
filename_det_layout = from_currsys("!DET.layout.file_name", cmds=self.cmds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah here you introduced the bug that you then fixed in AstarVienna/irdb#165 . We can merge that one if we also merge this one. Let me review the rest of this PR first though
self.meta = self._class_params | ||
self.meta.update(kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this copy()
seems rather dangerous, as now any instance of MetisLMSEfficiency
can change the values of other instances. E.g.:
from scopesim.effects.metis_lms_trace_list import MetisLMSEfficiency
eff1 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits")
print(f"{eff1.meta['eff_max']=}")
eff2 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits", eff_max=42)
print(f"{eff2.meta['eff_max']=}")
print(f"{eff1.meta['eff_max']=}")
eff3 = MetisLMSEfficiency(wavelen=4.2, filename="METIS/TRACE_LMS.fits")
print(f"{eff3.meta['eff_max']=}")
will print
eff1.meta['eff_max']=0.75
eff2.meta['eff_max']=42
eff1.meta['eff_max']=42
eff3.meta['eff_max']=42
is that intentional?
# HACK: Somehow we end up with duplicate keywords here. This hack | ||
# should not be necessary at all! Investigate what's really | ||
# going on... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe because you removed the copy()
in __init__()
? You directly set self.meta = self._class_params
, which means that all MetisLMSEfficiency
instances share the same .meta
.
Just guessing. And since I'm already started with 'single comments', I'll keep doing that :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main request for changes is the removal of the copy()
. If that change was intentional, then please add a comment why no copy is necessary, otherwise I will probably forget that and add the copy back in at some later date assuming it should have been there. If the removal of the copy()
was not on purpose, than I suggest adding it back in.
Other than that, my philosophy is that "Exceptions are for exceptional circumstances"; so I personally lean more toward returning errors than raising exceptions, but maybe I should change my mind on that.
I'm starting to question what I was fixing here in the first place. Like, I'm certain there were some errors related to unresolved bang-strings for the layout filename or something like that. Which is how the whole |
I think that change might have slipped in from another branch where I did some cmds/meta/params stuff. I'll revert that here and see if it solves the duplicate keyword thingy... |
Got a few errors when attempting to run the new
laser_spectrum
andpinhole_mask
through thelms
(aka IFU?) mode. This, together with the IRDB counterpart, makes it work and the output looks promising.Short explanation on those new exceptions:
When I initially ran the simulation, I got weird errors which I ultimately traced down to a less-than-optimal handling of "Spectral trace outside FOV". Now the trace being outside the FOV was a symptom of something else (wrong detector layout), but that shouldn't have stopped the simulation as a whole (the erroneous layout basically mimicked a
DetecorWindow
, and that's supposed to work...). However the functionmap_spectra_to_focal_plane()
just logged a warning/info and thenreturn None
(instead of a HDU), while the calling function had no way of handling this (unexpected but not impossible)None
value, so it subsequently failed attempting to access the supposed HDU's attributes. Since I figured it would be fine to just "skip" a trace if it's outside the final FOV anyway, I added the new exceptions as a way for the calling function to deal with unexpected (but not catastrophic) behavior of the lower level. This also has the benefits of a)map_spectra_to_focal_plane()
always returns a HDU or raises an exception, but never silently returnsNone
; b) allows different treatment of different fail conditions if required (currently just handles the base exception).All of this might also just be another symptom of the split between "normal" spectral traces and the "special" METIS classes.