def Dc2(z1,z2): Dcz1 = (p15.comoving_distance(z1).value*p15.h) Dcz2 = (p15.comoving_distance(z2).value*p15.h) res = Dcz2-Dcz1+1e-8 return res """Dc2(z1,z2) returns comoving distance between two objects at different redshifts. It accepts z1 and z2 as input, which are redshifts of lens and source, respectively.""" """Parameters
def convert_one_from_dir(file_name_base,ncc): mp=7.43e9 zs = 1.0 file_dir = "./15x15/" #file_name_base = "s97" file_in_base = file_dir+file_name_base zl_array = np.fromfile(file_in_base+"_redshift.bin",dtype = ">f") zl = 0.5*(zl_array.max()+zl_array.min()) zD = cosmo.comoving_distance(zl)*cosmo.h zB = cosmo.comoving_distance(zl_array.max())-cosmo.comoving_distance(zl_array.min()) x1 = np.fromfile(file_in_base+"_theta.bin",dtype = ">f") npp=len(x1) # total mass = 1e9*2e5 M_sun/h bsz = 15.0 if ((npp/500000.0)<2): nsa = 1 else: nsa = int(npp/500000.0) #nsa = 1 xc1 = (x1.max()+x1.min())*0.5 x1 = x1[::nsa]-xc1 x2 = np.fromfile(file_in_base+"_phi.bin",dtype = ">f") xc2 = (x2.max()+x2.min())*0.5 x2 = x2[::nsa]-xc2 x3 = (np.random.random_sample((len(x1)))-0.5)*zB/zD*mm.apr/3600 #print zB/zD*mm.apr/3600 #x3 = np.linspace(-0.5,0.5,len(x1))*100.0/zD*mm.apr/3600 #print nsa,len(x1),len(x2),len(x3) if npp > 100: sdens_angular = call_cic_sdens(x1,x2,bsz,ncc,len(x1))*mp/np.deg2rad(1.0)**2.0*npp/len(x1) else: sdens_angular = call_sph_sdens(x1,x2,x3,bsz,ncc,len(x1))*mp/np.deg2rad(1.0)**2.0*npp/len(x1) #sdens_angular_normal = (sdens_angular-sdens_angular.mean()) sdens_angular_normal = sdens_angular Dcl = (cosmo.comoving_distance(zl).value*cosmo.h) Dcs = (cosmo.comoving_distance(zs).value*cosmo.h) Dcls = Dcs-Dcl kappa = 4.0*np.pi*mm.G/mm.vc**2*(1.0+zl)/Dcl*Dcls/Dcs*sdens_angular_normal ##---------------------------- #sdens_normal = sdens_angular_normal/mm.Da(zl)**2.0/mm.sigma_crit(zl,zs) ##---------------------------- #file_out ="./output_files/"+file_name_base+"_"+str(zl)+"_sdens_normal.bin" #sdens_normal.astype(np.float32).tofile(file_out) return kappa,zl
def projected_rho_mean(z1, z2): # return the mean density of the unvierse integrated across redshifts # z1 and z2, in comoving (M_sun/h)(Mpc/h)^-3 pc0 = cosmo.critical_density(0).to(units.Msun / units.Mpc**3).value Om0 = cosmo.Om0 rho_mean_0 = Om0 * pc0 d1 = cosmo.comoving_distance(z1).value d2 = cosmo.comoving_distance(z2).value return rho_mean_0 * (d2 - d1) / cosmo.h
def _SFR_UV(self, z, fmag, nmag, rmag, f_flux): ''' calculate UV star formation rates based on Salim+(2007) Eq. 5, 7, 8. :param z: redshift :param fmag: FUV absolute magnitude :param nmag: NUV absolute magnitude :param rmag: r-band absolute magnitude :param f_flux: FUV flux in Janskies. See `_jansky` method for conversion ''' from astropy.cosmology import WMAP7 fn = fmag - nmag opt = nmag - rmag # N-r #Luminosity Distance dist = WMAP7.comoving_distance(z) ldist = (1 + z) * dist.value #calculating Attenuation 'atten' atten = np.repeat(-999., len(fmag)) case1 = np.where((opt > 4.) & (fn < 0.95)) atten[case1] = 3.32 * fn[case1] + 0.22 case2 = np.where((opt > 4.) & (fn >= 0.95)) atten[case2] = 3.37 case3 = np.where((opt <= 4.) & (fn < 0.9)) atten[case3] = 2.99 * fn[case3] + 0.27 case4 = np.where((opt <= 4.) & (fn >= 0.9)) atten[case4] = 2.96 #if opt >= 4.0: # if fn < 0.95: # atten = 3.32*fn + 0.22 # else: # atten = 3.37 #else: # if fn < 0.90: # atten = 2.99*fn +0.27 # else: # atten = 2.96 lum = 4. * np.pi * (ldist**2.0) * (3.087**2.0) * (10**( 25.0 + (atten / 2.5))) * f_flux #Luminosity sfr = 1.08 * (10**(-28.0)) * np.abs(lum) return sfr
def UVsfr(z, fmag, nmag, rmag, f_flux): ''' Calculate UV star formation rates. Inputs: NSAID,z,F-band magnitude, N-band magnitude, r-band magnitude, F-band flux in Janskies ''' fn = fmag - nmag opt = nmag - rmag # N-r #Luminosity Distance dist = WMAP7.comoving_distance(z) ldist = (1 + z) * dist #calculating Attenuation 'atten' atten = np.repeat(-999., len(fmag)) case1 = np.where((opt > 4.) & (fn < 0.95)) atten[case1] = 3.32 * fn[case1] + 0.22 case2 = np.where((opt > 4.) & (fn >= 0.95)) atten[case2] = 3.37 case3 = np.where((opt <= 4.) & (fn < 0.9)) atten[case3] = 2.99 * fn[case3] + 0.27 case4 = np.where((opt <= 4.) & (fn >= 0.9)) atten[case4] = 2.96 #if opt >= 4.0: # if fn < 0.95: # atten = 3.32*fn + 0.22 # else: # atten = 3.37 #else: # if fn < 0.90: # atten = 2.99*fn +0.27 # else: # atten = 2.96 lum = 4. * np.pi * (ldist**2.0) * (3.087**2.0) * (10**( 25.0 + (atten / 2.5))) * f_flux #Luminosity sfr = 1.08 * (10**(-28.0)) * np.abs(lum) return sfr
def uvsfr(id, z, fmag, nmag, rmag, f_flux): fn = fmag - nmag opt = nmag - rmag # N-r #Luminosity Distance dist = WMAP7.comoving_distance(z) ldist = (1 + z) * dist #calculating Attenuation 'a' if opt >= 4.0: if fn < 0.95: a = 3.32 * float(fn) + 0.22 else: a = 3.37 else: if fn < 0.90: a = 2.99 * float(fn) + 0.27 else: a = 2.96 lum = 4 * 3.14159 * (ldist**2.0) * (3.087**2.0) * (10**( 25.0 + (a / 2.5))) * f_flux #Luminosity sfr = 1.08 * (10**(-28.0)) * abs(lum) return sfr
def dcomv(z): return cosmo.comoving_distance(z).value * h #in Mpc/h
def Dc(z): res = p15.comoving_distance(z).value * p15.h return res
def __init__(self, snapnum, subhalos, mi, ci, RA_deg, DEC_deg, snapz, galaxy_camera_posx, galaxy_camera_posy, galaxy_camera_posz, centerz, galaxy_camera_velx, galaxy_camera_vely, galaxy_camera_velz, cyl, gmag): #fields=['SubhaloMass','SubhaloMassInMaxRad','SubhaloMassInRadType','SubhaloMassInMaxRadType','SubhaloPos','SubhaloSFR','SubhaloSFRinRad','SubhaloVel','SubhaloBHMass','SubhaloBHMdot','SubhaloStellarPhotometrics','SubhaloWindMass'] self.snapshot_number = snapnum + np.zeros_like(ci) self.subhalo_index = subhalos['SubFindID'][mi[ci]] self.RA_deg = RA_deg self.DEC_deg = DEC_deg self.snapz = snapz + np.zeros_like(RA_deg) self.center_z = centerz + np.zeros_like(RA_deg) self.cylinder_number = cyl + np.zeros_like(self.subhalo_index) self.galaxy_comoving_x_mpc = galaxy_camera_posx[ci] / 1000.0 self.galaxy_comoving_y_mpc = galaxy_camera_posy[ci] / 1000.0 self.galaxy_comoving_z_mpc = galaxy_camera_posz[ci] / 1000.0 #self.galaxy_camera_posx = galaxy_camera_posx[ci]/1000.0 #self.galaxy_camera_posy = galaxy_camera_posy[ci]/1000.0 #self.galaxy_camera_posz = galaxy_camera_posz[ci]/1000.0 self.galaxy_camera_velx = galaxy_camera_velx[ci] self.galaxy_camera_vely = galaxy_camera_vely[ci] self.galaxy_camera_velz = galaxy_camera_velz[ci] self.galaxy_peculiar_vr = 1.0 * self.galaxy_camera_velz self.galaxy_peculiar_z = 1.0 * self.galaxy_peculiar_vr / ( astropy.constants.c.value / 1.0e3) self.cosmological_redshift = np.zeros_like(self.RA_deg) for i, index in enumerate(ci): self.cosmological_redshift[i] = np.float64( z_at_value(WMAP7.comoving_distance, self.galaxy_comoving_z_mpc[i] * u.megaparsec, ztol=1e-12, maxfun=2000)) self.hubble_velocity = self.cosmological_redshift * astropy.constants.c.value / 1.0e3 #in km/s self.galaxy_observed_z = 1.0 * self.cosmological_redshift + self.galaxy_peculiar_z #self.galaxy_comoving_x_mpc = self.galaxy_camera_posx*(1.0 + self.cosmological_redshift) #self.galaxy_comoving_y_mpc = self.galaxy_camera_posy*(1.0 + self.cosmological_redshift) #self.galaxy_comoving_z_mpc = self.galaxy_camera_posz*(1.0 + self.cosmological_redshift) self.galaxy_camera_posx = self.galaxy_comoving_x_mpc / ( 1.0 + self.cosmological_redshift) self.galaxy_camera_posy = self.galaxy_comoving_y_mpc / ( 1.0 + self.cosmological_redshift) self.galaxy_camera_posz = self.galaxy_comoving_z_mpc / ( 1.0 + self.cosmological_redshift) self.angdiam_mpc = np.asarray( WMAP7.angular_diameter_distance(self.cosmological_redshift)) self.kpc_per_arcsec = np.asarray( WMAP7.kpc_proper_per_arcmin(self.cosmological_redshift) / 60.0) self.observed_angdiam_mpc = np.asarray( WMAP7.angular_diameter_distance(self.galaxy_observed_z)) self.observed_comoving_mpc = np.asarray( WMAP7.comoving_distance(self.galaxy_observed_z)) self.observed_kpc_per_arcsec = np.asarray( WMAP7.kpc_proper_per_arcmin(self.galaxy_observed_z) / 60.0) self.RA_kpc = self.RA_deg * 3600.0 * self.kpc_per_arcsec self.DEC_kpc = self.DEC_deg * 3600.0 * self.kpc_per_arcsec self.observed_RA_kpc = self.RA_deg * 3600.0 * self.observed_kpc_per_arcsec self.observed_DEC_kpc = self.DEC_deg * 3600.0 * self.observed_kpc_per_arcsec self.mstar_msun = subhalos['SubhaloMassInRadType'][self.subhalo_index, 4] * (1.0e10) / ilh self.mgas_msun = subhalos['SubhaloMassInRadType'][ self.subhalo_index, 0] * (1.0e10) / ilh #includes wind mass self.mbh_msun = subhalos['SubhaloMassInRadType'][self.subhalo_index, 5] * (1.0e10) / ilh self.mhalo_msun = subhalos['SubhaloMass'][self.subhalo_index] * ( 1.0e10) / ilh self.baryonmass_msun = self.mstar_msun + self.mgas_msun + self.mbh_msun #within 2x stellar half mass radius... best? self.xpos_ckh = subhalos['SubhaloPos'][self.subhalo_index, 0] #in cKpc/h of max bound part self.ypos_ckh = subhalos['SubhaloPos'][self.subhalo_index, 1] self.zpos_ckh = subhalos['SubhaloPos'][self.subhalo_index, 2] self.xpos_pmpc = (self.xpos_ckh * 1.0 / (1.0 + snapz) / ilh) / 1.0e3 self.ypos_pmpc = (self.ypos_ckh * 1.0 / (1.0 + snapz) / ilh) / 1.0e3 self.zpos_pmpc = (self.zpos_ckh * 1.0 / (1.0 + snapz) / ilh) / 1.0e3 self.xvel_kms = subhalos['SubhaloVel'][self.subhalo_index, 0] self.yvel_kms = subhalos['SubhaloVel'][self.subhalo_index, 1] self.zvel_kms = subhalos['SubhaloVel'][self.subhalo_index, 2] self.sfr = subhalos['SubhaloSFRinRad'][self.subhalo_index] self.bhmdot = subhalos['SubhaloBHMdot'][self.subhalo_index] self.gmag = subhalos['SubhaloStellarPhotometrics'][self.subhalo_index, 4] self.rmag = subhalos['SubhaloStellarPhotometrics'][self.subhalo_index, 5] self.imag = subhalos['SubhaloStellarPhotometrics'][self.subhalo_index, 6] self.zmag = subhalos['SubhaloStellarPhotometrics'][self.subhalo_index, 7] self.gmag_apparent = gmag[ci] #self.total_redshift = return
def Dc2(z1, z2): Dcz1 = (p15.comoving_distance(z1).value * p15.h) Dcz2 = (p15.comoving_distance(z2).value * p15.h) res = Dcz2 - Dcz1 + 1e-8 return res
def Da2(z1, z2): # return the proper distance to redshift z in Mpc/h Dcz1 = (cosmo.comoving_distance(z1).value * cosmo.h) Dcz2 = (cosmo.comoving_distance(z2).value * cosmo.h) res = (Dcz2 - Dcz1 + 1e-8) / (1 + z2) return res
def Da(z): # return the proper distance to redshift z in Mpc/h res = cosmo.comoving_distance(z).value * cosmo.h / (1 + z) return res
def Dc2(z1, z2): # return the comoving distance between redshifts z1 and z2 in Mpc/h Dcz1 = (cosmo.comoving_distance(z1).value * cosmo.h) Dcz2 = (cosmo.comoving_distance(z2).value * cosmo.h) res = (Dcz2 - Dcz1 + 1e-8) return res
def Dc(z): # return the comoving distance to redshift z in Mpc/h res = cosmo.comoving_distance(z).value * cosmo.h return res
def getcoords(a,d,z): comdis = WMAP7.comoving_distance(z) i = (comdis)*(math.cos(math.radians(d)))*(math.cos(math.radians(a))) j = (comdis)*(math.cos(math.radians(d)))*(math.sin(math.radians(a))) k = (comdis)*(math.sin(math.radians(d))) return(i,j,k,z)
def Dc(z): res = p15.comoving_distance(z).value*p15.h return res """Dc(z) returns comoving distance at a particular redshift z""" """Parameters
# Planck13.comoving_distance(ar_z)) # # plt.plot(ar_z, Planck13.comoving_distance(ar_z) / Planck13.comoving_distance(ar_z)) # plt.plot(ar_z, Planck13.comoving_distance(ar_z + ar_delta_z_planck13 - ar_delta_z_wmap7) / # Planck13.comoving_distance(ar_z)) # plt.show() # print(scipy.misc.derivative(func=Planck13.comoving_distance, x0=2, dx=0.1)) # ar_dcmv_dz_planck13 = np.array([scipy.misc.derivative( # func=lambda x: Planck13.comoving_distance(x).value, x0=z, dx=0.01) for z in ar_z]) # ar_dcmv_dz_wmap7 = np.array([scipy.misc.derivative( # func=lambda x: WMAP7.comoving_distance(x).value, x0=z, dx=0.01) for z in ar_z]) # plt.plot(ar_z, -(ar_dcmv_dz_planck13 - ar_dcmv_dz_wmap7) * ar_delta_z_planck13) # plt.show() del scipy.misc ar_base_cmvd_planck13 = Planck13.comoving_distance(ar_z) ar_true_planck13_cmvd = Planck13.comoving_distance(ar_z + ar_delta_z_planck13) ar_base_cmvd_wmap5 = WMAP5.comoving_distance(ar_z) ar_wmap5_apparent_cmvd = WMAP5.comoving_distance(ar_z + ar_delta_z_planck13) ar_base_cmvd_wmap7 = WMAP7.comoving_distance(ar_z) ar_wmap7_apparent_cmvd = WMAP7.comoving_distance(ar_z + ar_delta_z_planck13) ar_base_cmvd_wmap9 = WMAP9.comoving_distance(ar_z) ar_wmap9_apparent_cmvd = WMAP9.comoving_distance(ar_z + ar_delta_z_planck13) plt.plot(ar_z, ar_true_planck13_cmvd - ar_base_cmvd_planck13) plt.plot(ar_z, ar_wmap5_apparent_cmvd - ar_base_cmvd_wmap5) plt.plot(ar_z, ar_wmap7_apparent_cmvd - ar_base_cmvd_wmap7) plt.plot(ar_z, ar_wmap9_apparent_cmvd - ar_base_cmvd_wmap9) # plt.plot(ar_z, ar_wmap7_apparent_cmvd - ar_true_planck13_cmvd) plt.show()