def luminosity_correction(self): """ The FSPS templates are in L_sun/Angstrom, with L_sun = 3.83e26W so we change to the appropriate flux at each relevent redshift. Our SED code gives correct magnitudes if the SED is in units of ergs/s/cm/cm/Angstrom, and our distance class gives distances in Mpc/h, so we will need to use the conversion Mpc = 3.08568e24cm and assume a value for h. The conversion factor is conv = flux_density/luminosity_density and the templates should therefore be multiplied by conv to get the correct flux_density. The factor of (1+z) accounts for the fact that these are _densities_. 3.83e33 conv = ---------------- (1+z) 4 pi Dl**2 """ import distances from math import pi z = self.redshift dist = distances.Distance() cm_per_Mpc = 3.08568e24 if z == 0: dl = 1e-5 * cm_per_Mpc else: dl = dist.Dl(z) * cm_per_Mpc conv = 1. / (4 * pi * dl**2) conv *= 3.83e33 return conv
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: import distances D = distances.Distance(cosmo=cosmo) self.L = LensPopulation(reset=reset, sigfloor=sigfloor, zlmax=zlmax, bands=bands, D=D) self.S = SourcePopulation(reset=reset, bands=bands, D=D, population=sourcepop) self.E = EinsteinRadiusTools(D=D)
def loglkl(self, cosmo, data): lkl = 0 lensing_da_lognorm = np.zeros((self.num_points), 'float64') if cosmo.Omega_fld() and -1.e-3 < cosmo.Omega_lambda() < 1.e-3: params = [ cosmo.Omega_m(), cosmo.Omega_fld(), cosmo.h(), cosmo.w0(), cosmo.wa() ] else: params = [ cosmo.Omega_m(), cosmo.Omega_lambda(), cosmo.h(), -1., 0. ] #params = [self.cosmo_arguments['Omega_m'],self.cosmo_arguments['Omega_fld'],self.cosmo_arguments['h'],-1.,0.] import distances D = distances.Distance(params) for i in range(self.num_points): lensing_da_lognorm[i] = D.angular_diameter_distance(self.zl[i]) chi2 = np.log(lensing_da_lognorm[i] - self.loc[i]) + ( (np.log(lensing_da_lognorm[i] - self.loc[i]) - np.log(self.scale[i])) / self.shape[i])**2. / 2. # return ln(L) lkl -= chi2 return lkl
def __init__(self,zl,zs,nplanes=100,cosmo=[0.25,0.75,0.73]): assert zs > zl D = distances.Distance() self.name = '1D Redshift grid of lens planes, each containing precalculated quantities ' self.zmax = zs*1.0 self.zs = zs*1.0 self.zltrue = zl self.nplanes = nplanes self.cosmo = cosmo # These are the plane redshifts: self.redshifts,self.dz = self.redshiftbins = numpy.linspace(0.0,self.zmax,self.nplanes,endpoint=True,retstep=True) self.redshifts += (self.dz/2.) self.nz = len(self.redshifts) # Snap lens to grid, and compute special distances: self.zl = self.snap([zl])[0][0] self.Da_l = D.Da(zl) self.Da_s = D.Da(zs) self.Da_ls = D.Da(zl,zs) self.plane = {} # Grid planes: self.Da_p = numpy.zeros(self.nz) self.rho_crit = numpy.zeros(self.nz) self.Da_ps = numpy.zeros(self.nz) self.Da_pl = numpy.zeros(self.nz) self.sigma_crit = numpy.zeros(self.nz) self.beta = numpy.zeros(self.nz) for i in range(self.nz): z = self.redshifts[i] self.Da_p[i] = D.Da(0,z) self.rho_crit[i] = D.rho_crit_univ(z) self.Da_ps[i] = D.Da(z,zs) self.Da_pl[i] = D.Da(z,zl) self.sigma_crit[i] = (1.663*10**18)*(self.Da_s/(self.Da_p[i]*self.Da_ps[i])) # units M_sun/Mpc^2 if z > zl: # 1 is lens, 2 is perturber D1s = self.Da_ls D2 = self.Da_p[i] else: # 1 is perturber, 2 is lens D1s = self.Da_ps[i] D2 = self.Da_l D12 = self.Da_pl[i] self.beta[i] = (D12*self.Da_s)/(D2*D1s) return
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 = cPickle.load( splinedump) except IOError or EOFError: self.redshiftfunctions() else: self.redshiftfunctions()
import distances import lenspop # Simulate all lenses on the sky - takes about 7 hours: # fsky = 1 # Fast test - under a minute: fsky = 0.001 D = distances.Distance() Lpop = lenspop.LensPopulation(reset=True, sigfloor=100, zlmax=2, D=D) Ndeflectors = Lpop.Ndeflectors(2, zmin=0, fsky=fsky) L = lenspop.LensSample(reset=False, sigfloor=100, cosmo=[0.3,0.7,0.7], sourcepop="lsst") L.Generate_Lens_Pop(int(Ndeflectors), firstod=1, nsources=1, prunenonlenses=True)