[docs]classDustValues:"""Calculate extinction values Parameters ---------- R_v : `float` Extinction law parameter (3.1). bandpassDict : `dict` A dict with keys of filtername and values of rubin_sim.phot_utils.Bandpass objects. Default of None will load the standard ugrizy bandpasses. ref_ev : `float` The reference E(B-V) value to use. Things in MAF assume 1. Note ---- The value that dust_values calls "ax1" is equivalent to r_x in any filter. And r_x * ebv = A_x (the extinction due to dust in any bandpass). DustValues.r_x is also provided as a copy of DustValues.ax1 .. eventually ax1 may be deprecated in favor of r_x. """def__init__(self,r_v=3.1,bandpass_dict=None,ref_ebv=1.0):# Calculate dust extinction valuesself.ax1={}ifbandpass_dictisNone:bandpass_dict={}root_dir=os.path.join(get_data_dir(),"throughputs","baseline")forfin["u","g","r","i","z","y"]:bandpass_dict[f]=Bandpass()bandpass_dict[f].read_throughput(os.path.join(root_dir,f"total_{f}.dat"))forfilternameinbandpass_dict:wavelen_min=bandpass_dict[filtername].wavelen.min()wavelen_max=bandpass_dict[filtername].wavelen.max()testsed=Sed()testsed.set_flat_sed(wavelen_min=wavelen_min,wavelen_max=wavelen_max,wavelen_step=1.0)self.ref_ebv=ref_ebv# Calculate non-dust-extincted magnitudeflatmag=testsed.calc_mag(bandpass_dict[filtername])# Add dusta,b=testsed.setup_ccm_ab()testsed.add_dust(a,b,ebv=self.ref_ebv,r_v=r_v)# Calculate difference due to dust when EBV=1.0# (m_dust = m_nodust - Ax, Ax > 0)self.ax1[filtername]=testsed.calc_mag(bandpass_dict[filtername])-flatmag# Add the R_x term, to start to transition toward this name.self.r_x=self.ax1.copy()
defmake_dict(value,bandpass_names=("u","g","r","i","z","y","any")):newdict={}forfinbandpass_names:newdict[f]=valuereturnnewdictclassDefaultPhotometricParameters:""" This class will just contain a bunch of dict which store the default PhotometricParameters for LSST Bandpasses Users should not access this class (which is why it is not included in the __all__ declaration for this file). It is only used to initialize PhotometricParameters for a bandpass name. """# Obviously, some of these parameters (effarea, gain, platescale,# darkcurrent, and readnoise) will not change as a function of bandpass;# we are just making them dicts here to be consistent with# everything else (and to make it possible for# PhotometricParameters to access them using the bandpass name# passed to its constructor)## Note: all dicts contain an 'any' key which will be the default# value if an unknown bandpass is asked for## 'any' values should be kept consistent with r bandbandpass_names=["u","g","r","i","z","y","any"]# exposure time in secondsexptime_sec=15.0exptime=make_dict(exptime_sec)# number of exposuresnexp_n=2nexp=make_dict(nexp_n)# effective area in cm^2effarea_cm2=np.pi*(6.423/2.0*100)**2effarea=make_dict(effarea_cm2)# electrons per ADUgain_adu=2.3gain=make_dict(gain_adu)# electrons per pixel per exposurereadnoise_e=8.8readnoise=make_dict(readnoise_e)# electrons per pixel per seconddarkcurrent_e=0.2darkcurrent=make_dict(darkcurrent_e)# electrons per pixel per exposureothernoise_e=0.0othernoise=make_dict(othernoise_e)# arcseconds per pixelplatescale_as=0.2platescale=make_dict(platescale_as)# systematic squared error in magnitudes# see Table 14 of the SRD document# https://docushare.lsstcorp.org/docushare/dsweb/Get/LPM-17sigma_sys={"u":0.0075,"g":0.005,"r":0.005,"i":0.005,"z":0.0075,"y":0.0075,"any":0.005,}classPhotometricParameters:def__init__(self,exptime=None,nexp=None,effarea=None,gain=None,readnoise=None,darkcurrent=None,othernoise=None,platescale=None,sigma_sys=None,bandpass=None,):"""Store photometric parameters for SNR calculations. Parameters ---------- exptime : `float` Exposure time in seconds (per exposure). None will default to value from DefaultPhotometricParameters. nexp : `int` Number of exposures per visit. None will default to value from DefaultPhotometricParameters. effarea : `float` Effective area in cm^2. None will default to value from DefaultPhotometricParameters. gain : `float` Electrons per ADU. None will default to value from DefaultPhotometricParameters. readnoise : `float` Electrons per pixel per exposure. None will default to value from DefaultPhotometricParameters. darkcurrent : `float` Electons per pixel per second. None will default to value from DefaultPhotometricParameters. othernoise : `float` Electrons per pixel per exposure. None will default to value from DefaultPhotometricParameters. platescale : `float` Arcseconds per pixel. None will default to value from DefaultPhotometricParameters. sigma_sys : `float` Systematic error in magnitudes. None will default to value from DefaultPhotometricParameters. bandpass : `str` The name of the bandpass for these parameters. Examples -------- If `bandpass` is set to an LSST bandpass, the constructor will initialize PhotometricParameters to LSST default values for that bandpass, excepting any parameters that have been set by hand. e.g. >>> myPhotParams = PhotometricParameters(nexp=3, bandpass='u') will initialize a PhotometricParameters object to `u` band defaults, except with 3 exposures instead of 2. A bandpass value of None will use defaults from LSST `r` band where appropriate. """# readnoise, darkcurrent and othernoise are measured in electrons.# This is taken from the specifications document LSE-30 on Docushare# Section 3.4.2.3 states that the total noise per pixel shall# be 12.7 electrons per visit which the defaults sum to# (remember to multply darkcurrent by the number of seconds# in an exposure=15). [9 e- per 15 second exposure]self._exptime=Noneself._nexp=Noneself._effarea=Noneself._gain=Noneself._platescale=Noneself._sigma_sys=Noneself._readnoise=Noneself._darkcurrent=Noneself._othernoise=Noneself._bandpass=bandpassdefaults=DefaultPhotometricParameters()ifbandpassisNone:bandpass_key="any"# This is so we do not set the self._bandpass member variable# without the user's explicit consent, but we can still access# default values from the PhotometricParameterDefaultselse:bandpass_key=bandpassifbandpass_keyindefaults.bandpass_names:self._exptime=defaults.exptime[bandpass_key]self._nexp=defaults.nexp[bandpass_key]self._effarea=defaults.effarea[bandpass_key]self._gain=defaults.gain[bandpass_key]self._platescale=defaults.platescale[bandpass_key]self._sigma_sys=defaults.sigma_sys[bandpass_key]self._readnoise=defaults.readnoise[bandpass_key]self._darkcurrent=defaults.darkcurrent[bandpass_key]self._othernoise=defaults.othernoise[bandpass_key]ifexptimeisnotNone:self._exptime=exptimeifnexpisnotNone:self._nexp=nexpifeffareaisnotNone:self._effarea=effareaifgainisnotNone:self._gain=gainifplatescaleisnotNone:self._platescale=platescaleifsigma_sysisnotNone:self._sigma_sys=sigma_sysifreadnoiseisnotNone:self._readnoise=readnoiseifdarkcurrentisnotNone:self._darkcurrent=darkcurrentifothernoiseisnotNone:self._othernoise=othernoisefailure_message=""failure_ct=0ifself._exptimeisNone:failure_message+="did not set exptime\n"failure_ct+=1ifself._nexpisNone:failure_message+="did not set nexp\n"failure_ct+=1ifself._effareaisNone:failure_message+="did not set effarea\n"failure_ct+=1ifself._gainisNone:failure_message+="did not set gain\n"failure_ct+=1ifself._platescaleisNone:failure_message+="did not set platescale\n"failure_ct+=1ifself._sigma_sysisNone:failure_message+="did not set sigma_sys\n"failure_ct+=1ifself._readnoiseisNone:failure_message+="did not set readnoise\n"failure_ct+=1ifself._darkcurrentisNone:failure_message+="did not set darkcurrent\n"failure_ct+=1ifself._othernoiseisNone:failure_message+="did not set othernoise\n"failure_ct+=1iffailure_ct>0:raiseRuntimeError("In PhotometricParameters:\n%s"%failure_message)@propertydefbandpass(self):""" The name of the bandpass associated with these parameters. Can be None. """returnself._bandpass@bandpass.setterdefbandpass(self,value):raiseRuntimeError("You should not be setting bandpass on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefexptime(self):""" exposure time in seconds """returnself._exptime@exptime.setterdefexptime(self,value):raiseRuntimeError("You should not be setting exptime on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefnexp(self):""" number of exposures """returnself._nexp@nexp.setterdefnexp(self,value):raiseRuntimeError("You should not be setting nexp on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefeffarea(self):""" effective area in cm^2 """returnself._effarea@effarea.setterdefeffarea(self,value):raiseRuntimeError("You should not be setting effarea on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefgain(self):""" electrons per ADU """returnself._gain@gain.setterdefgain(self,value):raiseRuntimeError("You should not be setting gain on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefplatescale(self):""" arcseconds per pixel """returnself._platescale@platescale.setterdefplatescale(self,value):raiseRuntimeError("You should not be setting platescale on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefreadnoise(self):""" electrons per pixel per exposure """returnself._readnoise@readnoise.setterdefreadnoise(self,value):raiseRuntimeError("You should not be setting readnoise on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefdarkcurrent(self):""" electrons per pixel per second """returnself._darkcurrent@darkcurrent.setterdefdarkcurrent(self,value):raiseRuntimeError("You should not be setting darkcurrent on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefothernoise(self):""" electrons per pixel per exposure """returnself._othernoise@othernoise.setterdefothernoise(self,value):raiseRuntimeError("You should not be setting othernoise on the fly; "+"Just instantiate a new case of PhotometricParameters")@propertydefsigma_sys(self):""" systematic error in magnitudes """returnself._sigma_sys@sigma_sys.setterdefsigma_sys(self,value):raiseRuntimeError("You should not be setting sigma_sys on the fly; "+"Just instantiate a new case of PhotometricParameters")