def test_rectifiedSED(self): """ Check for an extreme case that the SN seds are being rectified. This is done by setting up an extreme case where there will be negative seds, and checking that this is indeed the case, and checking that they are not negative if rectified. """ snobj = SNObject(ra=30., dec=-60., source='salt2') snobj.set(z=0.96, t0=self.mjdobs, x1=-3., x0=1.8e-6) snobj.rectifySED = False times = np.arange(self.mjdobs - 50., self.mjdobs + 150., 1.) badTimes = [] for time in times: sed = snobj.SNObjectSED(time=time, bandpass=self.lsstBandPass['r']) if any(sed.flambda < 0.): badTimes.append(time) # Check that there are negative SEDs assert(len(badTimes) > 0) snobj.rectifySED = True for time in badTimes: sed = snobj.SNObjectSED(time=time, bandpass=self.lsstBandPass['r']) self.assertGreaterEqual(sed.calcADU(bandpass=self.lsstBandPass['r'], photParams=self.rectify_photParams), 0.) self.assertFalse(any(sed.flambda < 0.))
def get_phosimVars(self): """ Obtain variables sedFilepath to be used to obtain unique filenames for each SED for phoSim and MagNorm which is also used. Note that aside from acting as a getter, this also writes spectra to `self.sn_sedfile_prefix`snid_mjd_band.dat for each observation of interest """ # construct the unique filename # method: snid_mjd(to 4 places of decimal)_bandpassname mjd = "_{:0.4f}_".format(self.mjdobs) mjd += self.obs_metadata.bandpass + '.dat' fnames = np.array([ self.sn_sedfile_prefix + str(int(elem)) + mjd if isinstance( elem, numbers.Number) else self.sn_sedfile_prefix + str(elem) + mjd for elem in self.column_by_name('snid') ], dtype='str') c, x1, x0, t0, z = self.column_by_name('c'),\ self.column_by_name('x1'),\ self.column_by_name('x0'),\ self.column_by_name('t0'),\ self.column_by_name('redshift') bp = Bandpass() bp.imsimBandpass() magNorms = np.zeros(len(fnames)) snobject = SNObject() snobject.rectifySED = True for i in range(len(self.column_by_name('snid'))): # if t0 is nan, this was set by the catalog for dim SN, or SN # outside redshift range, We will not provide a SED file for these if np.isnan(t0[i]): magNorms[i] = np.nan fnames[i] = None else: snobject.set(c=c[i], x1=x1[i], x0=x0[i], t0=t0[i], z=z[i]) if snobject.modelOutSideTemporalRange == 'zero': if self.mjdobs > snobject.maxtime( ) or self.mjdobs < snobject.mintime(): magNorms[i] = np.nan fnames[i] = None # SED in rest frame sed = snobject.SNObjectSourceSED(time=self.mjdobs) try: magNorms[i] = sed.calcMag(bandpass=bp) except: # sed.flambda = 1.0e-20 magNorms[i] = 1000. # sed.calcMag(bandpass=bp) if self.writeSedFile: sed.writeSED(fnames[i]) return (fnames, magNorms)
def get_phosimVars(self): """ Obtain variables sedFilepath to be used to obtain unique filenames for each SED for phoSim and MagNorm which is also used. Note that aside from acting as a getter, this also writes spectra to `self.sn_sedfile_prefix`snid_mjd_band.dat for each observation of interest """ # construct the unique filename # method: snid_mjd(to 4 places of decimal)_bandpassname mjd = "_{:0.4f}_".format(self.mjdobs) mjd += self.obs_metadata.bandpass + '.dat' fnames = np.array([self.sn_sedfile_prefix + str(int(elem)) + mjd if isinstance(elem, numbers.Number) else self.sn_sedfile_prefix + str(elem) + mjd for elem in self.column_by_name('snid')], dtype='str') c, x1, x0, t0, z = self.column_by_name('c'),\ self.column_by_name('x1'),\ self.column_by_name('x0'),\ self.column_by_name('t0'),\ self.column_by_name('redshift') bp = Bandpass() bp.imsimBandpass() magNorms = np.zeros(len(fnames)) snobject = SNObject() snobject.rectifySED = True for i in range(len(self.column_by_name('snid'))): # if t0 is nan, this was set by the catalog for dim SN, or SN # outside redshift range, We will not provide a SED file for these if np.isnan(t0[i]): magNorms[i] = np.nan fnames[i] = None else: snobject.set(c=c[i], x1=x1[i], x0=x0[i], t0=t0[i], z=z[i]) if snobject.modelOutSideTemporalRange == 'zero': if self.mjdobs > snobject.maxtime() or self.mjdobs < snobject.mintime(): magNorms[i] = np.nan fnames[i] = None # SED in rest frame sed = snobject.SNObjectSourceSED(time=self.mjdobs) try: magNorms[i] = sed.calcMag(bandpass=bp) except: # sed.flambda = 1.0e-20 magNorms[i] = 1000. # sed.calcMag(bandpass=bp) if self.writeSedFile: sed.writeSED(fnames[i]) return (fnames, magNorms)
def test_attributeDefaults(self): """ Check the defaults and the setter properties for rectifySED and modelOutSideRange """ snobj = SNObject(ra=30., dec=-60., source='salt2') self.assertEqual(snobj.rectifySED, True) self.assertEqual(snobj.modelOutSideTemporalRange, 'zero') snobj.rectifySED = False self.assertFalse(snobj.rectifySED, False) self.assertEqual(snobj.modelOutSideTemporalRange, 'zero')