Skip to content

Commit

Permalink
Fix msa frame transform for opaque images (#9102)
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke authored Jan 29, 2025
2 parents d95188f + bd46fad commit 4f43822
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/9102.assign_wcs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash in transform from MSA to detector coordinates for NIRSpec imaging WCS with filter=OPAQUE.
7 changes: 5 additions & 2 deletions jwst/assign_wcs/nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def imaging(input_model, reference_files):

lam = wrange[0] + (wrange[1] - wrange[0]) * .5

# Scale wavelengths to microns if msa coordinates are terminal
if input_model.meta.instrument.filter == 'OPAQUE':
lam *= 1e6

lam_model = Mapping((0, 1, 1)) | Identity(2) & Const1D(lam)

gwa2msa = gwa_through | rotation | dircos2unitless | col | lam_model
Expand Down Expand Up @@ -148,8 +152,7 @@ def imaging(input_model, reference_files):
(v2v3vacorr, tel2sky),
(world, None)]
else:
# convert to microns if the pipeline ends earlier
gwa2msa = (gwa2msa | Identity(2) & Scale(1e6)).rename('gwa2msa')
# Pipeline ends with MSA coordinates
imaging_pipeline = [(det, dms2detector),
(sca, det2gwa),
(gwa, gwa2msa),
Expand Down
39 changes: 37 additions & 2 deletions jwst/assign_wcs/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def create_reference_files(datamodel):
return refs


def create_nirspec_imaging_file():
def create_nirspec_imaging_file(filter_name='F290LP'):
image = create_hdul()
image[0].header['exp_type'] = 'NRS_IMAGE'
image[0].header['filter'] = 'F290LP'
image[0].header['filter'] = filter_name
image[0].header['grating'] = 'MIRROR'
image[0].header['lamp'] = 'NONE'

return image


Expand Down Expand Up @@ -162,6 +164,39 @@ def test_nirspec_imaging():
# Test evaluating the WCS
im.meta.wcs(1, 2)

# Test that the MSA to detector transforms can be retrieved
det2msa = im.meta.wcs.get_transform('detector', 'msa')
result = det2msa(1.0, 2.0)
assert len(result) == 3

msa2det = im.meta.wcs.get_transform('msa', 'detector')
result = msa2det(1.0, 2.0)
assert len(result) == 2


def test_nirspec_imaging_opaque():
"""Test NIRSpec Imaging mode with OPAQUE filter."""
f = create_nirspec_imaging_file(filter_name='OPAQUE')
im = datamodels.ImageModel(f)

# Test creating the WCS
refs = create_reference_files(im)
pipe = nirspec.create_pipeline(im, refs, slit_y_range=[-.5, .5])
w = wcs.WCS(pipe)
im.meta.wcs = w

# Test evaluating the WCS
im.meta.wcs(1, 2)

# Test that the MSA to detector transforms can be retrieved
det2msa = im.meta.wcs.get_transform('detector', 'msa')
result = det2msa(1.0, 2.0)
assert len(result) == 3

msa2det = im.meta.wcs.get_transform('msa', 'detector')
result = msa2det(1.0, 2.0)
assert len(result) == 2


def test_nirspec_ifu_against_esa(wcs_ifu_grating):
"""
Expand Down

0 comments on commit 4f43822

Please sign in to comment.