@@ -213,24 +213,49 @@ def test_apply_fluxcalibration(self):
213
213
214
214
# preservation of resolution equation
215
215
resol = np .random .uniform (size = (flux .shape [0 ], 11 , flux .shape [1 ]))
216
- # input spectra
217
216
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
218
219
flux0 [:, :6 ] = 0
219
220
flux0 [:, - 7 :] = 0
220
221
# convolving with the resolution matrix
221
222
flux_conv = np .array ([desispec .resolution .Resolution (resol [i ])@flux0 [i ] for i in range (nspec )])
222
223
flux0_calib = flux0 / calib
223
224
frame = Frame (wave , flux_conv .copy (), ivar .copy (), spectrograph = 0 ,
224
225
resolution_data = resol .copy ())
225
- calib = np .random .uniform (.5 , 1.5 , size = origframe .flux .shape )
226
226
mask = np .zeros (origframe .flux .shape , dtype = np .uint32 )
227
227
fc = FluxCalib (origframe .wave , calib , ivar , mask )
228
228
apply_flux_calibration (frame , fc )
229
229
flux1_conv = np .array ([desispec .resolution .Resolution (
230
230
frame .resolution_data [i ])@flux0_calib [i ] for i in range (nspec )])
231
- print (flux1_conv [:7 ,5 :10 ], frame .flux [:7 ,5 :10 ])
232
231
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
+
234
259
235
260
def test_isStdStar (self ):
236
261
"""test isStdStar works for cmx, main, and sv1 fibermaps"""
0 commit comments