def cosmoComVol(redshift, WMAP9=False, H0=70.0, Om0=0.30, Planck15=False, Gpc=False): """ Get the Comoving Volume at redshift=z. This is simply a wrapper of astropy.cosmology The input redsfhit can be an array """ if WMAP9: from astropy.cosmology import WMAP9 as cosmo elif Planck15: from astropy.cosmology import Planck15 as cosmo else: from astropy.cosmology import FlatLambdaCDM cosmo = FlatLambdaCDM(H0=H0, Om0=Om0) v = cosmo.comoving_volume(redshift) if not Gpc: return v.value else: return v.to(u.Gpc).value
def calc_num_of_galaxies(M_min=-24, M_max=None, save=False): """ :param M_min: Minimum absolute magnitude :param M_max: Maximum absolute magnitude :param save: To save the galaxy numbers to a file :return: redshift bin edges and number of galaxies in that redshift bin """ alphas = [-1.05, -1.175, -1.3, -1.3, -1.3, -1.3, -1.3] phi_stars = [14.9 * 0.7**3, 4.32, 3.53, 3.23, 3.46, 3.78, 2.5] # 10^-3 h^3 Mpc^-3 mag^-1 (h = 1) Mb_stars = [ -20.44 + 5 * np.log10(0.7), -20.93, -20.64, -20.97, -21.08, -21.22, -21.39 ] # + 5 logh70 z_mins = np.array([0, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0]) z_maxs = np.array([0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2]) num_total = [] for idx, (z_min, z_max) in enumerate(zip(z_mins, z_maxs)): phi_star = phi_stars[idx] Mb_star = Mb_stars[idx] if not M_max: M_max = Mb_star + 5 alpha = alphas[idx] V_c_max = cosmo.comoving_volume(z_max).value # Mpc^3 V_c_min = cosmo.comoving_volume(z_min).value # Mpc^3 num_dens_gal = quad( schechter_fn, M_min, M_max, args=(phi_star, Mb_star, alpha))[0] * 10**(-3) # Mpc^-3 num_total.append(num_dens_gal * (V_c_max - V_c_min)) if save: data_path = os.path.split(__file__)[0] + '/data' with open(f"{data_path}/num_galaxies.txt", "w") as f: for (z_min, z_max, num_gal) in zip(z_mins, z_maxs, num_total): f.write("{0},{1},{2}\n".format(z_min, z_max, num_gal)) return z_mins, z_maxs, num_total
def __init__(self): self.Lsun = 3.838E+33 self.fluxlim_Jy_des = 1E-7 self.des_filters = { 'g': [3920, 4775.0, 5630], 'r': [5330, 6215.0, 7100], 'i': [6710, 7540.0, 8370], 'z': [7930, 8690.0, 9450] } self.fluxlim_ergcms_des = (self.des_filters['i'][2]-self.des_filters['i'][0])*2.99792458E-05*self.fluxlim_Jy_des/(self.des_filters['i'][1]**2) self.des_area_frac = 27/41252.96125 self.V_co_1 = cosmo.comoving_volume(1) self.D08_Mpc = lam = (2.6 * 1E-5)/(u.Mpc**3) self.D08_z = lam*self.V_co_1
def ChooseTABLE_z_V(MODnamef): OmegaMf = 0.3 # Omega M OmegaLf = 0.7 # Omega vac OmegaKf = 1. - OmegaMf - OmegaLf Hcf = 70.0 ######### TABLE V - Z ########### print " # DEFAULT COSMOLOGY: OmegaM = 0.3, OmegaL = 0.7, Hubble constant = 70 (km/s)/Mpc" print " # CHOSEN TABLE redshift(z) - Comoving Volume (CV): VOLUME_table_0p004_Om03_H70.txt #" print " # > step in z is: dz = step in z from the RATE #" print " # Enter 0 if that is ok #" print " # Enter 1 if you want the more refined table VOLUME_table_em6_Om03_H70.txt #" print " # Enter 2 if you want a more refined table to be built #" print " # Enter 3 if you want to change cosmology and redefined the table #" print " # NB: OPTION 3 AVAILABLE ONLY FOR User and Mandel rate models for concistency #" invalid_option = True NameFILE_TABf = "" while invalid_option: OPT = input(" # Enter the number: ") if (OPT == 0): invalid_option = False NameFILE_TABf = "VOLUME_table_0p004_Om03_H70.txt" TABzVCf = prefix + "z_CV_TABLES/" + NameFILE_TABf #sh.cp(TABzVC,"TEMP/.") elif (OPT == 1): invalid_option = False NameFILE_TABf = "VOLUME_table_em6_Om03_H70.txt" TABzVCf = prefix + "z_CV_TABLES/" + NameFILE_TABf elif (OPT == 2): invalid_option = False dz = input("Enter desired resolution in redshift dz: ") from astropy.cosmology import FlatLambdaCDM Vp = cosmo.comoving_volume(1) cosmo_FL = FlatLambdaCDM(H0=70, Om0=0.3) MINz = 0.0 MAXz = np.max(zR) ROUGH_dV_Om03_H70 = [] ROUGH_Vcum_Om03_H70 = [] Z_Vec = [] zi = MINz V_old = cosmo_FL.comoving_volume(zi) if (zi > 0.0000): Z_Vec.append(zi) ROUGH_dV_Om03_H70.append(V_old.value * Mpc**3) ROUGH_Vcum_Om03_H70.append(V_old.value * Mpc**3) while zi < MAXz: zi = zi + dz Z_Vec.append(zi) Vi = cosmo_FL.comoving_volume(zi) DV_i = Vi.value - V_old.value ROUGH_dV_Om03_H70.append(DV_i * Mpc**3) ROUGH_Vcum_Om03_H70.append(Vi.value * Mpc**3) V_old = Vi print len(ROUGH_dV_Om03_H70) print len(ROUGH_Vcum_Om03_H70) print len(Z_Vec) NameFILE_TABf = "VOLUME_table_%.2E_Om03_H70.txt" % dz TABzVCf = prefix + "z_CV_TABLES/" + NameFILE_TABf print TABzVCf with open(TABzVCf, 'w') as f: writer = csv.writer(f, delimiter='\t') writer.writerows( zip(Z_Vec, ROUGH_dV_Om03_H70, ROUGH_Vcum_Om03_H70)) elif (OPT == 3): if (MODnamef != "User" and MODnamef != "Mandel2017"): print " # Invalid option for rate ", MODnamef continue invalid_option = False invalidCOSM = True while invalidCOSM: Ode0 = input('# Cosmological constant: ') Om0 = input('# Matter constant: ') OmegaKf = input('# Curvature : ') H0 = input('# Hubble constant [km/s/Mpc]: ') if (np.abs(Ode0 + Om0 + OmegaKf - 1.) < 0.000001): invalidCOSM = False else: print " # INVALID COSMSOLOGY, constants not sum to 1" if OmegaKf == 0: from astropy.cosmology import FlatLambdaCDM Vp = cosmo.comoving_volume(1) cosmo_FL = FlatLambdaCDM(H0, Om0) dz = input('# Enter desired resolution in redshift dz: ') MINz = 0.0 MAXz = input( '# Enter maximum redshift for table building (please consider the redshifts required by the rate model): ' ) MAXz = MAXz + dz ROUGH_dV = [] ROUGH_Vcum = [] Z_Vec = [] zi = MINz V_old = cosmo_FL.comoving_volume(zi) if (zi > 0.0000): Z_Vec.append(zi) ROUGH_dV.append(V_old.value * Mpc**3) ROUGH_Vcum.append(V_old.value * Mpc**3) while zi < MAXz: zi = zi + dz Z_Vec.append(zi) Vi = cosmo_FL.comoving_volume(zi) DV_i = Vi.value - V_old.value ROUGH_dV.append(DV_i * Mpc**3) ROUGH_Vcum.append(Vi.value * Mpc**3) V_old = Vi print len(ROUGH_dV) print len(ROUGH_Vcum) print len(Z_Vec) NameFILE_TABf = "VOLUME_table_%.2E_Ode%.2f_Om%.2f_H%2.1f.txt" % ( dz, Ode0, Om0, H0) TABzVCf = prefix + "z_CV_TABLES/" + NameFILE_TABf print TABzVCf with open(TABzVCf, 'w') as f: writer = csv.writer(f, delimiter='\t') writer.writerows(zip(Z_Vec, ROUGH_dV, ROUGH_Vcum)) else: from astropy.cosmology import LambdaCDM Vp = cosmo.comoving_volume(1) cosmo_LCDM = LambdaCDM(H0, Om0, Ode0) dz = input('# Enter desired resolution in redshift dz: ') MINz = 0.0 MAXz = input( '# Enter maximum redshift for table building (please consider the redshifts required by the rate model): ' ) ROUGH_dV = [] ROUGH_Vcum = [] Z_Vec = [] zi = MINz V_old = cosmo_LCDM.comoving_volume(zi) if (zi > 0.0000): Z_Vec.append(zi) ROUGH_dV.append(V_old.value * Mpc**3) ROUGH_Vcum.append(V_old.value * Mpc**3) while zi < MAXz: zi = zi + dz Z_Vec.append(np.round(zi, 2)) Vi = cosmo_LCDM.comoving_volume(zi) DV_i = Vi.value - V_old.value ROUGH_dV.append(DV_i * Mpc**3) ROUGH_Vcum.append(Vi.value * Mpc**3) V_old = Vi print len(ROUGH_dV) print len(ROUGH_Vcum) print len(Z_Vec) NameFILE_TABf = "VOLUME_table_%.2E_Om%.2f_H%2.1f.txt" % ( dz, Om0, H0) TABzVCf = prefix + "z_CV_TABLES/" + NameFILE_TABf print TABzVCf with open(TABzVCf, 'w') as f: writer = csv.writer(f, delimiter='\t') writer.writerows(zip(Z_Vec, ROUGH_dV, ROUGH_Vcum)) Hcf = H0 OmegaLf = Ode0 OmegaMf = Om0 else: print "Invalid OPTION" print " ############################################################################################################" outTAB_Qf = [NameFILE_TABf, TABzVCf, Hcf, OmegaMf, OmegaLf, OmegaKf] return outTAB_Qf