Skip to content

Commit 34931c9

Browse files
committed
add a test with unknown fluxcalib at some pixels
1 parent af25b32 commit 34931c9

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

py/desispec/test/test_flux_calibration.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,49 @@ def test_apply_fluxcalibration(self):
213213

214214
# preservation of resolution equation
215215
resol = np.random.uniform(size=(flux.shape[0], 11, flux.shape[1]))
216-
# input spectra
217216
flux0 = np.random.uniform(0.9, 1.0, size=(nspec, nwave))
217+
calib = np.random.uniform(.5, 1.5, size=origframe.flux.shape)
218+
# input spectra
218219
flux0[:, :6] = 0
219220
flux0[:, -7:] = 0
220221
# convolving with the resolution matrix
221222
flux_conv = np.array([desispec.resolution.Resolution(resol[i])@flux0[i] for i in range(nspec)])
222223
flux0_calib = flux0 / calib
223224
frame = Frame(wave, flux_conv.copy(), ivar.copy(), spectrograph=0,
224225
resolution_data=resol.copy())
225-
calib = np.random.uniform(.5, 1.5, size=origframe.flux.shape)
226226
mask = np.zeros(origframe.flux.shape, dtype=np.uint32)
227227
fc = FluxCalib(origframe.wave, calib, ivar, mask)
228228
apply_flux_calibration(frame, fc)
229229
flux1_conv = np.array([desispec.resolution.Resolution(
230230
frame.resolution_data[i])@flux0_calib[i] for i in range(nspec)])
231-
print (flux1_conv[:7,5:10], frame.flux[:7,5:10])
232231
self.assertTrue(np.allclose(flux1_conv, frame.flux))
233-
232+
233+
# now we test that we correctly deal with cases where
234+
# calibration is unknown
235+
# preservation of resolution equation
236+
resol = np.random.uniform(size=(flux.shape[0], 11, flux.shape[1]))
237+
flux0 = np.random.uniform(0.9, 1.0, size=(nspec, nwave))
238+
calib0 = flux * 0 + 10
239+
calib = calib0.copy()
240+
# set bad calibration range
241+
calib[:, :10] = 0
242+
calib[:, 20:30] = 0
243+
bad_calib = calib == 0
244+
# input spectra
245+
flux0[:, :6] = 0
246+
flux0[:, -7:] = 0
247+
# convolving with the resolution matrix
248+
flux_conv = np.array([desispec.resolution.Resolution(resol[i])@flux0[i] for i in range(nspec)])
249+
flux0_calib = flux0 / calib0
250+
frame = Frame(wave, flux_conv.copy(), ivar.copy(), spectrograph=0,
251+
resolution_data=resol.copy())
252+
mask = np.zeros(origframe.flux.shape, dtype=np.uint32)
253+
fc = FluxCalib(origframe.wave, calib, ivar, mask)
254+
apply_flux_calibration(frame, fc)
255+
flux1_conv = np.array([desispec.resolution.Resolution(
256+
frame.resolution_data[i])@flux0_calib[i] for i in range(nspec)])
257+
self.assertTrue(np.allclose(flux1_conv[~bad_calib], frame.flux[~bad_calib]))
258+
234259

235260
def test_isStdStar(self):
236261
"""test isStdStar works for cmx, main, and sv1 fibermaps"""

0 commit comments

Comments
 (0)