Skip to content

Commit ef0a63e

Browse files
committed
write *correct* determineDistortion() tests
1 parent 3d50f75 commit ef0a63e

5 files changed

Lines changed: 55 additions & 37 deletions

File tree

geminidr/f2/tests/longslit/test_determine_distortion.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,25 @@ def test_regression_for_determine_distortion_using_wcs(
214214
distortion_determined_ad = p.writeOutputs().pop()
215215

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

224227
# Otherwise we're doing something wrong!
225-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
228+
assert model[-1].__class__.__name__ == ref_model[-1].__class__.__name__ == "Chebyshev2D"
226229

227-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
230+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
228231

229232
# We only care about pixels in the illuminated region
230233
xx, yy = X[ad[0].mask == 0], Y[ad[0].mask == 0]
231-
np.testing.assert_allclose(model(xx, yy), ref_model(xx, yy), atol=1)
234+
diffs = model(xx, yy)[1] - ref_model(xx, yy)[1] # 1 is y-axis in astropy
235+
np.testing.assert_allclose(diffs, 0, atol=1)
232236

233237

234238
@pytest.mark.f2ls

geminidr/gnirs/tests/crossdispersed/test_determine_distortion.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,25 @@ def test_regression_for_determine_distortion_using_wcs(
6161

6262
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
6363
for ext, ref_ext in zip(distortion_determined_ad, ref_ad):
64-
model = ext.wcs.pipeline[
65-
ext.wcs.available_frames.index(
66-
"distortion_corrected") - 1].transform[2]
67-
ref_model = ref_ext.wcs.pipeline[
68-
ref_ext.wcs.available_frames.index(
69-
"distortion_corrected") - 1].transform[2]
64+
# Confirm that the distortion model is placed after the rectification model
65+
assert (ext.wcs.avilable_frames.index("distortion_corrected") >
66+
ext.wcs.avilable_frames.index("rectified"))
67+
assert (ref_ext.wcs.avilable_frames.index("distortion_corrected") >
68+
ref_ext.wcs.avilable_frames.index("rectified"))
69+
70+
model = ext.wcs.get_transform("pixels", "distortion_corrected")
71+
ref_model = ref_ext.wcs.get_transform("pixels", "distortion_corrected")
7072

7173
# Otherwise we're doing something wrong!
72-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
74+
assert model[-1].__class__.__name__ == ref_model[-1].__class__.__name__ == "Chebyshev2D"
7375

7476
Y, X = np.mgrid[:ext.shape[0], :ext.shape[1]]
7577

7678
# We only care about pixels in the illuminated region
7779
xx, yy = X[ext.mask == 0], Y[ext.mask == 0]
78-
np.testing.assert_allclose(model(xx, yy), ref_model(xx, yy), atol=1)
80+
diffs = model(xx, yy)[1] - ref_model(xx, yy)[1] # 1 is y-axis in astropy
81+
np.testing.assert_allclose(diffs, 0, atol=1)
82+
7983

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

geminidr/gnirs/tests/longslit/test_determine_distortion.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,25 @@ def test_regression_for_determine_distortion_using_wcs(
115115
distortion_determined_ad = p.writeOutputs().pop()
116116

117117
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
118-
model = distortion_determined_ad[0].wcs.pipeline[
119-
distortion_determined_ad[0].wcs.available_frames.index(
120-
"distortion_corrected")-1].transform[2]
121-
ref_model = ref_ad[0].wcs.pipeline[
122-
ref_ad[0].wcs.available_frames.index(
123-
"distortion_corrected")-1].transform[2]
124-
# do_plots(ad, ref_ad)
118+
119+
# Confirm that the distortion model is placed after the rectification model
120+
assert (distortion_determined_ad.wcs.avilable_frames.index("distortion_corrected") >
121+
distortion_determined_ad.wcs.avilable_frames.index("rectified"))
122+
assert (ref_ad.wcs.avilable_frames.index("distortion_corrected") >
123+
ref_ad.wcs.avilable_frames.index("rectified"))
124+
125+
model = distortion_determined_ad[0].wcs.get_transform("pixels", "distortion_corrected")
126+
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")
125127

126128
# Otherwise we're doing something wrong!
127-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
129+
assert model[-1].__class__.__name__ == ref_model[-1].__class__.__name__ == "Chebyshev2D"
128130

129-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
131+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
130132

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

135138

136139
@pytest.mark.gnirs

geminidr/niri/tests/longslit/test_determine_distortion.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,26 @@ def test_regression_for_determine_distortion_using_wcs(
9494
distortion_determined_ad = p.writeOutputs().pop()
9595

9696
ref_ad = ref_ad_factory(distortion_determined_ad.filename)
97-
model = distortion_determined_ad[0].wcs.pipeline[
98-
distortion_determined_ad[0].wcs.available_frames.index(
99-
"distortion_corrected")-1].transform[1]
100-
ref_model = ref_ad[0].wcs.pipeline[
101-
ref_ad[0].wcs.available_frames.index(
102-
"distortion_corrected")-1].transform[1]
97+
98+
# Confirm that the distortion model is placed after the rectification model
99+
assert (distortion_determined_ad.wcs.avilable_frames.index("distortion_corrected") >
100+
distortion_determined_ad.wcs.avilable_frames.index("rectified"))
101+
assert (ref_ad.wcs.avilable_frames.index("distortion_corrected") >
102+
ref_ad.wcs.avilable_frames.index("rectified"))
103+
104+
model = distortion_determined_ad[0].wcs.get_transform("pixels", "distortion_corrected")
105+
ref_model = ref_ad[0].wcs.get_transform("pixels", "distortion_corrected")
103106

104107
# Otherwise we're doing something wrong!
105-
assert model.__class__.__name__ == ref_model.__class__.__name__ == "Chebyshev2D"
108+
# This distortion model modifies x so an Identity(1) will be after it for y
109+
assert model[-2].__class__.__name__ == ref_model[-2].__class__.__name__ == "Chebyshev2D"
106110

107-
X, Y = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
111+
Y, X = np.mgrid[:ad[0].shape[0], :ad[0].shape[1]]
108112

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

111118

112119
@pytest.mark.nirils

gempy/library/peak_finding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def find_wavelet_peaks(data, widths=None, mask=None, variance=None, min_snr=1, m
681681
# the width and 1.0^ + 0.75^2 = 1.25^2).
682682
snr = np.divide(wavelet_transformed_data[0], np.sqrt(variance),
683683
out=np.zeros_like(data, dtype=np.float32),
684-
where=variance > 0) * np.sqrt(2)
684+
where=variance > 0) * 1.25
685685

686686
peaks = [x for x in peaks if snr[x] > min_snr]
687687

0 commit comments

Comments
 (0)