def calculate_rf_lens_magnitudes(lens_redshift, velocity_dispersion, filters_dict): """Calculates the reference-frame lens magnitudes in multiple filters Parameters ---------- lens_redshift : float Redshift of the lens velocity_dispersion : float Velocity dispersion of the lens filters_dict : dict (See output of `get_sdss_filters` for details) Throughputs of various filters Returns ------- dict Each key is one of string characters 'u', 'g', 'r', 'i', 'z' representing the filter Each value is the reference-frame apparent magnitude of the quasar in the 'key' filter, of type float """ from stellarpop import tools from lenspop import population_functions, distances from astropy.cosmology import FlatLambdaCDM # Instantiate Distance distance = distances.Distance() #TODO: necessary? # Instantiate LensPopulation lenspop = population_functions.LensPopulation_() # Instantiate FlatLambdaCDM cosmology with reasonable parameters cosmology = FlatLambdaCDM(H0=70.0, Om0=0.3) lens_sed = tools.getSED('BC_Z=1.0_age=9.000gyr') velocity_dispersion = np.atleast_1d(velocity_dispersion) # Absolute --> apparent magnitude conversion in the R-band lens_abmag_r = tools.ABFilterMagnitude(filters_dict['r'], lens_sed, lens_redshift) distance_modulus = cosmology.distmod(lens_redshift).value lens_appmag_r = lens_abmag_r + distance_modulus # [Reference frame] Absolute --> apparent magnitude conversion in the R-band rf_lens_abmag_r, _ = lenspop.EarlyTypeRelations(velocity_dispersion) rf_lens_appmag = {} rf_lens_appmag['r'] = rf_lens_abmag_r + distance_modulus # Quantity which is added to ~magnitude to convert it into reference-frame ~magnitude offset_rf = rf_lens_abmag_r - lens_abmag_r # Converting absolute magnitude to reference-frame apparent magnitude for band in 'ugiz': rf_lens_appmag[band] = tools.ABFilterMagnitude( filters_dict[band], lens_sed, lens_redshift) + offset_rf + distance_modulus return rf_lens_appmag
def __init__(self,D=None,reset=False,zlmax=2,sigfloor=100, bands=['F814W_ACS','g_SDSS','r_SDSS','i_SDSS','z_SDSS','Y_UKIRT'],cosmo=[0.3,0.7,0.7],sourcepop="lsst" ): self.sourcepopulation=sourcepop if D==None: D=distances.Distance(cosmo=cosmo) self.L = lenspop.LensPopulation(reset=reset, sigfloor=sigfloor, zlmax=zlmax, bands=bands, D=D) self.S = lenspop.SourcePopulation(reset=reset, bands=bands, D=D, population=sourcepop) self.E = lenspop.EinsteinRadiusTools(D=D)
def beginRedshiftDependentRelation(self, D, reset, zmax=10, cosmo=[0.3, 0.7, 0.7]): self.zmax = zmax self.zbins, self.dz = numpy.linspace(0, self.zmax, 401, retstep=True) self.z2bins, self.dz2 = numpy.linspace(0, self.zmax, 201, retstep=True) if D == None: D = distances.Distance(cosmo=cosmo) self.D = D if reset != True: try: #load useful redshift splines splinedump = open("redshiftsplines.pkl", "rb") self.Da_spline, self.Dmod_spline, self.volume_spline, self.Da_bispline = pickle.load( splinedump) except IOError or EOFError: self.redshiftfunctions() else: self.redshiftfunctions()
def paint(self, Nmax=None, verbose=False, lrg_input_cat='$OM10_DIR/data/LRGo.txt', qso_input_cat='$OM10_DIR/data/QSOo.txt', synthetic=False): """ Add new columns to the table, for the magnitudes in various filters. Parameters ---------- synthetic : boolean Use `lenspop` to make synthetic magnitudes in various filters target : string Paint lenses ('lens') or sources ('source') lrg_input_cat : string Name of LRG catalog, if not using synthetic paint qso_input_cat : string Name of QSO catalog, if not using synthetic paint verbose : boolean print progress to stdout Notes ----- * Synthetic painting is very slow, as we loop over each object. * The treatment of QSOs may be flawed: the offset calculation has not been tested. """ if synthetic==False: # read data from SDSS f=open(os.path.expandvars(lrg_input_cat),'r') lrg=loadtxt(f) f.close() g=open(os.path.expandvars(qso_input_cat),'r') qso=loadtxt(g) g.close() ###MY OWN REDSHIFT ONLY MATCHING HERE: lens_props = ['MAGG_LENS','MAGR_LENS','MAGI_LENS','MAGZ_LENS', \ 'MAGW1_LENS','MAGW2_LENS','MAGW3_LENS','MAGW4_LENS', 'SDSS_FLAG_LENS'] src_props = ['MAGG_SRC','MAGR_SRC','MAGI_SRC','MAGZ_SRC', \ 'MAGW1_SRC','MAGW2_SRC','MAGW3_SRC','MAGW4_SRC', 'SDSS_FLAG_SRC'] tmp_lens = Table(np.zeros((len(self.sample),len(lens_props)),dtype='f8'),names=lens_props) tmp_src = Table(np.zeros((len(self.sample),len(src_props)),dtype='f8'),names=src_props) if verbose: print('setup done') lrg_sort = lrg[np.argsort(lrg[:,0]),:] qso_sort = qso[np.argsort(qso[:,0]),:] lens_count = 0 for lens in self.sample: #paint lens ind = np.searchsorted(lrg_sort[:,0],lens['ZLENS']) if ind >= len(lrg_sort): ind = len(lrg_sort) - 1 tmp_lens[lens_count] = lrg_sort[ind,6:] - lrg_sort[ind,8] + lens['APMAG_I'] #assign colors, not mags #paint source qso_ind = np.searchsorted(qso_sort[:,0],lens['ZSRC']) if qso_ind >= len(qso_sort): qso_ind = len(qso_sort) - 1 tmp_src[lens_count] = qso_sort[qso_ind,1:] - qso_sort[qso_ind,3] + lens['MAGI'] lens_count += 1 self.sample = hstack([self.sample,tmp_lens,tmp_src]) if synthetic==True: lens_count = 0 total = len(self.sample) Rfilter = tools.filterfromfile('r_SDSS') Ufilter = tools.filterfromfile('u_SDSS') # sort the Ufilter array Ufilterarg=np.sort(Ufilter[1]) Ufilter = (Ufilter[0], Ufilterarg, 1) Gfilter = tools.filterfromfile('g_SDSS') Ifilter = tools.filterfromfile('i_SDSS') Zfilter = tools.filterfromfile('z_SDSS') self.Nlenses=len(self.sample) bands = ('r_SDSS_lens', 'g_SDSS_lens', 'i_SDSS_lens', 'z_SDSS_lens', 'u_SDSS_lens','r_SDSS_quasar', 'g_SDSS_quasar', 'i_SDSS_quasar', 'z_SDSS_quasar', 'u_SDSS_quasar') if verbose: print('OM10: computing synthetic magnitudes in the following bands: ', bands) # call a distance class constructor d = distances.Distance() # number of data in the table of calculated magnitude totalEntrees = self.Nlenses*10.0 t = Table(np.arange(totalEntrees).reshape(self.Nlenses, 10), names=bands) Lsed = tools.getSED('BC_Z=1.0_age=9.000gyr') Qsed = tools.getSED('agn') from astropy.cosmology import FlatLambdaCDM cosmo = FlatLambdaCDM(H0=70, Om0=0.3) lenspop_constructor = population_functions.LensPopulation_() for lens in self.sample: # calculate the quasar magnitude redshift = lens['ZSRC'] RF_Imag_app_q = lens['MAGI_IN'] Qoffset = RF_Imag_app_q - tools.ABFilterMagnitude(Ifilter, Qsed, redshift) RF_Rmag_app_q = tools.ABFilterMagnitude(Rfilter, Qsed, redshift) + Qoffset RF_Gmag_app_q = tools.ABFilterMagnitude(Gfilter, Qsed, redshift) + Qoffset RF_Zmag_app_q = tools.ABFilterMagnitude(Zfilter, Qsed, redshift) + Qoffset if(redshift<3.9): RF_Umag_app_q = tools.ABFilterMagnitude(Ufilter, Qsed, redshift) + Qoffset elif(redshift>=3.9): RF_Umag_app_q = 99 # calculate the lens magnitude veldisp = np.atleast_1d(lens['VELDISP']) redshift = lens['ZLENS'] # Reference Frame Absolute R magnitude RF_RMag_abs, _ = lenspop_constructor.EarlyTypeRelations(veldisp) RMag_abs = tools.ABFilterMagnitude(Rfilter, Lsed, redshift) distMod = cosmo.distmod(redshift).value Rmag_app = RMag_abs + distMod offset_abs_app = RMag_abs - Rmag_app offset_RF_abs = RF_RMag_abs - RMag_abs RF_Rmag_app = RF_RMag_abs - offset_abs_app # Get filters and calculate magnitudes for each filter: RF_Umag_app = tools.ABFilterMagnitude(Ufilter, Lsed, redshift) + offset_RF_abs + distMod RF_Gmag_app = tools.ABFilterMagnitude(Gfilter, Lsed, redshift) + offset_RF_abs + distMod RF_Imag_app = tools.ABFilterMagnitude(Ifilter, Lsed, redshift) + offset_RF_abs + distMod RF_Zmag_app = tools.ABFilterMagnitude(Zfilter, Lsed, redshift) + offset_RF_abs + distMod t['u_SDSS_lens'][lens_count] = RF_Umag_app t['r_SDSS_lens'][lens_count] = RF_Rmag_app t['g_SDSS_lens'][lens_count] = RF_Gmag_app t['i_SDSS_lens'][lens_count] = RF_Imag_app t['z_SDSS_lens'][lens_count] = RF_Zmag_app t['u_SDSS_quasar'][lens_count] = RF_Umag_app_q t['r_SDSS_quasar'][lens_count] = RF_Rmag_app_q t['g_SDSS_quasar'][lens_count] = RF_Gmag_app_q t['i_SDSS_quasar'][lens_count] = RF_Imag_app_q t['z_SDSS_quasar'][lens_count] = RF_Zmag_app_q lens_count = lens_count + 1 dot = np.mod(lens_count, total/np.min([79,total])) == 0 if verbose and dot: print('.', end="") # Update the sample by adding the table of calculated magnitude self.sample.add_columns(t.columns.values()) self.lenses = self.sample.copy() return