Skip to content

Commit e1dd8c2

Browse files
committed
sort out determineDistortion() tests based on previous commit
1 parent 6b84e7b commit e1dd8c2

4 files changed

Lines changed: 78 additions & 41 deletions

File tree

geminidr/f2/tests/longslit/test_determine_distortion.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"nsum": 10,
3838
"spatial_order": 3,
3939
"spectral_order": 3,
40-
"min_line_length": 0.3,
40+
"min_line_length": 0.8,
4141
"debug_reject_bad": False
4242
}
4343

@@ -186,7 +186,6 @@
186186
# Tests Definitions ------------------------------------------------------------
187187
@pytest.mark.f2ls
188188
@pytest.mark.preprocessed_data
189-
@pytest.mark.regression
190189
@pytest.mark.parametrize("ad,params", input_pars, indirect=['ad'])
191190
def test_regression_for_determine_distortion_using_wcs(
192191
ad, params, change_working_dir, ref_ad_factory):
@@ -214,18 +213,24 @@ def test_regression_for_determine_distortion_using_wcs(
214213
distortion_determined_ad = p.writeOutputs().pop()
215214

216215
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
217-
model = distortion_determined_ad[0].wcs.get_transform(
218-
"pixels", "distortion_corrected")[2]
219-
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")[2]
216+
217+
# Confirm that the distortion model is placed after the rectification model
218+
assert (distortion_determined_ad[0].wcs.available_frames.index("distortion_corrected") >
219+
distortion_determined_ad[0].wcs.available_frames.index("rectified"))
220+
assert (ref_ad[0].wcs.available_frames.index("distortion_corrected") >
221+
ref_ad[0].wcs.available_frames.index("rectified"))
222+
223+
model = distortion_determined_ad[0].wcs.get_transform("pixels", "distortion_corrected")
224+
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")
220225

221226
# Otherwise we're doing something wrong!
222227
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
223228

224-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
229+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
225230

226-
# Increasing atol to 0.07 due to S20180114S0104_flatCorrected.fits producing
227-
# slightly different results on Jenkins vs. on MacOS. DB 20240820
228-
np.testing.assert_allclose(model(X, Y), ref_model(X, Y), atol=0.07)
231+
xx, yy = X[ad[0].mask == 0], Y[ad[0].mask == 0]
232+
diffs = model(xx, yy)[1] - ref_model(xx, yy)[1] # 1 is y-axis in astropy
233+
np.testing.assert_allclose(diffs, 0, atol=1)
229234

230235

231236
@pytest.mark.f2ls
@@ -252,8 +257,9 @@ def test_fitcoord_table_and_gwcs_match(ad, params, change_working_dir):
252257
p.determineDistortion(**fixed_parameters_for_determine_distortion)
253258
distortion_determined_ad = p.writeOutputs().pop()
254259

255-
model = distortion_determined_ad[0].wcs.get_transform(
256-
"pixels", "distortion_corrected")
260+
model = distortion_determined_ad[0].wcs.pipeline[
261+
distortion_determined_ad[0].wcs.available_frames.index(
262+
"distortion_corrected") - 1].transform
257263

258264
fitcoord = distortion_determined_ad[0].FITCOORD
259265
fitcoord_model = am.table_to_model(fitcoord[0])

geminidr/gnirs/tests/crossdispersed/test_determine_distortion.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"min_snr": 5.,
2626
"nsum": 10,
2727
"spectral_order": 3,
28-
"min_line_length": 0.8,
28+
"min_line_length": 0.5,
2929
"debug_reject_bad": False
3030
}
3131

@@ -51,7 +51,6 @@
5151
# Tests -----------------------------------------------------------------------
5252
@pytest.mark.gnirsxd
5353
@pytest.mark.preprocessed_data
54-
@pytest.mark.regression
5554
@pytest.mark.parametrize("ad,params", input_pars, indirect=['ad'])
5655
def test_regression_for_determine_distortion_using_wcs(
5756
ad, params, change_working_dir, ref_ad_factory):
@@ -62,16 +61,27 @@ def test_regression_for_determine_distortion_using_wcs(
6261
distortion_determined_ad = p.writeOutputs().pop()
6362

6463
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
65-
model = distortion_determined_ad[0].wcs.get_transform(
66-
"pixels", "distortion_corrected")[2]
67-
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")[2]
6864

69-
# Otherwise we're doing something wrong!
70-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
65+
for ext, ref_ext in zip(distortion_determined_ad, ref_ad):
66+
# Confirm that the distortion model is placed after the rectification model
67+
assert (ext.wcs.available_frames.index("distortion_corrected") >
68+
ext.wcs.available_frames.index("rectified"))
69+
assert (ref_ext.wcs.available_frames.index("distortion_corrected") >
70+
ref_ext.wcs.available_frames.index("rectified"))
7171

72-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
72+
model = ext.wcs.get_transform("pixels", "distortion_corrected")
73+
ref_model = ref_ext.wcs.get_transform("pixels", "distortion_corrected")
74+
75+
# Otherwise we're doing something wrong!
76+
assert model[-1].__class__.__name__ == ref_model[-1].__class__.__name__ == "Chebyshev2D"
77+
78+
Y, X = np.mgrid[:ext.shape[0], :ext.shape[1]]
79+
80+
# We only care about pixels in the illuminated region
81+
xx, yy = X[ext.mask == 0], Y[ext.mask == 0]
82+
diffs = model(xx, yy)[1] - ref_model(xx, yy)[1] # 1 is y-axis in astropy
83+
np.testing.assert_allclose(diffs, 0, atol=1)
7384

74-
np.testing.assert_allclose(model(X, Y), ref_model(X, Y), atol=0.05)
7585

7686
# Local Fixtures and Helper Functions ------------------------------------------
7787
@pytest.fixture(scope='function')

geminidr/gnirs/tests/longslit/test_determine_distortion.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"nsum": 10,
4040
"spatial_order": 3,
4141
"spectral_order": None,
42-
"min_line_length": None,
42+
"min_line_length": 0.8,
4343
"debug_reject_bad": False
4444
}
4545

@@ -87,7 +87,6 @@
8787
# Tests Definitions ------------------------------------------------------------
8888
@pytest.mark.gnirsls
8989
@pytest.mark.preprocessed_data
90-
@pytest.mark.regression
9190
@pytest.mark.parametrize("ad,params", input_pars, indirect=['ad'])
9291
def test_regression_for_determine_distortion_using_wcs(
9392
ad, params, change_working_dir, ref_ad_factory):
@@ -116,20 +115,29 @@ def test_regression_for_determine_distortion_using_wcs(
116115
distortion_determined_ad = p.writeOutputs().pop()
117116

118117
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
119-
model = distortion_determined_ad[0].wcs.get_transform(
120-
"pixels", "distortion_corrected")[2]
121-
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")[2]
122-
# do_plots(ad, ref_ad)
118+
119+
# Confirm that the distortion model is placed after the rectification model
120+
if "rectified" in distortion_determined_ad[0].wcs.available_frames:
121+
assert (distortion_determined_ad[0].wcs.available_frames.index("distortion_corrected") >
122+
distortion_determined_ad[0].wcs.available_frames.index("rectified"))
123+
# assert (ref_ad[0].wcs.available_frames.index("distortion_corrected") >
124+
# ref_ad[0].wcs.available_frames.index("rectified"))
125+
126+
model = distortion_determined_ad[0].wcs.get_transform("pixels", "distortion_corrected")
127+
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")
123128

124129
# Otherwise we're doing something wrong!
125-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
130+
assert model[-1].__class__.__name__ == ref_model[-1].__class__.__name__ == "Chebyshev2D"
126131

127-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
132+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
128133

129-
np.testing.assert_allclose(model(X, Y), ref_model(X, Y), atol=0.05)
134+
# We only care about pixels in the illuminated region
135+
xx, yy = X[ad[0].mask == 0], Y[ad[0].mask == 0]
136+
diffs = model(xx, yy)[1] - ref_model(xx, yy)[1] # 1 is y-axis in astropy
137+
np.testing.assert_allclose(diffs, 0, atol=1)
130138

131139

132-
@pytest.mark.gnirs
140+
@pytest.mark.gnirsls
133141
@pytest.mark.preprocessed_data
134142
@pytest.mark.parametrize("ad, params", input_pars, indirect=['ad'])
135143
def test_fitcoord_table_and_gwcs_match(ad, params, change_working_dir):
@@ -154,8 +162,9 @@ def test_fitcoord_table_and_gwcs_match(ad, params, change_working_dir):
154162
**params})
155163
distortion_determined_ad = p.writeOutputs().pop()
156164

157-
model = distortion_determined_ad[0].wcs.get_transform(
158-
"pixels", "distortion_corrected")
165+
model = distortion_determined_ad[0].wcs.pipeline[
166+
distortion_determined_ad[0].wcs.available_frames.index(
167+
"distortion_corrected") - 1].transform
159168

160169
fitcoord = distortion_determined_ad[0].FITCOORD
161170
fitcoord_model = am.table_to_model(fitcoord[0])

geminidr/niri/tests/longslit/test_determine_distortion.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"nsum": 10,
3939
"spatial_order": 3,
4040
"spectral_order": 3,
41-
"min_line_length": 0.,
41+
"min_line_length": 0.8,
4242
"debug_reject_bad": False
4343
}
4444

@@ -65,7 +65,6 @@
6565
# Tests Definitions ------------------------------------------------------------
6666
@pytest.mark.nirils
6767
@pytest.mark.preprocessed_data
68-
@pytest.mark.regression
6968
@pytest.mark.parametrize("ad,params", input_pars, indirect=['ad'])
7069
def test_regression_for_determine_distortion_using_wcs(
7170
ad, params, change_working_dir, ref_ad_factory):
@@ -94,16 +93,28 @@ def test_regression_for_determine_distortion_using_wcs(
9493
distortion_determined_ad = p.writeOutputs().pop()
9594

9695
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
96+
97+
# Confirm that the distortion model is placed after the rectification model
98+
assert (distortion_determined_ad[0].wcs.available_frames.index("distortion_corrected") >
99+
distortion_determined_ad[0].wcs.available_frames.index("rectified"))
100+
# We're using old refs with the models in the wrong order, but the overall
101+
# solution is good enough for this test. If they're remade, uncomment this.
102+
# assert (ref_ad[0].wcs.available_frames.index("distortion_corrected") >
103+
# ref_ad[0].wcs.available_frames.index("rectified"))
104+
97105
model = distortion_determined_ad[0].wcs.get_transform(
98-
"pixels", "distortion_corrected")[1]
99-
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")[1]
106+
"pixels", "distortion_corrected")
107+
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")
100108

101109
# Otherwise we're doing something wrong!
102-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
110+
assert model[-2].__class__.__name__ == ref_model[-2].__class__.__name__ == "Chebyshev2D"
103111

104-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
112+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
105113

106-
np.testing.assert_allclose(model(X, Y), ref_model(X, Y), atol=0.05)
114+
# We only care about pixels in the illuminated region
115+
xx, yy = X[ad[0].mask == 0], Y[ad[0].mask == 0]
116+
diffs = model(xx, yy)[0] - ref_model(xx, yy)[0] # 0 is x-axis in astropy
117+
np.testing.assert_allclose(diffs, 0, atol=1)
107118

108119

109120
@pytest.mark.nirils
@@ -131,8 +142,9 @@ def test_fitcoord_table_and_gwcs_match(ad, params, change_working_dir):
131142
**params})
132143
distortion_determined_ad = p.writeOutputs().pop()
133144

134-
model = distortion_determined_ad[0].wcs.get_transform(
135-
"pixels", "distortion_corrected")
145+
model = distortion_determined_ad[0].wcs.pipeline[
146+
distortion_determined_ad[0].wcs.available_frames.index(
147+
"distortion_corrected") - 1].transform
136148

137149
fitcoord = distortion_determined_ad[0].FITCOORD
138150
fitcoord_model = am.table_to_model(fitcoord[0])

0 commit comments

Comments
 (0)