Skip to content

Commit 112ccc7

Browse files
Update tests to always define forward transform and a full coordinate frame for GWCS
1 parent 8f77fc5 commit 112ccc7

File tree

7 files changed

+78
-8
lines changed

7 files changed

+78
-8
lines changed

jwst/assign_wcs/tests/test_wfss.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import numpy as np
22
import pytest
3+
from astropy import units as u
4+
from astropy.coordinates import ICRS
35
from astropy.modeling.models import Const1D, Mapping, Polynomial1D, Polynomial2D, Shift
46
from gwcs import wcs
7+
from gwcs.coordinate_frames import CelestialFrame, CompositeFrame, Frame2D, SpectralFrame
58
from gwcs.wcstools import grid_from_bounding_box
69
from numpy.testing import assert_allclose
710
from stdatamodels.jwst.datamodels import SlitModel
@@ -21,7 +24,16 @@ def create_nircam_slit(model, x0, y0, order):
2124
| (Shift(xmin) & Shift(ymin) & Const1D(x0) & Const1D(y0) & Const1D(order))
2225
| model
2326
)
24-
wcsobj = wcs.WCS([("det", model), ("world", None)])
27+
detector = Frame2D(name="detector")
28+
# Note there is a "non-coordinate" output from the model.
29+
world = CompositeFrame(
30+
[
31+
CelestialFrame(name="sky", axes_order=(0, 1), reference_frame=ICRS()),
32+
SpectralFrame(name="spectral", axes_order=(2,), unit=(u.um,)),
33+
],
34+
name="world",
35+
)
36+
wcsobj = wcs.WCS([(detector, model), (world, None)])
2537
wcsobj.bounding_box = ((20, 25), (800, 805))
2638
slit = SlitModel()
2739
slit.meta.wcs = wcsobj
@@ -39,7 +51,16 @@ def create_niriss_slit(model, x0, y0, order):
3951
| (Shift(xmin) & Shift(ymin) & Const1D(x0) & Const1D(y0) & Const1D(order))
4052
| model
4153
)
42-
wcsobj = wcs.WCS([("det", model), ("world", None)])
54+
detector = Frame2D(name="detector")
55+
# Note there is a "non-coordinate" output from the model.
56+
world = CompositeFrame(
57+
[
58+
CelestialFrame(name="sky", axes_order=(0, 1), reference_frame=ICRS()),
59+
SpectralFrame(name="spectral", axes_order=(2,), unit=(u.um,)),
60+
],
61+
name="world",
62+
)
63+
wcsobj = wcs.WCS([(detector, model), (world, None)])
4364
slit = SlitModel()
4465
slit.meta.wcs = wcsobj
4566
slit.source_xpos = x0

jwst/datamodels/tests/test_library.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import pytest
77
import stdatamodels.jwst.datamodels
8+
from astropy.modeling.models import Identity
89
from astropy.time import Time
910
from gwcs import coordinate_frames as cf
1011
from stdatamodels.jwst.datamodels import ImageModel
@@ -274,7 +275,9 @@ def test_read_meta_from_open_model(example_asn_path, flatten):
274275
model.int_list = [1, 2, 3, 4]
275276
model.nested_list = [[{"key": "value"}], [{"key2": "value2"}]] * 2
276277
model.meta.wcs = gwcs.WCS(
277-
input_frame=cf.Frame2D(name="input"), output_frame=cf.Frame2D(name="output")
278+
input_frame=cf.Frame2D(name="input"),
279+
output_frame=cf.Frame2D(name="output"),
280+
forward_transform=Identity(2),
278281
)
279282
model.unsupported_type = set([1, 2, 3])
280283
meta = _read_meta_from_open_model(model, flatten)

jwst/extract_1d/tests/test_source_location.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gwcs
22
import numpy as np
33
import pytest
4+
from astropy import units as u
45
from astropy.modeling.models import Identity, Scale
56

67
from jwst.extract_1d import source_location as sl
@@ -288,7 +289,20 @@ def test_nod_pair_location_miri(mock_miri_lrs_fs, dispaxis):
288289

289290
# mock v2v3 transform
290291
model.meta.wcs = gwcs.WCS(
291-
[model.meta.wcs.pipeline[0], ("v2v3", Identity(3)), model.meta.wcs.pipeline[1]]
292+
[
293+
model.meta.wcs.pipeline[0],
294+
(
295+
gwcs.CompositeFrame(
296+
[
297+
gwcs.Frame2D(name="frame", axes_order=(0, 1)),
298+
gwcs.SpectralFrame(name="lambda", axes_order=(2,), unit=(u.um,)),
299+
],
300+
name="v2v3",
301+
),
302+
Identity(3),
303+
),
304+
model.meta.wcs.pipeline[1],
305+
]
292306
)
293307
model.meta.wcsinfo.v3yangle = 1.0
294308
model.meta.wcsinfo.v2_ref = 1.0

jwst/lib/tests/test_wcs_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ def test_get_wavelengths_soss():
9999

100100
# mock a SOSS wcs
101101
soss_transform = NirissSOSSModel([1], [model.meta.wcs])
102-
new_wcs = wcs.WCS([("detector", soss_transform), ("world", None)])
102+
detector = cf.Frame2D(name="detector")
103+
world = cf.CompositeFrame(
104+
[
105+
cf.CelestialFrame(name="icrs", axes_order=(0, 1), reference_frame=coord.ICRS()),
106+
cf.SpectralFrame(
107+
name="spectral", axes_order=(2,), unit=(u.micron,), axes_names=("wavelength",)
108+
),
109+
],
110+
name="world",
111+
)
112+
new_wcs = wcs.WCS([(detector, soss_transform), (world, None)])
103113
model.meta.wcs = new_wcs
104114

105115
# calculate what the wavelength array should be

jwst/pixel_replace/tests/test_pixel_replace.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from glob import glob
33

4+
import astropy.units as u
45
import gwcs
56
import numpy as np
67
import pytest
@@ -128,8 +129,14 @@ def miri_mrs():
128129

129130
# Mock a wcs that just returns 1 for alpha, beta, lam
130131
transform = Mapping((0, 1, 1), n_inputs=2) | Const1D(1) & Const1D(1) & Const1D(1)
131-
model.meta.wcs = gwcs.WCS([("detector", transform), ("alpha_beta", None)])
132-
132+
output_frame = gwcs.CompositeFrame(
133+
[
134+
gwcs.Frame2D(name="alpha_beta_spatial", axes_order=(0, 1), unit=(u.arcsec, u.arcsec)),
135+
gwcs.SpectralFrame(name="lam", axes_order=(2,), unit=(u.um,)),
136+
],
137+
name="alpha_beta",
138+
)
139+
model.meta.wcs = gwcs.WCS([(gwcs.Frame2D(name="detector"), transform), (output_frame, None)])
133140
return model, bad_idx
134141

135142

jwst/residual_fringe/tests/test_residual_fringe.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gwcs
22
import numpy as np
33
import pytest
4+
from astropy import units as u
45
from astropy.modeling.models import Const1D, Identity, Mapping
56
from stdatamodels.jwst import datamodels
67

@@ -260,7 +261,21 @@ def test_get_wavemap():
260261

261262
# Mock a WCS that returns 1 for wavelengths
262263
transform = Mapping((0, 1, 1), n_inputs=2) | Identity(2) & Const1D(1)
263-
model.meta.wcs = gwcs.WCS([("detector", transform), ("world", None)])
264+
model.meta.wcs = gwcs.WCS(
265+
[
266+
(gwcs.Frame2D(name="detector"), transform),
267+
(
268+
gwcs.CompositeFrame(
269+
[
270+
gwcs.Frame2D(name="sky0", axes_order=(0, 1)),
271+
gwcs.SpectralFrame(name="spectral", axes_order=(2,), unit=u.micron),
272+
],
273+
name="world",
274+
),
275+
None,
276+
),
277+
]
278+
)
264279

265280
rf = ResidualFringeCorrection(model, "N/A", "N/A", None)
266281
wavemap = rf._get_wave_map()
2.15 KB
Binary file not shown.

0 commit comments

Comments
 (0)