Пример #1
0
    def test_compute_fluxcalibration(self):
        """ Test compute_fluxcalibration interface
        """

        #get frame data
        frame = get_frame_data()
        #get model data
        modelwave, modelflux = get_models()
        # pick std star fibers
        stdfibers = np.random.choice(9, 3,
                                     replace=False)  # take 3 std stars fibers
        frame.fibermap['DESI_TARGET'][stdfibers] = desi_mask.STD_FAINT

        input_model_wave = modelwave
        input_model_flux = modelflux[
            0:
            3]  # assuming the first three to be best models,3 is exclusive here
        fluxCalib = compute_flux_calibration(frame,
                                             input_model_wave,
                                             input_model_flux,
                                             input_model_fibers=stdfibers,
                                             nsig_clipping=4.)
        # assert the output
        self.assertTrue(np.array_equal(fluxCalib.wave, frame.wave))
        self.assertEqual(fluxCalib.calib.shape, frame.flux.shape)

        #- nothing should be masked for this test case
        self.assertFalse(np.any(fluxCalib.mask))
Пример #2
0
    def test_outliers(self):
        '''Test fluxcalib when input starts with large outliers'''
        frame = get_frame_data()
        modelwave, modelflux = get_models()
        nstd = 5
        frame.fibermap['OBJTYPE'][0:nstd] = 'STD'
        nstd = np.count_nonzero(frame.fibermap['OBJTYPE'] == 'STD')

        frame.flux[0] = np.mean(frame.flux[0])        
        fluxCalib = compute_flux_calibration(frame, modelwave, modelflux[0:nstd],input_model_fibers=np.arange(nstd))
Пример #3
0
    def test_outliers(self):
        '''Test fluxcalib when input starts with large outliers'''
        frame = get_frame_data()
        modelwave, modelflux = get_models()
        nstd = 5
        frame.fibermap['OBJTYPE'][0:nstd] = 'STD'
        nstd = np.count_nonzero(frame.fibermap['OBJTYPE'] == 'STD')

        frame.flux[0] = np.mean(frame.flux[0])        
        fluxCalib = compute_flux_calibration(frame, modelwave, modelflux[0:nstd],input_model_fibers=np.arange(nstd))
Пример #4
0
    def test_masked_data(self):
        """Test compute_fluxcalibration with some ivar=0 data
        """
        frame = get_frame_data()
        modelwave, modelflux = get_models()
        nstd = 1
        frame.fibermap['OBJTYPE'][2:2+nstd] = 'STD'
        frame.ivar[2:2+nstd, 20:22] = 0

        fluxCalib = compute_flux_calibration(frame, modelwave, modelflux[2:2+nstd], input_model_fibers=np.arange(2,2+nstd), debug=True)
        
        self.assertTrue(np.array_equal(fluxCalib.wave, frame.wave))
        self.assertEqual(fluxCalib.calib.shape,frame.flux.shape)
Пример #5
0
    def test_masked_data(self):
        """Test compute_fluxcalibration with some ivar=0 data
        """
        frame = get_frame_data()
        modelwave, modelflux = get_models()
        nstd = 1
        frame.fibermap['OBJTYPE'][2:2+nstd] = 'STD'
        frame.ivar[2:2+nstd, 20:22] = 0

        fluxCalib = compute_flux_calibration(frame, modelwave, modelflux[2:2+nstd], input_model_fibers=np.arange(2,2+nstd), debug=True)
        
        self.assertTrue(np.array_equal(fluxCalib.wave, frame.wave))
        self.assertEqual(fluxCalib.calib.shape,frame.flux.shape)
Пример #6
0
 def _write_models(self):
     wav, mods = get_models(wavemin=2900, wavemax=11000)
     nmod = len(mods)
     tid, logg, feh, teff = [np.arange(nmod) for _ in range(4)]
     tab = Table({
         'TEMPLATEID': tid,
         'LOGG': logg,
         'FEH': feh,
         'TEFF': teff
     })
     fits.HDUList(
         [fits.PrimaryHDU(mods),
          fits.BinTableHDU(tab),
          fits.ImageHDU(wav)]).writeto(self.modelfile, overwrite=True)
Пример #7
0
    def test_match_templates(self):
        """
        Test with simple interface check for matching best templates with the std star flux
        """
        from desispec.fluxcalibration import match_templates
        frame = get_frame_data()
        # first define dictionaries
        flux = {"b": frame.flux, "r": frame.flux * 1.1, "z": frame.flux * 1.2}
        wave = {"b": frame.wave, "r": frame.wave + 10, "z": frame.wave + 20}
        ivar = {"b": frame.ivar, "r": frame.ivar / 1.1, "z": frame.ivar / 1.2}
        # resol_data={"b":np.mean(frame.resolution_data,axis=0),"r":np.mean(frame.resolution_data,axis=0),"z":np.mean(frame.resolution_data,axis=0)}
        resol_data = {
            "b": frame.resolution_data,
            "r": frame.resolution_data,
            "z": frame.resolution_data
        }

        #model

        nmodels = 10
        modelwave, modelflux = get_models(nmodels)
        teff = np.random.uniform(5000, 7000, nmodels)
        logg = np.random.uniform(4.0, 5.0, nmodels)
        feh = np.random.uniform(-2.5, -0.5, nmodels)
        # say there are 3 stdstars
        stdfibers = np.random.choice(9, 3, replace=False)
        frame.fibermap['OBJTYPE'][stdfibers] = 'STD'

        #pick fluxes etc for each stdstars find the best match
        bestid = -np.ones(len(stdfibers))
        bestwave = np.zeros((bestid.shape[0], modelflux.shape[1]))
        bestflux = np.zeros((bestid.shape[0], modelflux.shape[1]))
        red_chisq = np.zeros(len(stdfibers))

        for i in range(len(stdfibers)):

            stdflux = {"b": flux["b"][i], "r": flux["r"][i], "z": flux["z"][i]}
            stdivar = {"b": ivar["b"][i], "r": ivar["r"][i], "z": ivar["z"][i]}
            stdresol_data = {
                "b": resol_data["b"][i],
                "r": resol_data["r"][i],
                "z": resol_data["z"][i]
            }

            bestid, redshift, chi2 = \
                match_templates(wave, stdflux, stdivar, stdresol_data,
                    modelwave, modelflux, teff, logg, feh)
Пример #8
0
    def test_compute_fluxcalibration(self):
        """ Test compute_fluxcalibration interface
        """

        #get frame data
        frame=get_frame_data()
        #get model data
        modelwave,modelflux=get_models()
        # pick std star fibers
        stdfibers=np.random.choice(9,3,replace=False) # take 3 std stars fibers
        frame.fibermap['DESI_TARGET'][stdfibers] = desi_mask.STD_FAINT

        input_model_wave=modelwave
        input_model_flux=modelflux[0:3] # assuming the first three to be best models,3 is exclusive here
        fluxCalib =compute_flux_calibration(frame, input_model_wave,input_model_flux,input_model_fibers=stdfibers,nsig_clipping=4.)
        # assert the output
        self.assertTrue(np.array_equal(fluxCalib.wave, frame.wave))
        self.assertEqual(fluxCalib.calib.shape,frame.flux.shape)

        #- nothing should be masked for this test case
        self.assertFalse(np.any(fluxCalib.mask))
Пример #9
0
    def test_match_templates(self):
        """
        Test with simple interface check for matching best templates with the std star flux
        """
        from desispec.fluxcalibration import match_templates
        frame=get_frame_data()
        # first define dictionaries
        flux={"b":frame.flux,"r":frame.flux*1.1,"z":frame.flux*1.2}
        wave={"b":frame.wave,"r":frame.wave+10,"z":frame.wave+20}
        ivar={"b":frame.ivar,"r":frame.ivar/1.1,"z":frame.ivar/1.2}
        # resol_data={"b":np.mean(frame.resolution_data,axis=0),"r":np.mean(frame.resolution_data,axis=0),"z":np.mean(frame.resolution_data,axis=0)}
        resol_data={"b":frame.resolution_data,"r":frame.resolution_data,"z":frame.resolution_data}

        #model

        nmodels = 10
        modelwave,modelflux=get_models(nmodels)
        teff = np.random.uniform(5000, 7000, nmodels)
        logg = np.random.uniform(4.0, 5.0, nmodels)
        feh = np.random.uniform(-2.5, -0.5, nmodels)
        # say there are 3 stdstars
        stdfibers=np.random.choice(9,3,replace=False)
        frame.fibermap['OBJTYPE'][stdfibers] = 'STD'

        #pick fluxes etc for each stdstars find the best match
        bestid=-np.ones(len(stdfibers))
        bestwave=np.zeros((bestid.shape[0],modelflux.shape[1]))
        bestflux=np.zeros((bestid.shape[0],modelflux.shape[1]))
        red_chisq=np.zeros(len(stdfibers))

        for i in range(len(stdfibers)):

            stdflux={"b":flux["b"][i],"r":flux["r"][i],"z":flux["z"][i]}
            stdivar={"b":ivar["b"][i],"r":ivar["r"][i],"z":ivar["z"][i]}
            stdresol_data={"b":resol_data["b"][i],"r":resol_data["r"][i],"z":resol_data["z"][i]}

            bestid, redshift, chi2 = \
                match_templates(wave, stdflux, stdivar, stdresol_data,
                    modelwave, modelflux, teff, logg, feh)