Skip to content
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

Support MIRI LRS slit in aperturename and setup_sim_to_match_file functions #781

Merged
merged 1 commit into from
Dec 22, 2023

Conversation

mperrin
Copy link
Collaborator

@mperrin mperrin commented Dec 22, 2023

I encountered a bug when trying to use setup_sim_to_match_file with a MIRI LRS observation, using SIAF aperture name 'MIRIM_SLIT'. This is a SLIT-type SIAF aperture, which defines V2,V3 coordinates but does not specify a particular set of detector coordinates or subarray (it's read out using the MIRIM full array). You can also reproduce this bug simply with:

webbpsf.MIRI().set_position_from_aperture_name('MIRIM_SLIT')

The necessary code for handling this kind of aperture was previously only present in the NIRSpec class, which has several slit apertures. I'd missed that MIRI SIAF also uses this for the LRS.

This PR refactors the code from the NIRSpec class aperturename and _tel_coords functions, moving it up to the JWInstrument class and generalizing it to work on any slit aperture for any instrument.

Overall this PR actually makes the code shorter and simpler (more deleted lines than added lines!), which is pretty satisfying.

@mperrin mperrin self-assigned this Dec 22, 2023
@mperrin mperrin requested a review from obi-wan76 December 22, 2023 00:52
@mperrin mperrin added bug Something isn't working JWST Affects JWST models in WebbPSF labels Dec 22, 2023
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (b45e76f) 54.52% compared to head (a89a0ea) 54.50%.
Report is 9 commits behind head on develop.

Files Patch % Lines
webbpsf/webbpsf_core.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #781      +/-   ##
===========================================
- Coverage    54.52%   54.50%   -0.03%     
===========================================
  Files           16       16              
  Lines         6560     6552       -8     
===========================================
- Hits          3577     3571       -6     
+ Misses        2983     2981       -2     

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

Copy link
Collaborator

@obi-wan76 obi-wan76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I reproduced the original bug
`TypeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 webbpsf.MIRI().set_position_from_aperture_name('MIRIM_SLIT')

File ~/webbpsf_issues_726_736/webbpsf/webbpsf_core.py:981, in JWInstrument.set_position_from_aperture_name(self, aperture_name)
978 detname = aperture_name.split('_')[0]
979 self.detector = detname # As a side effect this auto reloads SIAF info, see detector.setter
--> 981 self.aperturename = aperture_name
983 if self.name != 'NIRSpec' and ap.AperType != 'SLIT':
984 # Regular imaging apertures, so we can just look up the reference coords directly
985 self.detector_position = (ap.XSciRef, ap.YSciRef) # set this AFTER the SIAF reload

File ~/webbpsf_issues_726_736/webbpsf/webbpsf_core.py:937, in JWInstrument.aperturename(self, value)
935 self._aperturename = value
936 # Update detector reference coordinates
--> 937 self.detector_position = (ap.XSciRef, ap.YSciRef)
939 # Update DetectorGeometry class
940 self._detector_geom_info = DetectorGeometry(self.siaf, self._aperturename)

File ~/webbpsf_issues_726_736/webbpsf/webbpsf_core.py:301, in SpaceTelescopeInstrument.detector_position(self, position)
298 @detector_position.setter
299 def detector_position(self, position):
300 try:
--> 301 x, y = map(int, position)
302 except ValueError:
303 raise ValueError("Detector pixel coordinates must be pairs of nonnegative numbers, not {}".format(position))

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
This PR addressed this issue with no errors and the test functions returns True for both V2/V3 fortel_coords`, that they are the same.

@obi-wan76 obi-wan76 merged commit 208ab22 into spacetelescope:develop Dec 22, 2023
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working JWST Affects JWST models in WebbPSF
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants