def process_for_redshift(z, mstar_bins, gsmf_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. The given value corresponds to the lower edge of a range in redshift, which has width 0.25 for z < 1.5 and 0.5 for z >= 1.5 mstar_bins: the list of stellar mass bins for which the GSMF is tabulated gsmf_at_z: the slice of the GSMF array at the chosen redshift """ processed = ObservationalData() plot_as = "points" h = cosmology.h M = 10 ** mstar_bins * (h / ORIGINAL_H) ** (-2) * unyt.Solar_Mass Phi = 10 ** gsmf_at_z[:, 0] * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz Phi_err = ( (10 ** gsmf_at_z[:, [0]] * np.log(10) * gsmf_at_z[:, [2, 1]]).T * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) ) processed.associate_x( M, scatter=None, comoving=True, description="Galaxy Stellar Mass" ) processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_redshift(sum(z) * 0.5, *z) processed.associate_plot_as(plot_as) return processed
def process_for_redshift(z, Mstar_bins, gsmf_at_z): """ Output an `ObservationalData` instance containing the GSMF at a given redshift. z: the redshift to produce the GSMF for Mstar_bins: the list of stellar mass bins for which the GSMF is tabulated gsmf_at_z: the values of the GSMF at the chosen redshift """ processed = ObservationalData() plot_as = "line" h = cosmology.h M = Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass M_err = None Phi = gsmf_at_z * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) Phi_err = None processed.associate_x(M, scatter=M_err, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_redshift(z) processed.associate_plot_as(plot_as) return processed
def process_for_redshift(z, gdmf_and_Mstar_at_z): """ Output an HDF5 file containing the GDMF at a given redshift. z: the redshift to produce the GDMF for. The given value corresponds to the lower edge of a range in redshift of width 0.5, except for the first bin 0.2 < z < 0.5, and the last bin 3.0 < z < 4.0 gdmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the chosen redshift """ processed = ObservationalData() comment = ( "Beeston et al. (2018). Obtained using H-ATLAS+GAMA" f"data, h-corrected for SWIFT using Cosmology: {cosmology.name}.") citation = "Beeston et al. (2018)" bibcode = "2018MNRAS.479.1077B" name = "GDMF from H-ATLAS+GAMA" plot_as = "points" redshift = z h = cosmology.h Mstar_bins = gdmf_and_Mstar_at_z[:, 0] M = 10**Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass Phi = 10**gdmf_and_Mstar_at_z[:, 1] * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz M_err = ((10**gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) * gdmf_and_Mstar_at_z[:, [2, 3]]).T * (h / ORIGINAL_H)**3 * unyt.Solar_Mass) Phi_err = ((10**gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) * gdmf_and_Mstar_at_z[:, [4, 5]]).T * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3)) processed.associate_x(M, scatter=M_err, comoving=True, description="Galaxy Dust Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GDMF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. The given value corresponds to the lower edge of a range in redshift of width 0.5, except for the first bin 0.2 < z < 0.5, and the last bin 3.0 < z < 4.0 gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() comment = ( "Assuming Chabrier IMF and Vmax selection, quoted redshift is lower bound of range. " f"h-corrected for SWIFT using Cosmology: {cosmology.name}.") citation = "Ilbert et al. (2013)" bibcode = "2013A&A...556A..55I" name = "GSMF from UltraVISTA" plot_as = "points" redshift = z h = cosmology.h Mstar_bins = gsmf_and_Mstar_at_z[:, 0] M = 10**Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass Phi = 10**gsmf_and_Mstar_at_z[:, 1] * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz Phi_err = ((10**gsmf_and_Mstar_at_z[:, 1][:, None] * np.log(10) * gsmf_and_Mstar_at_z[:, 2:]).T * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3)) processed.associate_x(M, scatter=None, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. The given value corresponds to the lower edge of a range in redshift of width 0.5, except for the first bin 0.2 < z < 0.5, and the last bin 3.0 < z < 4.0 gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() plot_as = "points" h = cosmology.h Mstar_bins = gsmf_and_Mstar_at_z[:, 0] Mstar_Chab = Mstar_bins - np.log10( kroupa_to_chabrier_mass ) # convert from Kroupa IMF M = 10 ** Mstar_Chab * (h / ORIGINAL_H) ** (-2) * unyt.Solar_Mass M_err = ( (10 ** Mstar_Chab * np.log(10) * gsmf_and_Mstar_at_z[:, 1]) * (h / ORIGINAL_H) ** (-2) * unyt.Solar_Mass ) Phi = 10 ** gsmf_and_Mstar_at_z[:, 2] * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz Phi_err = ( ( 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) * gsmf_and_Mstar_at_z[:, [4, 3]] ).T * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) ) processed.associate_x( M, scatter=M_err, comoving=True, description="Galaxy Stellar Mass" ) processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_redshift(sum(z) * 0.5, *z) processed.associate_plot_as(plot_as) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. The given value corresponds to the lower edge of a range in redshift of width 0.5 for z < 3.0, and width 1.0 for z > 3.0 gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() comment = ( "Assuming Chabrier IMF and Vmax selection, quoted redshift is lower bound of range. " f"h-corrected for SWIFT using Cosmology: {cosmology.name}.") citation = "Deshmukh et al. (2018)" bibcode = "2018ApJ...864..166D" name = "GSMF from SMUVS" plot_as = "points" redshift = z h = cosmology.h Mstar_bins = gsmf_and_Mstar_at_z[:, 0] M = 10**Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass # GSMF and errors are stored in datafile with units 10^-4 Mpc^-3 dex^-1 Phi = 1e-4 * gsmf_and_Mstar_at_z[:, 1] * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' Phi_err = (1e-4 * gsmf_and_Mstar_at_z[:, 2:].T * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3)) processed.associate_x(M, scatter=None, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, sfrf_at_z): """ Output an HDF5 file containing the SFRF at a given redshift. z: the redshift to produce the SFRF for. sfrf_at_z: the array containing SFR and Phi_SFR bins at the chosen redshift """ processed = ObservationalData() comment = ( "Assuming Chabrier IMF and Vmax selection. Includes dust corrections as " "described in Katsianis et. al. 2017, section 2. " f"h-corrected for SWIFT using Cosmology: {cosmology.name}.") citation = "van der Burg et. al. (2010)" bibcode = "2010A&A...523A..74V" name = "SFRF from CFHT Legacy Survey" plot_as = "points" redshift = z h = cosmology.h SFR_bins = sfrf_at_z[:, 0] SFR = SFR_bins * unyt.Solar_Mass / unyt.year # SFRF and errors are stored in datafile with units 10^-2 Mpc^-3 dex^-1 Phi = sfrf_at_z[:, 1] * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' Phi_err = sfrf_at_z[:, 2:].T * unyt.Mpc**(-3) processed.associate_x(SFR, scatter=None, comoving=True, description="Star Formation Rate") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (SFRF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. The given value corresponds to the lower edge of a range in redshift of width 0.5 for z < 3.0, and width 1.0 for z > 3.0 gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() plot_as = "points" redshift = z h = cosmology.h Mstar_bins = 10**gsmf_and_Mstar_at_z[:, 0] M = Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass # Mass errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz M_err = (Mstar_bins * np.log(10) * gsmf_and_Mstar_at_z[:, 1] * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass) Phi = gsmf_and_Mstar_at_z[:, 2] * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' Phi_err = gsmf_and_Mstar_at_z[:, 3:].T * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) processed.associate_x(M, scatter=M_err, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, sfrf_at_z): """ Output an HDF5 file containing the SFRF at a given redshift. z: the redshift to produce the SFRF for. sfrf_at_z: the array containing SFR and Phi_SFR bins at the chosen redshift """ processed = ObservationalData() comment = ( "Assuming Chabrier IMF and Vmax selection. Includes dust corrections as " "described in Katsianis et. al. 2017, section 2. " f"h-corrected for SWIFT using Cosmology: {cosmology.name}." ) citation = "Smit et. al. (2012)" bibcode = "2013MNRAS.428.1128S" name = "SFRF from Bouwens+2007;2011" plot_as = "points" redshift = z h = cosmology.h SFR_bins = sfrf_at_z[:, 0] SFR = 10 ** SFR_bins * unyt.Solar_Mass / unyt.year Phi = sfrf_at_z[:, 1] * unyt.Mpc ** (-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' Phi_err = sfrf_at_z[:, 2] * unyt.Mpc ** (-3) processed.associate_x( SFR, scatter=None, comoving=True, description="Star Formation Rate" ) processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (SFRF)") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift to produce the GSMF for. gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() plot_as = "points" h = cosmology.h Mstar_bins = gsmf_and_Mstar_at_z[:, 0] M = 10**Mstar_bins * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass M_err = ((10**Mstar_bins * np.log(10) * gsmf_and_Mstar_at_z[:, 1]) * (h / ORIGINAL_H)**(-2) * unyt.Solar_Mass) Phi = 10**gsmf_and_Mstar_at_z[:, 2] * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz Phi_err = ((10**gsmf_and_Mstar_at_z[:, 2][:, None] * np.abs(gsmf_and_Mstar_at_z[:, [4, 3]]) * np.log(10)).T * (h / ORIGINAL_H)**3 * unyt.Mpc**(-3)) processed.associate_x(M, scatter=M_err, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_redshift(z) processed.associate_plot_as(plot_as) return processed
def process_for_redshift(z, gsmf_and_Mstar_at_z): """ Output an HDF5 file containing the GSMF at a given redshift. z: the redshift range to produce the GSMF for. gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the chosen redshift """ processed = ObservationalData() plot_as = "points" h = cosmology.h Mstar_bins = (gsmf_and_Mstar_at_z[:, 0] * salpeter_to_chabrier_mass ) # convert from Salpeter IMF M = Mstar_bins * h**-2 * unyt.Solar_Mass Phi = 10**gsmf_and_Mstar_at_z[:, 1] * h**3 * unyt.Mpc**(-3) # y_scatter should be a 1xN or 2xN array describing offsets from # the median point 'y' # Errors are log error dz = 1/ln(10) dy/y # We want dy = y ln(10) dz Phi_err = ((10**gsmf_and_Mstar_at_z[:, [1]] * np.log(10) * gsmf_and_Mstar_at_z[:, [3, 2]]).T * h**3 * unyt.Mpc**(-3)) processed.associate_x(M, scatter=None, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Phi, scatter=Phi_err, comoving=True, description="Phi (GSMF)") processed.associate_redshift(sum(z) * 0.5, *z) processed.associate_plot_as(plot_as) return processed
def cosmic_star_formation_history_true(): # Meta-data name = f"Fit to true star formation rate history from Behroozi et al. (2019)" comment = ( "The data is taken from https://www.peterbehroozi.com/data.html. " "The cosmic star formation rate is the true one. This means that no" "observational systematics (e.g., due to dust) are accounted for. " "Uses the Chabrier initial mass function. " "The scatter shows the 16th-84th percentile range from the posterior. " "Cosmology: Omega_m=0.307, Omega_lambda=0.693, h=0.678, sigma_8=0.823, " "n_s=0.96. " "Shows total true cosmic star formation rate (Msun/yr/Mpc^3) for " "the best-fitting model from Behroozi et al. (2019)") citation = "Behroozi et al. (2019) [True]" bibcode = "2019MNRAS.488.3143B" plot_as = "line" output_filename = "Behroozi2019_true.hdf5" output_directory = "../" # Create observational data instance processed = ObservationalData() processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_cosmology(cosmology) if not os.path.exists(output_directory): os.mkdir(output_directory) # Load raw Behroozi2019 data data = np.loadtxt(f"../raw/Behroozi2019_csfrs.dat") # Fetch the fields we need scale_factor = unyt.unyt_array(data[:, 0], units="dimensionless") SFR, SFR_plus, SFR_minus = data[:, 7], data[:, 9], data[:, 8] # Define scatter with respect to the best-fit value (16 and 84 percentiles) SFR_scatter = unyt.unyt_array((SFR_minus, SFR_plus), units="Msun/yr/Mpc**3") redshift, redshift_lower, redshift_upper = 5.0, 0.0, 10.0 processed.associate_x( scale_factor, scatter=None, comoving=False, description="Cosmic scale factor", ) processed.associate_y( SFR * SFR_scatter.units, scatter=SFR_scatter, comoving=False, description="Cosmic average star formation rate density", ) processed.associate_redshift(redshift, redshift_lower, redshift_upper) processed.associate_plot_as(plot_as) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
Z_asm = 6.29 alpha = 0.21 else: Z_asm = 4.84 alpha = 0.35 log10_M_star_min = 9.5 log10_M_star_max = 11.5 M_star = np.arange(log10_M_star_min, log10_M_star_max, 0.2) Z_gas = (Z_asm + alpha * M_star) * unyt.dimensionless # 12 + log(O/H) M_star = 10**M_star * unyt.Solar_Mass processed.associate_x(M_star, scatter=None, comoving=True, description="Galaxy Stellar Mass") processed.associate_y(Z_gas, scatter=None, comoving=True, description="Gas phase metallicity") processed.associate_redshift(z, redshift_lower, redshift_upper) processed.associate_plot_as(plot_as) multi_z.associate_dataset(processed) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) multi_z.write(filename=output_path)
outobj.associate_x( oabundance_med, scatter=x_scatter, comoving=True, description="Gas phase 12 + log10(O/H)", ) outobj.associate_y( logMHIMstar_med, scatter=y_scatter, comoving=True, description="HI mass to stellar mass ratio", ) outobj.associate_citation(citation, bibcode) outobj.associate_name(name) outobj.associate_comment(comment) outobj.associate_redshift(redshift, redshift_lower, redshift_upper) outobj.associate_plot_as(plot_as) outobj.associate_cosmology(cosmology) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) outobj.write(filename=output_path) # Also output median and scatter points for composite sample x_all = np.hstack(x_all) * unyt.dimensionless y_all = np.hstack(y_all) * unyt.dimensionless plussig = lambda a: np.percentile(a, 84)
name = "Stellar mass - H2 Gas to Stellar Mass ratio" plot_as = "points" redshift = 0.0 h = h_sim # Write everything processed = ObservationalData() processed.associate_x(M_star, scatter=None, comoving=True, description="Galaxy Stellar Mass") processed.associate_y( MH2_per_Mstar, scatter=y_scatter, comoving=True, description="Stellar mass - H2 Gas to Stellar Mass ratio", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift, 0, 2) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
smf = unyt.unyt_array(N, units=1 / unyt.Mpc**3) smf_scatter = unyt.unyt_array(sigma, units=1 / unyt.Mpc**3) processed.associate_x( mass, scatter=None, comoving=False, description=f"Galaxy Stellar Mass ({aperture} kpc)", ) processed.associate_y( smf, scatter=smf_scatter, comoving=True, description="Galaxy Stellar Mass Function", ) processed.associate_redshift(redshift, redshift_lower=redshift - 0.25, redshift_upper=redshift + 0.25) processed.associate_plot_as(plot_as) multi_z.associate_dataset(processed) output_path = f"{output_directory}/Schaye2015_{box_size}_{aperture}kpc.hdf5" if os.path.exists(output_path): os.remove(output_path) multi_z.write(filename=output_path)
def cosmic_star_formation_history_novak(): # Meta-data name = f"Star formation rate density from Novak et al. (2017)" comment = ( "based on JVLA COSMOS radio observations at 3 GHz " "cosmology is H0=70, OmegaM=0.3, OmegaL=0.7 " "Uses a Chabrier IMF" ) citation = "Novak et al. (2017)" bibcode = "2017A&A...602A...5N" plot_as = "points" output_filename = "Novak2017.hdf5" output_directory = "../" # Create observational data instance processed = ObservationalData() processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_cosmology(cosmology) if not os.path.exists(output_directory): os.mkdir(output_directory) # Load raw Novak2017 data data = np.loadtxt(f"../raw/sfr_novak2017.dat") # Fetch the fields we need z, delta_z_minus, delta_z_plus = data[:, 0], data[:, 1], data[:, 2] SFR, delta_SFR_minus, delta_SFR_plus = data[:, 3], data[:, 4], data[:, 5] a = 1.0 / (1.0 + z) # division turns large into small, so minus <-> plus a_minus = 1.0 / (1.0 + z + delta_z_plus) a_plus = 1.0 / (1.0 + z + delta_z_minus) delta_a_minus = a - a_minus delta_a_plus = a_plus - a a_bin = unyt.unyt_array(a, units="dimensionless") a_scatter = unyt.unyt_array((delta_a_minus, delta_a_plus), units="dimensionless") # convert from log10(SFRD) to SFRD and carry the uncertainties SFR_minus = 10.0 ** (SFR + delta_SFR_minus) SFR_plus = 10.0 ** (SFR + delta_SFR_plus) SFR = 10.0 ** SFR SFR_scatter = unyt.unyt_array( (SFR - SFR_minus, SFR_plus - SFR), units="Msun/yr/Mpc**3" ) SFR = unyt.unyt_array(SFR, units="Msun/yr/Mpc**3") processed.associate_x( a_bin, scatter=a_scatter, comoving=False, description="Cosmic scale factor" ) processed.associate_y( SFR, scatter=SFR_scatter, comoving=False, description="Cosmic average star formation rate density", ) z_minus = (z + delta_z_minus).min() z_plus = (z + delta_z_plus).max() processed.associate_redshift(0.5 * (z_minus + z_plus), z_minus, z_plus) processed.associate_plot_as(plot_as) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
zhis = np.sort(list(set(z_hi))) for i in range(zs.size): bdx = z_lo == z_lo[i] output_path = f"{output_directory}/{output_filename.format(stringify_z(zs[i]))}" print(output_path) processed.associate_x( oabundance[bdx], scatter=None, comoving=False, description="[O/H]", ) processed.associate_y( d2m[bdx], scatter=None, comoving=False, description="D2M", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(zs[i], zlos[i], zhis[i]) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
smf_scatter = unyt.unyt_array(sigma, units=1 / unyt.Mpc ** 3) processed.associate_x( mass, scatter=None, comoving=False, description=f"Galaxy Stellar Mass ({aperture} kpc)", ) processed.associate_y( smf, scatter=smf_scatter, comoving=True, description="Galaxy Stellar Mass Function", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift( redshift, redshift_lower=redshift, redshift_upper=0.1 ) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"{output_directory}/Schaye2015_{box_size}_{aperture}kpc.hdf5" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
def Phi_passive_galaxies(): # Meta-data name = f"Fit to the quenched galaxy stellar mass function at z=[{redshift_header_info:s}]" comment = ( "The data is taken from https://www.peterbehroozi.com/data.html. " "The stellar mass is the observed stellar mass as defined in Behroozi et al. " "(2019) eq. 25. " "The quenched fractions are defined using the standard criterion where specific" " star formation rate < 1e-11 yr^-1. " "Uses the Chabrier initial mass function. " "GSMF is incomplete below 10**7.0 Msun at z=0 and 10**8.5 Msum at z=8. " "Cosmology: Omega_m=0.307, Omega_lambda=0.693, h=0.678, sigma_8=0.823, " "n_s=0.96. " "Shows the quenched galaxy stellar mass function (number densities in comoving" " Mpc^-3 dex^-1 vs. stellar mass).") # Store metadata at the top level multi_z = MultiRedshiftObservationalData() multi_z.associate_citation(citation, bibcode) multi_z.associate_name(name) multi_z.associate_comment(comment) multi_z.associate_cosmology(cosmology) multi_z.associate_maximum_number_of_returns(1) output_filename = "Behroozi2019_passive.hdf5" output_directory = "../" if not os.path.exists(output_directory): os.mkdir(output_directory) for z, dz_lower, dz_upper, a_str in zip(redshifts, redshifts_lower, redshifts_upper, scale_factors_str): # Create a single observational-data instance at redshift z processed = ObservationalData() # Load raw Behroozi2019 data data = np.loadtxt(f"../raw/Behroozi2019_smf_a{a_str}.dat") # Fetch the fields we need log_M_star, Phi, Phi_plus, Phi_minus = ( data[:, 0], data[:, 7], data[:, 8], data[:, 9], ) # We don't want to plot zeros mask = np.where(Phi > 0.0) # Transform stellar mass M_star = (10.0**log_M_star) * unyt.Solar_Mass # Define scatter with respect to the best-fit value (16 and 84 percentiles) Phi_scatter = unyt.unyt_array((Phi_minus[mask], Phi_plus[mask]), units=unyt.Mpc**(-3)) # Compute \Delta z redshift_lower, redshift_upper = [z - dz_lower, z + dz_upper] processed.associate_x( M_star[mask], scatter=None, comoving=False, description="Galaxy Stellar Mass", ) processed.associate_y( Phi[mask] * (h_sim / ORIGINAL_H)**3 * unyt.Mpc**(-3), scatter=Phi_scatter * (h_sim / ORIGINAL_H)**3, comoving=True, description="Phi (GSMF)", ) processed.associate_redshift(z, redshift_lower, redshift_upper) processed.associate_plot_as(plot_as) multi_z.associate_dataset(processed) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) multi_z.write(filename=output_path)
def cosmic_star_formation_history_enia(): # Meta-data name = f"Star formation rate density from Enia et al. (2022)" comment = ("Uses the Chabrier initial mass function. " "Cosmology: Planck 2016: H0=67.8, OmegaM=0.308.") citation = "Enia et al. (2022)" bibcode = "2022arXiv220200019E" plot_as = "points" output_filename = "Enia2022.hdf5" output_directory = "../" # Create observational data instance processed = ObservationalData() processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_cosmology(cosmology) if not os.path.exists(output_directory): os.mkdir(output_directory) # Load raw Enia2022 data data = np.loadtxt(f"../raw/sfr_enia2022.dat") # Fetch the fields we need z_minus, z_plus = data[:, 0], data[:, 1] SFR, SFR_stderr = data[:, 2], data[:, 3] # Enia (2022) fig. 10 uses specific values for z in each bin, but does not # explicitly list those in their table 4. We simply use the middle of each # bin. z = 0.5 * (z_minus + z_plus) a = 1.0 / (1.0 + z) a_minus = 1.0 / (1.0 + z_plus) a_plus = 1.0 / (1.0 + z_minus) a_bin = unyt.unyt_array(a, units="dimensionless") a_scatter = unyt.unyt_array((a - a_minus, a_plus - a), units="dimensionless") # convert from log10(SFRD) to SFRD and carry the uncertainties SFR_minus = 10.0**(SFR - SFR_stderr) SFR_plus = 10.0**(SFR + SFR_stderr) SFR = 10.0**SFR SFR_scatter = unyt.unyt_array((SFR - SFR_minus, SFR_plus - SFR), units="Msun/yr/Mpc**3") SFR = unyt.unyt_array(SFR, units="Msun/yr/Mpc**3") processed.associate_x(a_bin, scatter=a_scatter, comoving=False, description="Cosmic scale factor") processed.associate_y( SFR, scatter=SFR_scatter, comoving=False, description="Cosmic average star formation rate density", ) z_minus = z_minus.min() z_plus = z_plus.max() processed.associate_redshift(0.5 * (z_minus + z_plus), z_minus, z_plus) processed.associate_plot_as(plot_as) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
a = unyt.unyt_array([a], units=unyt.dimensionless) SNIa_rate = unyt.unyt_array([SNIa_rate], units=1.0 / (unyt.yr * unyt.Mpc**3)) SNIa_scatter = unyt.unyt_array(([SNIa_err_m], [SNIa_err_p]), units=1.0 / (unyt.yr * unyt.Mpc**3)) processed.associate_x(a, scatter=None, comoving=False, description="Cosmic scale factor") processed.associate_y( SNIa_rate, scatter=SNIa_scatter, comoving=False, description="Cosmic SNIa rate", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) zmin = 0.0 zmax = 1000.0 processed.associate_redshift(z, zmin, zmax) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"../Frohmaier2019.hdf5" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
zindex = np.digitize(z, zbins[1:], right=True) for i in range(zcens.size): bdx = zindex == i output_path = f"{output_directory}/{output_filename.format(stringify_z(zcens[i]))}" print(output_path) processed.associate_x( M[bdx], scatter=unyt.unyt_array((M_lo[bdx], M_hi[bdx])), comoving=False, description="Galaxy Stellar Mass", ) processed.associate_y( Mdust[bdx], scatter=unyt.unyt_array((Mdust_lo[bdx], Mdust_hi[bdx])), comoving=False, description="Galaxy Dust Mass", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(zcens[i]) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
def cddf_zwaan(): # Meta-data name = f"CDDF fit from Zwaan et al. (2005)" comment = "" citation = "Zwaan et al. (2005)" bibcode = "2005MNRAS.364.1467Z" plot_as = "line" output_filename = "Zwaan2005.hdf5" output_directory = "../" # Create observational data instance processed = ObservationalData() processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_cosmology(cosmology) if not os.path.exists(output_directory): os.mkdir(output_directory) # Fit parameters (equation 3 in the paper) NHI_star = 10.0**21.2 f_star = 0.0193 beta = 1.24 logNHI = np.linspace(19.8, 22.1, 100) dlogNHI = logNHI[1] - logNHI[0] logNHI_minus = logNHI - 0.5 * dlogNHI logNHI_plus = logNHI + 0.5 * dlogNHI dlogNHI = logNHI_plus - logNHI_minus dNHI = 10.0**logNHI_plus - 10.0**logNHI_minus NHI = 10.0**logNHI f_NHI = (f_star / NHI_star) * (NHI_star / NHI)**beta * np.exp( -NHI / NHI_star) # convert from d/dN to d/dlogN f_NHI *= dNHI / dlogNHI NHI_bin = unyt.unyt_array(NHI, units="cm**(-2)") NHI_scatter = unyt.unyt_array( (NHI - 10.0**logNHI_minus, 10.0**logNHI_plus - NHI), units="cm**(-2)", ) f_NHI_bin = unyt.unyt_array(f_NHI, units="dimensionless") processed.associate_x(NHI_bin, scatter=NHI_scatter, comoving=False, description="Column density") processed.associate_y( f_NHI_bin, scatter=None, comoving=False, description="Column density distribution function", ) z_minus = 0.0 z_plus = 0.0 processed.associate_redshift(0.5 * (z_minus + z_plus), z_minus, z_plus) processed.associate_plot_as(plot_as) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
citation = "Schaye et al. (2015) (EAGLE)" bibcode = "2015MNRAS..446..521S" name = "Gas phase metal mass density obtained from the Ref EAGLE model" redshift = np.mean(z) plot_as = "points" # Write everything processed = ObservationalData() processed.associate_x(a, scatter=None, comoving=True, description="Scale-factor") processed.associate_y(rho_Z_gas, scatter=None, comoving=True, description="Gas Phase Metal Mass Density") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) processed.associate_redshift(redshift, np.min(redshift), np.max(redshift)) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
def cddf_ho(): # Meta-data name = f"CDDF from Ho et al. (2021)" comment = "" citation = "Ho et al. (2021)" bibcode = "2021MNRAS.507..704H" plot_as = "points" output_filename = "Ho2021.hdf5" output_directory = "../" # Create observational data instance processed = ObservationalData() processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_cosmology(cosmology) if not os.path.exists(output_directory): os.mkdir(output_directory) # Load raw data data = np.loadtxt(f"../raw/cddf_Ho2021.dat") # Fetch the fields we need logNHI_minus = data[:, 0] logNHI_plus = data[:, 1] # add pre-factor 10^{-21} f_NHI = data[:, 2] * 1.0e-21 f_NHI_minus = data[:, 3] * 1.0e-21 f_NHI_plus = data[:, 4] * 1.0e-21 logNHI = 0.5 * (logNHI_minus + logNHI_plus) dlogNHI = logNHI_plus - logNHI_minus dNHI = 10.0**logNHI_plus - 10.0**logNHI_minus # convert from d/dN to d/dlogN f_NHI *= dNHI / dlogNHI f_NHI_minus *= dNHI / dlogNHI f_NHI_plus *= dNHI / dlogNHI NHI_bin = unyt.unyt_array(10.0**logNHI, units="cm**(-2)") NHI_scatter = unyt.unyt_array( (10.0**logNHI - 10.0**logNHI_minus, 10.0**logNHI_plus - 10.0**logNHI), units="cm**(-2)", ) f_NHI_bin = unyt.unyt_array(f_NHI, units="dimensionless") f_NHI_scatter = unyt.unyt_array((f_NHI - f_NHI_minus, f_NHI_plus - f_NHI), units="dimensionless") processed.associate_x(NHI_bin, scatter=NHI_scatter, comoving=False, description="Column density") processed.associate_y( f_NHI_bin, scatter=f_NHI_scatter, comoving=False, description="Column density distribution function", ) z_minus = 2.0 z_plus = 5.0 processed.associate_redshift(0.5 * (z_minus + z_plus), z_minus, z_plus) processed.associate_plot_as(plot_as) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
[ 10**(binned_data[0]) - 10**(binned_data[0] - array_x_bin_std_down), 10**(binned_data[0] + array_x_bin_std_up) - 10**(binned_data[0]), ], units="Msun/kpc**2", ) processed.associate_x(SigmaH2, scatter=SigmaH2_err, comoving=False, description="$\\Sigma_{\\rm H_2}$") processed.associate_y(SigmaSFR, scatter=SigmaSFR_err, comoving=False, description="$\\Sigma_{\\rm SFR}$") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(0.0, 0.0, 0.0) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"../Abdurrouf2022.hdf5" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
def passive_fractions_centrals(): # Meta-data name = ("Fit to the passive fraction - stellar mass (centrals) " f"at z=[{redshift_header_info:s}]") comment = ( "The data is taken from https://www.peterbehroozi.com/data.html. " "The quenched fractions are defined using the standard criterion where " "specific star formation rate < 1e-11 yr^-1. " "The stellar mass is the observed stellar mass as defined in Behroozi et al. " "(2019) eq. 25. " "Uses the Chabrier initial mass function. " "The passive fractions are given by the 50th percentile of the posterior " "distribution of the fitting model. " "Cosmology: Omega_m=0.307, Omega_lambda=0.693, h=0.678, sigma_8=0.823, " "n_s=0.96. " "Shows the passive fraction of centrals versus galaxy stellar mass.") # Store metadata at the top level multi_z = MultiRedshiftObservationalData() multi_z.associate_citation(citation, bibcode) multi_z.associate_name(name) multi_z.associate_comment(comment) multi_z.associate_cosmology(cosmology) multi_z.associate_maximum_number_of_returns(1) output_filename = "Behroozi2019_centrals.hdf5" output_directory = "../" if not os.path.exists(output_directory): os.mkdir(output_directory) for z, dz_lower, dz_upper, a_str in zip(redshifts, redshifts_lower, redshifts_upper, scale_factors_str): # Create a single observational-data instance at redshift z processed = ObservationalData() # Load raw Behroozi2019 data data = np.loadtxt(f"../raw/Behroozi2019_qf_groupstats_a{a_str}.dat") # Fetch the fields we need log_M_star, QF, QF_plus, QF_minus = ( data[:, 0], data[:, 1], data[:, 2], data[:, 3], ) # We don't want to plot zeros mask = np.where(QF > 0.0) # Transform stellar mass M_star = (10.0**log_M_star) * unyt.Solar_Mass # Define scatter with respect to the best-fit value (16 and 84 percentiles) QF_scatter = unyt.unyt_array((QF_minus[mask], QF_plus[mask]), units="dimensionless") # Compute \Delta z redshift_lower, redshift_upper = [z - dz_lower, z + dz_upper] processed.associate_x( M_star[mask], scatter=None, comoving=False, description="Galaxy Stellar Mass", ) processed.associate_y( QF[mask] * unyt.dimensionless, scatter=QF_scatter, comoving=False, description="Passive Fraction (centrals)", ) processed.associate_redshift(z, redshift_lower, redshift_upper) processed.associate_plot_as(plot_as) multi_z.associate_dataset(processed) output_path = f"{output_directory}/{output_filename}" if os.path.exists(output_path): os.remove(output_path) multi_z.write(filename=output_path)
else: x_vals = tables[i][:, 4] * units[i] fh2 = 10**tables[i][:, 6] * unitless fh2_plus_err = (10**(tables[i][:, 6] + tables[i][:, 7]) * unitless) - fh2 fh2_minus_err = fh2 - (10**(tables[i][:, 6] - tables[i][:, 7]) * unitless) fh2_err = np.row_stack([fh2_minus_err, fh2_plus_err]) processed.associate_x(x_vals, scatter=None, comoving=False, description=labels[i]) processed.associate_y(fh2, scatter=fh2_err, comoving=False, description="Average Galaxy H2 fraction") processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) processed.associate_redshift(redshift) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"{output_directory}/{output_filename.format(filetag[i])}" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)
a = unyt.unyt_array(a, units=unyt.dimensionless) SNIa_rate = unyt.unyt_array(SNIa_rate, units=1.0 / (unyt.yr * unyt.Mpc**3)) SNIa_scatter = unyt.unyt_array((SNIa_err_m, SNIa_err_p), units=1.0 / (unyt.yr * unyt.Mpc**3)) processed.associate_x(a, scatter=None, comoving=False, description="Cosmic scale factor") processed.associate_y( SNIa_rate, scatter=SNIa_scatter, comoving=False, description="Cosmic SNIa rate", ) processed.associate_citation(citation, bibcode) processed.associate_name(name) processed.associate_comment(comment) zmin = z.min() zmax = z.max() processed.associate_redshift(0.5 * (zmin + zmax), zmin, zmax) processed.associate_plot_as(plot_as) processed.associate_cosmology(cosmology) output_path = f"../Dilday2010.hdf5" if os.path.exists(output_path): os.remove(output_path) processed.write(filename=output_path)