diff --git a/changes/9102.assign_wcs.rst b/changes/9102.assign_wcs.rst new file mode 100644 index 0000000000..8fcfafae44 --- /dev/null +++ b/changes/9102.assign_wcs.rst @@ -0,0 +1 @@ +Fix crash in transform from MSA to detector coordinates for NIRSpec imaging WCS with filter=OPAQUE. diff --git a/jwst/assign_wcs/nirspec.py b/jwst/assign_wcs/nirspec.py index 2fd86ee1bb..4398b9c122 100644 --- a/jwst/assign_wcs/nirspec.py +++ b/jwst/assign_wcs/nirspec.py @@ -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 @@ -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), diff --git a/jwst/assign_wcs/tests/test_nirspec.py b/jwst/assign_wcs/tests/test_nirspec.py index fc7a7032c3..95d6002148 100644 --- a/jwst/assign_wcs/tests/test_nirspec.py +++ b/jwst/assign_wcs/tests/test_nirspec.py @@ -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 @@ -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): """