Skip to content

Commit

Permalink
Merge pull request #897 from mperrin/enhance_868_nrs_aper_pas
Browse files Browse the repository at this point in the history
Update NIRSpec aperture PAs
  • Loading branch information
obi-wan76 authored Aug 7, 2024
2 parents cab6ef4 + f1679be commit 9244107
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions webbpsf/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def test_calc_datacube_fast():
def test_mode_switch():
"""Test switch between IFU and imaging modes"""
nrs = webbpsf_core.NIRSpec()
nrs_default_v3pa = nrs._rotation
# check mode swith to IFU
nrs.mode = 'IFU'
assert 'IFU' in nrs.aperturename
assert nrs.band == 'PRISM/CLEAR'
assert nrs.image_mask is None
assert nrs._rotation != nrs_default_v3pa

# check switch of which IFU band
nrs.disperser = 'G395H'
Expand All @@ -75,6 +77,7 @@ def test_mode_switch():
# check mode switch back to imaging
nrs.mode = 'imaging'
assert 'IFU' not in nrs.aperturename
assert nrs._rotation == nrs_default_v3pa


def test_IFU_wavelengths():
Expand All @@ -91,3 +94,23 @@ def test_IFU_wavelengths():
# and test we can specify a reduced wavelength sampling:
for n in (10, 100):
assert len(nrs.get_IFU_wavelengths(n)) == n


def test_aperture_rotation_updates():
""" Test that switching detector or aperture updates the aperture PA
(this is a tiny detail)"""
nrs = webbpsf_core.NIRSpec()
pa_nrs1_full = nrs._rotation

# changing aperture updates PA
nrs.set_position_from_aperture_name('NRS_S200A1_SLIT')
assert nrs._rotation != pa_nrs1_full

# change back to original aperture
nrs.set_position_from_aperture_name('NRS1_FULL')
assert nrs._rotation == pa_nrs1_full

# changing detector should update aperturename and also update PA
nrs.detector = 'NRS2'
assert nrs.aperturename == 'NRS2_FULL'
assert nrs._rotation != pa_nrs1_full
16 changes: 16 additions & 0 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,9 @@ def aperturename(self, value):
self.image_mask = None
else:
self._mode = 'imaging' # More to implement here later!
# Update the rotation angle
# This works the same for both regular and IFU modes
self._rotation = self._get_aperture_rotation(self.aperturename)

def _tel_coords(self):
"""Convert from science frame coordinates to telescope frame coordinates using
Expand Down Expand Up @@ -3356,6 +3359,19 @@ def _get_pixelscale_from_apername(self, apername):
else:
return super()._get_pixelscale_from_apername(apername)

def _get_aperture_rotation(self, apername):
"""Get the rotation angle of a given aperture, using values from SIAF.
Returns ~ position angle counterclockwise from the V3 axis, in degrees
(i.e. SIAF V3IdlYangle)
For NIRSpec this is simple, since even the SLIT type apertures have
V3IdlYAngle values defined. And we don't have the complexity of
COMPOUND type apertures that MIRI has to deal with.
"""
return self.siaf[apername].V3IdlYAngle

@property
def disperser(self):
"""NIRSpec spectral dispersing element (grating or prism).
Expand Down

0 comments on commit 9244107

Please sign in to comment.