def tot_num_src(redshift_evolution, cosmology, zmax, density): integrand = lambda z: redshift_evolution(z) * \ diff_comoving_volume(z, **cosmology) norm = 4 * np.pi * scipy.integrate.quad(integrand, 0, zmax)[0] area = 4 * np.pi * scipy.integrate.quad(integrand, 0, 0.01)[0] vlocal = comoving_volume(0.01, **cosmology) Ntotal = density * vlocal / (area / norm) return Ntotal, norm
def dvdz(z): # Planck best-fit parameters cosmo = {'omega_M_0': 0.316, 'omega_lambda_0': 0.684, 'omega_b_0': 0.049, 'N_eff': 3.046, 'h': 0.67, 'ns': 0.962, 'sigma_8': 0.834, 'gamma': 0.55, 'w0': -1., 'wa': 0., 'sigma_nl': 7.} cosmo = cd.set_omega_k_0(cosmo) Vc = cd.diff_comoving_volume(z, **cosmo) return Vc
def test_figure5(): """Plot Hogg fig. 5: The dimensionless comoving volume element (1/DH)^3(dVC/dz). The three curves are for the three world models, (omega_M, omega_lambda) = (1, 0), solid; (0.05, 0), dotted; and (0.2, 0.8), dashed. """ z = numpy.arange(0, 5.05, 0.05) cosmo = {} cosmo['omega_M_0'] = numpy.array([[1.0], [0.05], [0.2]]) cosmo['omega_lambda_0'] = numpy.array([[0.0], [0.0], [0.8]]) cosmo['h'] = 0.5 cd.set_omega_k_0(cosmo) linestyle = ['-', ':', '--'] dh = cd.hubble_distance_z(0, **cosmo) dVc = cd.diff_comoving_volume(z, **cosmo) dVc_normed = dVc / (dh**3.) Vc = cd.comoving_volume(z, **cosmo) dz = z[1:] - z[:-1] dVc_numerical = (Vc[:, 1:] - Vc[:, :-1]) / dz / (4. * numpy.pi) dVc_numerical_normed = dVc_numerical / (dh**3.) pylab.figure(figsize=(6, 6)) for i in range(len(linestyle)): pylab.plot(z, dVc_normed[i], ls=linestyle[i], lw=2.) pylab.plot(z[:-1], dVc_numerical_normed[i], ls=linestyle[i], c='k', alpha=0.1) pylab.xlim(0, 5) pylab.ylim(0, 1.1) pylab.xlabel("redshift z") pylab.ylabel(r"comoving volume element $[1/D_H^3]$ $dV_c/dz/d\Omega$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def dvdz(z): ''' this function is to calculate the diff comoving volume the results are given in units of Mpc^3. to use this function you need to install cosmolopy. Also note that the cosmological parameters are Planck best-fit parameters. ''' cosmo = {'omega_M_0': 0.316, 'omega_lambda_0': 0.684, 'omega_b_0': 0.049, 'N_eff': 3.046, 'h': 0.67, 'ns': 0.962, 'sigma_8': 0.834, 'gamma': 0.55, 'w0': -1., 'wa': 0., 'sigma_nl': 7.} cosmo = cd.set_omega_k_0(cosmo) Vc = cd.diff_comoving_volume(z, **cosmo) return Vc
def test_figure5(): """Plot Hogg fig. 5: The dimensionless comoving volume element (1/DH)^3(dVC/dz). The three curves are for the three world models, (omega_M, omega_lambda) = (1, 0), solid; (0.05, 0), dotted; and (0.2, 0.8), dashed. """ z = numpy.arange(0, 5.05, 0.05) cosmo = {} cosmo['omega_M_0'] = numpy.array([[1.0],[0.05],[0.2]]) cosmo['omega_lambda_0'] = numpy.array([[0.0],[0.0],[0.8]]) cosmo['h'] = 0.5 cd.set_omega_k_0(cosmo) linestyle = ['-', ':', '--'] dh = cd.hubble_distance_z(0, **cosmo) dVc = cd.diff_comoving_volume(z, **cosmo) dVc_normed = dVc/(dh**3.) Vc = cd.comoving_volume(z, **cosmo) dz = z[1:] - z[:-1] dVc_numerical = (Vc[:,1:] - Vc[:,:-1])/dz/(4. * numpy.pi) dVc_numerical_normed = dVc_numerical/(dh**3.) pylab.figure(figsize=(6,6)) for i in range(len(linestyle)): pylab.plot(z, dVc_normed[i], ls=linestyle[i], lw=2.) pylab.plot(z[:-1], dVc_numerical_normed[i], ls=linestyle[i], c='k', alpha=0.1) pylab.xlim(0,5) pylab.ylim(0,1.1) pylab.xlabel("redshift z") pylab.ylabel(r"comoving volume element $[1/D_H^3]$ $dV_c/dz/d\Omega$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def volume(z, area, cosmo=cosmo): omega = (area / 41253.0) * 4.0 * np.pi # str volperstr = cd.diff_comoving_volume(z, **cosmo) # cMpc^3 str^-1 dz^-1 return omega * volperstr # cMpc^3 dz^-1
def volwmag(z): #if __name__ == "__main__": if (len(sys.argv)>1): lensmodels = sys.argv[1] else: # lensmodels='lensmodels.lis' lensmodels='vp_lensmodels.lis' if not (os.path.isfile(lensmodels)): print 'missing startup file' sys.exit() clist=asciitable.read(lensmodels, names=['alias','clusterdir','deflxfile','deflyfile','segfile','zcluster','zmodel']) # Observed F160W AB magnitude is 25.7. Its restframe B-band magnitude # is approximately -22.4, uncorrected for the magnification of ~15.5. # So the corrected absolute magnitude is -22.4+2.5*log(15.5) = -19.4. # a reasonable grid of magnifications #mu=np.linspace(0.2,120,100) mu=np.linspace(1,100,100) # representative magnifications ###magref=[5.4, 8.0, 13.5, 14.5, 18.7, 57.7] magref=[1, 2, 3, 4, 5, 5.4, 6, 6.6, 7, 7.5, 8.0, 9, 10, 11, 12, 13, 13.5, 14, 14.5, 15, 16, 17, 18, 18.7, 20, 25, 30, 35, 40, 45, 50, 57.7, 60] # set the anchor point of Mref <-> muref ### Mref, muref = -19.5, 14.5 Mref, muref = -19.5, 9.0 Mlim = Mref+2.5*np.log10(mu/muref) def getmu(Mag): return muref*10**(0.4*(Mag-Mref)) TotalVolarrayWithSeg = np.zeros(mu.shape) TotalVolarray = np.zeros(mu.shape) # target source redshift for rescaling model deflection maps # *** #ztarget = 9.5 #ztarget = 9.6 #ztarget = 5.5 ztarget = z # Plot stuff fig=plt.figure() MFig=fig.add_subplot(111) MFig.set_xlabel('Magnification [$\mu$]') MFig.set_ylabel('Effective Volume (>$\mu$) [Mpc$^3$]') MFig.set_xlim(0.2,100) MFig.set_ylim(1.0,2e5) MFig.set_xscale('log') MFig.set_yscale('log') # some annotations # *** MFig.text(30,2e4,'z=[9,10]',size=13) #MFig.text(30,2e4,'z=[5,6]',size=13) ytext = 1e5 # *** #MFig.text(0.22,ytext,'Unlensed M$_{B}$ AB limit:',size=10) ## including some absolute magnitudes that correspond to magnifications #plotmus=[-18.0,Mref,-21.0,-22.0] #for pp in plotmus: MFig.text(getmu(pp)/1.2,ytext,'%.1f' % pp,size=10) outdata = open('volumedata_a1689.dat','w') for ii in np.arange(clist.size): #for ii in [0]: alias = clist['alias'][ii] clusterdir = clist['clusterdir'][ii] deflxfile = clist['deflxfile'][ii] deflyfile = clist['deflyfile'][ii] segfile = clist['segfile'][ii] zcluster = clist['zcluster'][ii] zmodel = clist['zmodel'][ii] rescale = \ (cdad(ztarget, zcluster, **cosmo) / cdad(ztarget, **cosmo)) * \ (cdad(zmodel, **cosmo) / cdad(zmodel, zcluster, **cosmo)) # read in the deflections from Adi's lens models axlist = pyfits.open(clusterdir+'/'+deflxfile) aylist = pyfits.open(clusterdir+'/'+deflyfile) ax, ay = rescale*axlist[0].data, rescale*aylist[0].data # read in the segmentation map, which we are implicitly assuming has # already been wregistered to the model try: segfile = pyfits.open(clusterdir+'/'+segfile) segmap=segfile[0].data segflag = 1 except: segflag = 0 segmap=ax*0.0 # do some initializations etc Unity = np.zeros(ax.shape)+1.0 header = axlist[0].header try: cdelt1, cdelt2 = header['CDELT1'], header['CDELT2'] header['CDELT1'], header['CDELT2'] = cdelt1, cdelt2 pxsc = np.abs(cdelt1)*3600.0 # in arcseconds per linear pixel dimension except: cd1_1, cd2_2 = header['CD1_1'], header['CD2_2'] pxsc = np.abs(cd1_1)*3600.0 # in arcseconds per linear pixel dimension # Calculate the magnification from the Jacobian. Note that it first # calculates the gradient with respect to the 'y' axis, and then wrt # the 'x' axis. axy, axx = np.gradient(ax) ayy, ayx = np.gradient(ay) Jxx = Unity -axx Jxy = -axy Jyx = -ayx Jyy = Unity -ayy Mu = Unity / (Jxx*Jyy - Jxy*Jyx) AbsMu = np.abs(Mu) # define the total wfc3ir outline mask # regionfile = clusterdir+'/'+'wfc3ir_outline.reg' regionfile = clusterdir+'/'+'acs_outline.reg' rwcs=pyregion.open(regionfile) rcoo=pyregion.open(regionfile).as_imagecoord(header) maskboo=rwcs.get_mask(hdu=axlist[0]) # rmask=np.zeros(ax.shape) # rmask[(maskboo)]=1.0 # The diff_comoving_volume is the differential comoving volume per # unit redshift per unit solid angle, in units of Mpc**3 ster**-1. So # we convert that to the Volume per (unlensed) pixel, for a source # plane at ztarget. VolPix = (pxsc/206265.0)**2 * cd.diff_comoving_volume(ztarget, **cosmo) # PixMap will now be the Mpc**3 volume that each pixel corresponds to # in the z=9-10 source plane. PixMap = VolPix / AbsMu # Now let's zap the areas of the mosaic that are covered by objects # via the IR-detected segmentation map. # /Volumes/Archive/CLASH/archive.stsci.edu/pub/clash/outgoing/macs1149/HST/catalogs/mosaicdrizzle_image_pipeline/IR_detection/SExtractor # Now let us calculate the source-plane volume for each of the # magnification lower limits we established. VolarrayWithSeg = np.zeros(mu.shape) Volarray = np.zeros(mu.shape) for jj in np.arange(mu.size): # VolarrayWithSeg[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (rmask==1.0) & (segmap==0) )] ) # Volarray[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (rmask==1.0))] ) VolarrayWithSeg[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (maskboo) & (segmap==0) )] ) Volarray[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (maskboo))] ) TotalVolarrayWithSeg += VolarrayWithSeg TotalVolarray += Volarray s=si.UnivariateSpline(np.log10(mu),np.log10(VolarrayWithSeg),s=5) print alias,clusterdir,10**s(np.log10(muref)) outstring = '%s %s %.1f ' % (alias,clusterdir,10**s(np.log10(muref))) outdata.write(outstring+'\n') # need to write the mu, Volarray data to a file.... MFig.plot(mu,Volarray,label=alias) MFig.plot(mu,VolarrayWithSeg,'--') MFig.legend(loc=3,prop={'size':8}) # no error checking here yet... sws = si.UnivariateSpline(np.log10(mu),np.log10(TotalVolarrayWithSeg),s=5) s = si.UnivariateSpline(np.log10(mu),np.log10(TotalVolarray),s=5) volwithseg = (np.asarray(10**sws(np.log10(magref)))).reshape(len(magref), 1) volnoseg = (np.asarray(10**s(np.log10(magref)))).reshape(len(magref),1) magref = (np.asarray(magref)).reshape(len(magref),1) MVolArray = np.hstack((magref, volnoseg, volwithseg)) return MVolArray
def calc_dN(LF, logL0, z0, logLbinwidth, zbinwidth, N_tot, int_norm, cosmology): LF_val = LF(z0, logL0) return (4*np.pi*LF_val*diff_comoving_volume(z0, **cosmology)/int_norm) * \ logLbinwidth*zbinwidth*N_tot
def volz(minmu, zmin=2.5, zmax=11.5): clist = asciitable.read('lensmodels.lis', names=[ 'alias', 'clusterdir', 'deflxfile', 'deflyfile', 'segfile', 'zcluster', 'zmodel' ]) # Observed F160W AB magnitude is 25.7. Its restframe B-band magnitude # is approximately -22.4, uncorrected for the magnification of ~15.5. # So the corrected absolute magnitude is -22.4+2.5*log(15.5) = -19.4. # target source redshift for rescaling model deflection maps spacing = zmax - zmin + 1 ztarget = np.linspace(zmin, zmax, spacing) # a reasonable grid of magnifications mu = np.linspace(0.2, 120, 100) # fiducial threshold magnification mufiducial = minmu mustr = '%.1f' % mufiducial # set the anchor point of Mref <-> muref Mref, muref = -19.5, 9.0 #Mref, muref = -19.4, 15.5 Mlim = Mref + 2.5 * np.log10(mu / muref) def getmu(Mag): return muref * 10**(0.4 * (Mag - Mref)) TotalVolarray = np.zeros(mu.shape) TotalRedarray = np.zeros(ztarget.shape) # Plot stuff fig = plt.figure() MFig = fig.add_subplot(111) MFig.set_xlabel('Redshift [z]') MFig.set_ylabel('Effective Volume ($\mu>$' + mustr + ') [Mpc$^3$]') MFig.set_xlim(2.0, 12) MFig.set_ylim(1.0, 2e5) MFig.set_yscale('log') # # some annotations # MFig.text(30,2e4,'z=[9,10]',size=13) # ytext = 1e5 # MFig.text(0.22,ytext,'Unlensed M$_{B}$ [AB] limit:',size=10) # plotmus=[-18.0,Mref,-21.0,-22.0] # for pp in plotmus: MFig.text(getmu(pp)/1.2,ytext,'%.1f' % pp,size=10) # outdata = open('redshiftdata.dat','w') for ii in np.arange(clist.size): alias = clist['alias'][ii] clusterdir = clist['clusterdir'][ii] deflxfile = clist['deflxfile'][ii] deflyfile = clist['deflyfile'][ii] zcluster = clist['zcluster'][ii] zmodel = clist['zmodel'][ii] # read in the deflections from Adi's lens models axlist = pyfits.open(clusterdir + '/' + deflxfile) aylist = pyfits.open(clusterdir + '/' + deflyfile) # ax, ay = rescale*axlist[0].data, rescale*aylist[0].data ax, ay = axlist[0].data, aylist[0].data # do some initializations etc Unity = np.zeros(ax.shape) + 1.0 header = axlist[0].header try: cdelt1, cdelt2 = header['CDELT1'], header['CDELT2'] header['CDELT1'], header['CDELT2'] = cdelt1, cdelt2 pxsc = np.abs( cdelt1) * 3600.0 # in arcseconds per linear pixel dimension except: cd1_1, cd2_2 = header['CD1_1'], header['CD2_2'] pxsc = np.abs( cd1_1) * 3600.0 # in arcseconds per linear pixel dimension regionfile = clusterdir + '/' + 'acs_outline.reg' rwcs = pyregion.open(regionfile) rcoo = pyregion.open(regionfile).as_imagecoord(header) maskboo = rwcs.get_mask(hdu=axlist[0]) Redarray = np.zeros(ztarget.shape) for zi in np.arange(ztarget.size): #print alias, ztarget[zi] rescale = \ (cdad(ztarget[zi], zcluster, **cosmo) / cdad(ztarget[zi], **cosmo)) * \ (cdad(zmodel, **cosmo) / cdad(zmodel, zcluster, **cosmo)) # Calculate the magnification from the Jacobian. Note that it first # calculates the gradient with respect to the 'y' axis, and then wrt # the 'x' axis. axy, axx = np.gradient(rescale * ax) ayy, ayx = np.gradient(rescale * ay) Jxx = Unity - axx Jxy = -axy Jyx = -ayx Jyy = Unity - ayy Mu = Unity / (Jxx * Jyy - Jxy * Jyx) AbsMu = np.abs(Mu) # The diff_comoving_volume is the differential comoving volume per # unit redshift per unit solid angle, in units of Mpc**3 ster**-1. So # we convert that to the Volume per (unlensed) pixel, for a source # plane at z=9-10. VolPix = (pxsc / 206265.0)**2 * cd.diff_comoving_volume( ztarget[zi], **cosmo) # PixMap will now be the Mpc**3 volume that each pixel corresponds to # in the z=9-10 source plane. PixMap = VolPix / AbsMu Redarray[zi] = np.sum(PixMap[((AbsMu > mufiducial) & (maskboo))]) TotalRedarray += Redarray MFig.plot(ztarget, Redarray, label=alias) MFig.legend(loc=3, prop={'size': 8}) MFig.plot(ztarget, TotalRedarray, linewidth=4, color='b', label='CLASH 12') MFig.legend(loc=3, prop={'size': 10}) d1 = len(ztarget) VolZarray = ztarget.reshape(d1, 1) TotalRedarray = TotalRedarray.reshape(d1, 1) VolZarray = np.hstack((VolZarray, TotalRedarray)) return VolZarray
def volwmag(z, mumin=1, mumax=100): #if __name__ == "__main__": if (len(sys.argv)>1): lensmodels = sys.argv[1] else: # lensmodels='lensmodels.lis' lensmodels='vp_lensmodels.lis' if not (os.path.isfile(lensmodels)): print 'missing startup file' sys.exit() clist=asciitable.read(lensmodels, names=['alias','clusterdir','deflxfile','deflyfile','segfile','zcluster','zmodel']) # Observed F160W AB magnitude is 25.7. Its restframe B-band magnitude # is approximately -22.4, uncorrected for the magnification of ~15.5. # So the corrected absolute magnitude is -22.4+2.5*log(15.5) = -19.4. # a reasonable grid of magnifications #mu=np.linspace(0.2,120,100) mu=np.linspace(1,100,100) # representative magnifications ###magref=[5.4, 8.0, 13.5, 14.5, 18.7, 57.7] #magref=[1, 2, 3, 4, 5, 5.4, 6, 6.6, 7, 7.5, 8.0, 9, 10, 11, 12, 13, 13.5, 14, 14.5, 15, 16, 17, 18, 18.7, 20, 25, 30, 35, 40, 45, 50, 57.7, 60] mspacing = mumax - mumin + 1 magref = np.linspace(mumin, mumax, mspacing) # set the anchor point of Mref <-> muref ### Mref, muref = -19.5, 14.5 Mref, muref = -19.5, 9.0 Mlim = Mref+2.5*np.log10(mu/muref) def getmu(Mag): return muref*10**(0.4*(Mag-Mref)) TotalVolarrayWithSeg = np.zeros(mu.shape) TotalVolarray = np.zeros(mu.shape) # target source redshift for rescaling model deflection maps # *** #ztarget = 9.5 #ztarget = 9.6 #ztarget = 5.5 ztarget = z # Plot stuff fig=plt.figure() MFig=fig.add_subplot(111) MFig.set_xlabel('Magnification [$\mu$]') MFig.set_ylabel('Effective Volume (>$\mu$) [Mpc$^3$]') MFig.set_xlim(0.2,100) MFig.set_ylim(1.0,2e5) MFig.set_xscale('log') MFig.set_yscale('log') # some annotations # *** MFig.text(30,2e4,'z=[9,10]',size=13) #MFig.text(30,2e4,'z=[5,6]',size=13) ytext = 1e5 # *** #MFig.text(0.22,ytext,'Unlensed M$_{B}$ AB limit:',size=10) ## including some absolute magnitudes that correspond to magnifications #plotmus=[-18.0,Mref,-21.0,-22.0] #for pp in plotmus: MFig.text(getmu(pp)/1.2,ytext,'%.1f' % pp,size=10) outdata = open('volumedata_a1689.dat','w') for ii in np.arange(clist.size): #for ii in [0]: alias = clist['alias'][ii] clusterdir = clist['clusterdir'][ii] deflxfile = clist['deflxfile'][ii] deflyfile = clist['deflyfile'][ii] segfile = clist['segfile'][ii] zcluster = clist['zcluster'][ii] zmodel = clist['zmodel'][ii] rescale = \ (cdad(ztarget, zcluster, **cosmo) / cdad(ztarget, **cosmo)) * \ (cdad(zmodel, **cosmo) / cdad(zmodel, zcluster, **cosmo)) # read in the deflections from Adi's lens models axlist = pyfits.open(clusterdir+'/'+deflxfile) aylist = pyfits.open(clusterdir+'/'+deflyfile) ax, ay = rescale*axlist[0].data, rescale*aylist[0].data # read in the segmentation map, which we are implicitly assuming has # already been wregistered to the model try: segfile = pyfits.open(clusterdir+'/'+segfile) segmap=segfile[0].data segflag = 1 except: segflag = 0 segmap=ax*0.0 # do some initializations etc Unity = np.zeros(ax.shape)+1.0 header = axlist[0].header try: cdelt1, cdelt2 = header['CDELT1'], header['CDELT2'] header['CDELT1'], header['CDELT2'] = cdelt1, cdelt2 pxsc = np.abs(cdelt1)*3600.0 # in arcseconds per linear pixel dimension except: cd1_1, cd2_2 = header['CD1_1'], header['CD2_2'] pxsc = np.abs(cd1_1)*3600.0 # in arcseconds per linear pixel dimension # Calculate the magnification from the Jacobian. Note that it first # calculates the gradient with respect to the 'y' axis, and then wrt # the 'x' axis. axy, axx = np.gradient(ax) ayy, ayx = np.gradient(ay) Jxx = Unity -axx Jxy = -axy Jyx = -ayx Jyy = Unity -ayy Mu = Unity / (Jxx*Jyy - Jxy*Jyx) AbsMu = np.abs(Mu) # define the total wfc3ir outline mask # regionfile = clusterdir+'/'+'wfc3ir_outline.reg' regionfile = clusterdir+'/'+'acs_outline.reg' rwcs=pyregion.open(regionfile) rcoo=pyregion.open(regionfile).as_imagecoord(header) maskboo=rwcs.get_mask(hdu=axlist[0]) # rmask=np.zeros(ax.shape) # rmask[(maskboo)]=1.0 # The diff_comoving_volume is the differential comoving volume per # unit redshift per unit solid angle, in units of Mpc**3 ster**-1. So # we convert that to the Volume per (unlensed) pixel, for a source # plane at ztarget. VolPix = (pxsc/206265.0)**2 * cd.diff_comoving_volume(ztarget, **cosmo) # PixMap will now be the Mpc**3 volume that each pixel corresponds to # in the z=9-10 source plane. PixMap = VolPix / AbsMu # Now let's zap the areas of the mosaic that are covered by objects # via the IR-detected segmentation map. # /Volumes/Archive/CLASH/archive.stsci.edu/pub/clash/outgoing/macs1149/HST/catalogs/mosaicdrizzle_image_pipeline/IR_detection/SExtractor # Now let us calculate the source-plane volume for each of the # magnification lower limits we established. VolarrayWithSeg = np.zeros(mu.shape) Volarray = np.zeros(mu.shape) for jj in np.arange(mu.size): # VolarrayWithSeg[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (rmask==1.0) & (segmap==0) )] ) # Volarray[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (rmask==1.0))] ) VolarrayWithSeg[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (maskboo) & (segmap==0) )] ) Volarray[jj] = np.sum( PixMap[((AbsMu>mu[jj]) & (maskboo))] ) TotalVolarrayWithSeg += VolarrayWithSeg TotalVolarray += Volarray s=si.UnivariateSpline(np.log10(mu),np.log10(VolarrayWithSeg),s=5) print alias,clusterdir,10**s(np.log10(muref)) outstring = '%s %s %.1f ' % (alias,clusterdir,10**s(np.log10(muref))) outdata.write(outstring+'\n') # need to write the mu, Volarray data to a file.... MFig.plot(mu,Volarray,label=alias) MFig.plot(mu,VolarrayWithSeg,'--') MFig.legend(loc=3,prop={'size':8}) # no error checking here yet... sws = si.UnivariateSpline(np.log10(mu),np.log10(TotalVolarrayWithSeg),s=5) s = si.UnivariateSpline(np.log10(mu),np.log10(TotalVolarray),s=5) volwithseg = (np.asarray(10**sws(np.log10(magref)))).reshape(len(magref), 1) volnoseg = (np.asarray(10**s(np.log10(magref)))).reshape(len(magref),1) magref = (np.asarray(magref)).reshape(len(magref),1) MVolArray = np.hstack((magref, volnoseg, volwithseg)) return MVolArray
def volz(minmu, zmin=2.5, zmax=11.5): clist=asciitable.read('lensmodels.lis', names=['alias','clusterdir','deflxfile','deflyfile','segfile', 'zcluster','zmodel']) # Observed F160W AB magnitude is 25.7. Its restframe B-band magnitude # is approximately -22.4, uncorrected for the magnification of ~15.5. # So the corrected absolute magnitude is -22.4+2.5*log(15.5) = -19.4. # target source redshift for rescaling model deflection maps spacing = zmax - zmin + 1 ztarget = np.linspace(zmin,zmax,spacing) # a reasonable grid of magnifications mu=np.linspace(0.2,120,100) # fiducial threshold magnification mufiducial = minmu mustr = '%.1f' % mufiducial # set the anchor point of Mref <-> muref Mref, muref = -19.5, 9.0 #Mref, muref = -19.4, 15.5 Mlim = Mref+2.5*np.log10(mu/muref) def getmu(Mag): return muref*10**(0.4*(Mag-Mref)) TotalVolarray = np.zeros(mu.shape) TotalRedarray = np.zeros(ztarget.shape) # Plot stuff fig=plt.figure() MFig=fig.add_subplot(111) MFig.set_xlabel('Redshift [z]') MFig.set_ylabel('Effective Volume ($\mu>$'+mustr+') [Mpc$^3$]') MFig.set_xlim(2.0,12) MFig.set_ylim(1.0,2e5) MFig.set_yscale('log') # # some annotations # MFig.text(30,2e4,'z=[9,10]',size=13) # ytext = 1e5 # MFig.text(0.22,ytext,'Unlensed M$_{B}$ [AB] limit:',size=10) # plotmus=[-18.0,Mref,-21.0,-22.0] # for pp in plotmus: MFig.text(getmu(pp)/1.2,ytext,'%.1f' % pp,size=10) # outdata = open('redshiftdata.dat','w') for ii in np.arange(clist.size): alias = clist['alias'][ii] clusterdir = clist['clusterdir'][ii] deflxfile = clist['deflxfile'][ii] deflyfile = clist['deflyfile'][ii] zcluster = clist['zcluster'][ii] zmodel = clist['zmodel'][ii] # read in the deflections from Adi's lens models axlist = pyfits.open(clusterdir+'/'+deflxfile) aylist = pyfits.open(clusterdir+'/'+deflyfile) # ax, ay = rescale*axlist[0].data, rescale*aylist[0].data ax, ay = axlist[0].data, aylist[0].data # do some initializations etc Unity = np.zeros(ax.shape)+1.0 header = axlist[0].header try: cdelt1, cdelt2 = header['CDELT1'], header['CDELT2'] header['CDELT1'], header['CDELT2'] = cdelt1, cdelt2 pxsc = np.abs(cdelt1)*3600.0 # in arcseconds per linear pixel dimension except: cd1_1, cd2_2 = header['CD1_1'], header['CD2_2'] pxsc = np.abs(cd1_1)*3600.0 # in arcseconds per linear pixel dimension regionfile = clusterdir+'/'+'acs_outline.reg' rwcs=pyregion.open(regionfile) rcoo=pyregion.open(regionfile).as_imagecoord(header) maskboo=rwcs.get_mask(hdu=axlist[0]) Redarray=np.zeros(ztarget.shape) for zi in np.arange(ztarget.size): #print alias, ztarget[zi] rescale = \ (cdad(ztarget[zi], zcluster, **cosmo) / cdad(ztarget[zi], **cosmo)) * \ (cdad(zmodel, **cosmo) / cdad(zmodel, zcluster, **cosmo)) # Calculate the magnification from the Jacobian. Note that it first # calculates the gradient with respect to the 'y' axis, and then wrt # the 'x' axis. axy, axx = np.gradient(rescale*ax) ayy, ayx = np.gradient(rescale*ay) Jxx = Unity -axx Jxy = -axy Jyx = -ayx Jyy = Unity -ayy Mu = Unity / (Jxx*Jyy - Jxy*Jyx) AbsMu = np.abs(Mu) # The diff_comoving_volume is the differential comoving volume per # unit redshift per unit solid angle, in units of Mpc**3 ster**-1. So # we convert that to the Volume per (unlensed) pixel, for a source # plane at z=9-10. VolPix = (pxsc/206265.0)**2 * cd.diff_comoving_volume(ztarget[zi], **cosmo) # PixMap will now be the Mpc**3 volume that each pixel corresponds to # in the z=9-10 source plane. PixMap = VolPix / AbsMu Redarray[zi]=np.sum(PixMap[((AbsMu>mufiducial) & (maskboo))]) TotalRedarray += Redarray MFig.plot(ztarget,Redarray,label=alias) MFig.legend(loc=3,prop={'size':8}) MFig.plot(ztarget,TotalRedarray,linewidth=4,color='b',label='CLASH 12') MFig.legend(loc=3,prop={'size':10}) d1 = len(ztarget) VolZarray = ztarget.reshape(d1, 1) TotalRedarray = TotalRedarray.reshape(d1, 1) VolZarray = np.hstack((VolZarray, TotalRedarray)) return VolZarray
for i in xrange(len(z)): #Hubble Distance dh = cd.hubble_distance_z(z[i], **Cosmology) * cd.e_z(z[i], **Cosmology) #In David Hogg's (arXiv:astro-ph/9905116v4) formalism, this is equivalent to D_H / E(z) = c / (H_0 E(z)) [see his eq. 14], which #appears in the definitions of many other distance measures. dm = cd.comoving_distance_transverse(z[i], **Cosmology) #See equation 16 of David Hogg's arXiv:astro-ph/9905116v4 da = cd.angular_diameter_distance(z[i], **Cosmology) #See equations 18-19 of David Hogg's arXiv:astro-ph/9905116v4 dl = cd.luminosity_distance(z[i], **Cosmology) #Units are Mpc dVc = cd.diff_comoving_volume(z[i], **Cosmology) #The differential comoving volume element dV_c/dz/dSolidAngle. #Dimensions are volume per unit redshift per unit solid angle. #Units are Mpc**3 Steradians^-1. #See David Hogg's arXiv:astro-ph/9905116v4, equation 28 tl = cd.lookback_time(z[i], **Cosmology) #See equation 30 of David Hogg's arXiv:astro-ph/9905116v4. Units are s. agetl = cd.age(z[i], **Cosmology) #Age at z is lookback time at z'->Infinity minus lookback time at z. tH = 3.09e17 / Cosmology['h'] ez = cd.e_z(z[i], **Cosmology) #The unitless Hubble expansion rate at redshift z.
from math import *
# the 'x' axis. axy, axx = np.gradient(rescale * ax) ayy, ayx = np.gradient(rescale * ay) Jxx = Unity - axx Jxy = -axy Jyx = -ayx Jyy = Unity - ayy Mu = Unity / (Jxx * Jyy - Jxy * Jyx) AbsMu = np.abs(Mu) # The diff_comoving_volume is the differential comoving volume per # unit redshift per unit solid angle, in units of Mpc**3 ster**-1. So # we convert that to the Volume per (unlensed) pixel, for a source # plane at z=9-10. VolPix = (pxsc / 206265.0)**2 * cd.diff_comoving_volume( ztarget[zi], **cosmo) # PixMap will now be the Mpc**3 volume that each pixel corresponds to # in the z=9-10 source plane. PixMap = VolPix / AbsMu Redarray[zi] = np.sum(PixMap[(AbsMu > mufiducial)]) TotalRedarray += Redarray MFig.plot(ztarget, Redarray, label=alias) MFig.legend(loc=3, prop={'size': 8}) # # Now let us calculate the source-plane volume for each of the # # magnification lower limits we established. #
for i in xrange(len(z)): #Hubble Distance dh = cd.hubble_distance_z(z[i],**Cosmology)*cd.e_z(z[i],**Cosmology) #In David Hogg's (arXiv:astro-ph/9905116v4) formalism, this is equivalent to D_H / E(z) = c / (H_0 E(z)) [see his eq. 14], which #appears in the definitions of many other distance measures. dm = cd.comoving_distance_transverse(z[i],**Cosmology) #See equation 16 of David Hogg's arXiv:astro-ph/9905116v4 da = cd.angular_diameter_distance(z[i],**Cosmology) #See equations 18-19 of David Hogg's arXiv:astro-ph/9905116v4 dl = cd.luminosity_distance(z[i],**Cosmology) #Units are Mpc dVc = cd.diff_comoving_volume(z[i], **Cosmology) #The differential comoving volume element dV_c/dz/dSolidAngle. #Dimensions are volume per unit redshift per unit solid angle. #Units are Mpc**3 Steradians^-1. #See David Hogg's arXiv:astro-ph/9905116v4, equation 28 tl = cd.lookback_time(z[i],**Cosmology) #See equation 30 of David Hogg's arXiv:astro-ph/9905116v4. Units are s. agetl = cd.age(z[i],**Cosmology) #Age at z is lookback time at z'->Infinity minus lookback time at z. tH = 3.09e17/Cosmology['h'] ez = cd.e_z(z[i],**Cosmology) #The unitless Hubble expansion rate at redshift z.
def Dv(z): '''__________ Dv_________________________''' cosmo = {'omega_M_0' : 0.24, 'omega_lambda_0' : 1.0 - 0.24, 'h' : 0.73} cosmo = cd.set_omega_k_0(cosmo) Dv = cd.diff_comoving_volume(z, **cosmo) return Dv