From 8ee0b1cc4c057c783fedfd475845fa69b2e64fd1 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 30 Mar 2020 15:59:38 +0100 Subject: [PATCH 1/7] added new dust data --- .../convert/convertBeeston2018.py | 165 +++++++++++++++++ .../convert/convertPozzi2020.py | 166 ++++++++++++++++++ .../raw/Beeston2018.txt | 22 +++ data/GalaxyDustMassFunction/raw/Pozzi2020.txt | 19 ++ 4 files changed, 372 insertions(+) create mode 100644 data/GalaxyDustMassFunction/convert/convertBeeston2018.py create mode 100644 data/GalaxyDustMassFunction/convert/convertPozzi2020.py create mode 100644 data/GalaxyDustMassFunction/raw/Beeston2018.txt create mode 100644 data/GalaxyDustMassFunction/raw/Pozzi2020.txt diff --git a/data/GalaxyDustMassFunction/convert/convertBeeston2018.py b/data/GalaxyDustMassFunction/convert/convertBeeston2018.py new file mode 100644 index 00000000..d74852ce --- /dev/null +++ b/data/GalaxyDustMassFunction/convert/convertBeeston2018.py @@ -0,0 +1,165 @@ +from velociraptor.observations.objects import ObservationalData + +import unyt +import numpy as np +import os +import re +import sys +import itertools as it + +ORIGINAL_H = 0.7 + +def load_file_and_split_by_z(raw_file_name): + """ + Read the data file and do all the mucking around needed to extract a list of the + redshift bins for which the GSMF is tabulated, along with the corresponding GSMF + values and their errors. + The number and spacing of the stellar mass bins vary with z; they are given in the + first column of the returned array. + + raw_file_name: the file name of the raw data file to extract the GSMF from + """ + + data = np.genfromtxt(raw_file_name, comments='#') + + # array of the lower redshift bin edges for each GDMF + z_bins_arr = np.unique(data[:,-2]) + + gsmf_arr = [] + for zlow in z_bins_arr: + bdx = data[:,-2] == zlow + gsmf_arr.append(data[bdx,:-2]) + + + # # find header lines indicating the start of each block of data + # header_line_nos = [i for i, line in enumerate(lines) if "1/Vmax" in line] + # header_line_nos.append(len(lines)) + + # # split the full loist of lines into one block of lines per redshift bin + # split_lines = [] + # for l1, l2 in pairwise(header_line_nos): + # split_lines.append(lines[l1:l2]) + + # # The datafile uses '-99' to indicate missing data; we convert these to NaNs + # handle_bad_value_converter = ( + # lambda s: float(s.strip()) if b"-99" not in s else np.nan + # ) + # converter_dict = dict(zip(range(2, 5), it.repeat(handle_bad_value_converter))) + + # # figure out the redshift bins + # z_bins_arr = np.zeros_like(split_lines) + # gsmf_arr = [] + # for isl, lines in enumerate(split_lines): + # z_bins_arr[isl] = float(re.search("z=\[(\d.\d)", lines[0]).group(1)) + # gsmf_arr.append(np.loadtxt(lines, converters=converter_dict, usecols=range(5))) + + return z_bins_arr, gsmf_arr + + +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 = ( + "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 = 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 + M_err = ( + ( + 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + * np.log(10) + * gsmf_and_Mstar_at_z[:, [2, 3]] + ).T + * (h / ORIGINAL_H) ** 3 + * unyt.Solar_Mass + ) + + Phi_err = ( + ( + 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + * np.log(10) + * gsmf_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 stringify_z(z): + """ + Eagle-style text formatting of redshift label. + Example: z=1.5 will be printed as z001p500. + + z: The redshift to produce a label for + """ + whole = int(z) + frac = int(1000 * (z - whole)) + return f"z{whole:03d}p{frac:03d}" + + +# Exec the master cosmology file passed as first argument +# These lines are _required_ and you are required to use +# the cosmology specified (this is an astropy.cosmology +# instance) +with open(sys.argv[1], "r") as handle: + exec(handle.read()) + +input_filename = "../raw/Beeston2018.txt" + +output_filename = "Beeston2018_{}.hdf5" +output_directory = "../" + +if not os.path.exists(output_directory): + os.mkdir(output_directory) + +# z_bins is a 1-D ndarray containing the lower edges of the redshift bins +# gsmf_and_Mstar is a list of 2D ndarrays, one per redshift +# Each contains five columns as follows: +# log(Mstar) bins, Mstar errors, log(GSMF), GSMF +- errors +z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) + +for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): + processed = process_for_redshift(z, gsmf_and_Mstar_at_z) + + output_path = f"{output_directory}/{output_filename.format(stringify_z(z))}" + + if os.path.exists(output_path): + os.remove(output_path) + + processed.write(filename=output_path) diff --git a/data/GalaxyDustMassFunction/convert/convertPozzi2020.py b/data/GalaxyDustMassFunction/convert/convertPozzi2020.py new file mode 100644 index 00000000..6174e796 --- /dev/null +++ b/data/GalaxyDustMassFunction/convert/convertPozzi2020.py @@ -0,0 +1,166 @@ +from velociraptor.observations.objects import ObservationalData + +import unyt +import numpy as np +import os +import re +import sys +import itertools as it + +ORIGINAL_H = 0.7 + +def load_file_and_split_by_z(raw_file_name): + """ + Read the data file and do all the mucking around needed to extract a list of the + redshift bins for which the GSMF is tabulated, along with the corresponding GSMF + values and their errors. + The number and spacing of the stellar mass bins vary with z; they are given in the + first column of the returned array. + + raw_file_name: the file name of the raw data file to extract the GSMF from + """ + + data = np.genfromtxt(raw_file_name, comments='#') + + # array of the lower redshift bin edges for each GDMF + z_bins_arr = np.unique(data[:,-2]) + + gsmf_arr = [] + for zlow in z_bins_arr: + bdx = data[:,-2] == zlow + gsmf_arr.append(data[bdx,:-2]) + + + # # find header lines indicating the start of each block of data + # header_line_nos = [i for i, line in enumerate(lines) if "1/Vmax" in line] + # header_line_nos.append(len(lines)) + + # # split the full loist of lines into one block of lines per redshift bin + # split_lines = [] + # for l1, l2 in pairwise(header_line_nos): + # split_lines.append(lines[l1:l2]) + + # # The datafile uses '-99' to indicate missing data; we convert these to NaNs + # handle_bad_value_converter = ( + # lambda s: float(s.strip()) if b"-99" not in s else np.nan + # ) + # converter_dict = dict(zip(range(2, 5), it.repeat(handle_bad_value_converter))) + + # # figure out the redshift bins + # z_bins_arr = np.zeros_like(split_lines) + # gsmf_arr = [] + # for isl, lines in enumerate(split_lines): + # z_bins_arr[isl] = float(re.search("z=\[(\d.\d)", lines[0]).group(1)) + # gsmf_arr.append(np.loadtxt(lines, converters=converter_dict, usecols=range(5))) + + return z_bins_arr, gsmf_arr + + +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 = ( + "Pozzi et al. (2020), Figure 5. Obtained using Herschel+GAMA" + "data, and derived using the MAGPHYS SED fitting package." + f"h-corrected for SWIFT using Cosmology: {cosmology.name}." + ) + citation = "Pozzi et al. (2020)" + bibcode = "2020MNRAS.491.5073P" + name = "GDMF from Herschel+GAMA" + 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 + M_err = ( + ( + 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + * np.log(10) + * gsmf_and_Mstar_at_z[:, [2, 3]] + ).T + * (h / ORIGINAL_H) ** 3 + * unyt.Solar_Mass + ) + + Phi_err = ( + ( + 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + * np.log(10) + * gsmf_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 stringify_z(z): + """ + Eagle-style text formatting of redshift label. + Example: z=1.5 will be printed as z001p500. + + z: The redshift to produce a label for + """ + whole = int(z) + frac = int(1000 * (z - whole)) + return f"z{whole:03d}p{frac:03d}" + + +# Exec the master cosmology file passed as first argument +# These lines are _required_ and you are required to use +# the cosmology specified (this is an astropy.cosmology +# instance) +with open(sys.argv[1], "r") as handle: + exec(handle.read()) + +input_filename = "../raw/Pozzi2020.txt" + +output_filename = "Pozzi2020_{}.hdf5" +output_directory = "../" + +if not os.path.exists(output_directory): + os.mkdir(output_directory) + +# z_bins is a 1-D ndarray containing the lower edges of the redshift bins +# gsmf_and_Mstar is a list of 2D ndarrays, one per redshift +# Each contains five columns as follows: +# log(Mstar) bins, Mstar errors, log(GSMF), GSMF +- errors +z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) + +for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): + processed = process_for_redshift(z, gsmf_and_Mstar_at_z) + + output_path = f"{output_directory}/{output_filename.format(stringify_z(z))}" + + if os.path.exists(output_path): + os.remove(output_path) + + processed.write(filename=output_path) diff --git a/data/GalaxyDustMassFunction/raw/Beeston2018.txt b/data/GalaxyDustMassFunction/raw/Beeston2018.txt new file mode 100644 index 00000000..82f7fb0f --- /dev/null +++ b/data/GalaxyDustMassFunction/raw/Beeston2018.txt @@ -0,0 +1,22 @@ +# +# Galaxy Dust Mass Function from Beeston+18, columns: +# | log10 (Mdust/Msun) | phi [cMpc^-3] | Mdust err + | Mdust err - | phi err + | phi err - | redshift edge lower | redshift edge upper | +# +4.12808 -1.30441 0 0 0 0 0. 0.06 +4.37931 -1.30441 0 0 0 0 0. 0.06 +4.63054 -1.59813 0 0 0 0 0. 0.06 +4.88177 -1.48598 0 0 0 0 0. 0.06 +5.12808 -1.45394 0 0 0 0 0. 0.06 +5.37931 -1.71562 0 0 0 0 0. 0.06 +5.63054 -1.70494 0 0 0 0 0. 0.06 +5.87685 -1.73698 0 0 0 0 0. 0.06 +6.12808 -1.80641 0 0 0 0 0. 0.06 +6.37931 -1.95594 0 0 0 0 0. 0.06 +6.62562 -2.04139 0 0 0 0 0. 0.06 +6.88177 -2.13218 0 0 0 0 0. 0.06 +7.12808 -2.22296 0 0 0 0 0. 0.06 +7.37931 -2.29773 0 0 0 0 0. 0.06 +7.63054 -2.54339 0 0 0 0 0. 0.06 +7.88177 -2.97063 0 0 0 0 0. 0.06 +8.12808 -3.73965 0 0 0 0 0. 0.06 +8.37931 -4.60481 0 0 0 0 0. 0.06 diff --git a/data/GalaxyDustMassFunction/raw/Pozzi2020.txt b/data/GalaxyDustMassFunction/raw/Pozzi2020.txt new file mode 100644 index 00000000..a0562e92 --- /dev/null +++ b/data/GalaxyDustMassFunction/raw/Pozzi2020.txt @@ -0,0 +1,19 @@ +# +# Galaxy Dust Mass Function from Pozzi+2020, columns: +# | log10 (Mdust/Msun) | phi [cMpc^-3] | Mdust err + | Mdust err - | phi err + | phi err - | redshift edge lower | redshift edge upper | +# +6.69767 -1.75705 0 0 0 0 0.1 0.25 +6.90439 -2.07041 0 0 0 0 0.1 0.25 +7.09819 -2.21705 0 0 0 0 0.1 0.25 +7.29199 -2.46786 0 0 0 0 0.1 0.25 +7.49871 -2.61456 0 0 0 0 0.1 0.25 +7.70543 -2.90708 0 0 0 0 0.1 0.25 +7.89922 -3.32456 0 0 0 0 0.1 0.25 +8.09302 -4.24203 0 0 0 0 0.1 0.25 +8.70026 -4.41123 0 0 0 0 0.1 0.25 +8.70898 -3.71850 0 0 0 0 1.8 2.5 +8.89474 -4.16943 0 0 0 0 1.8 2.5 +9.09598 -4.57043 0 0 0 0 1.8 2.5 +9.29721 -4.94644 0 0 0 0 1.8 2.5 +9.49845 -5.82245 0 0 0 0 1.8 2.5 +10.10217 -6.45046 0 0 0 0 1.8 2.5 From 14ebbf7bcbd5e4f39c717672053cb75d4ab811eb Mon Sep 17 00:00:00 2001 From: James Date: Mon, 30 Mar 2020 22:12:19 +0100 Subject: [PATCH 2/7] add dust mass functions --- convert.sh | 1 + requirements.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/convert.sh b/convert.sh index 86f6e9eb..cd9ff194 100644 --- a/convert.sh +++ b/convert.sh @@ -8,6 +8,7 @@ do for convert in ./*.py; do + echo $convert python3 $convert ../../../cosmology.py; this_return_code=$? return_code=$(( $return_code > $this_return_code ? $return_code : $this_return_code )) diff --git a/requirements.txt b/requirements.txt index 2e86fcae..4076ee5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ velociraptor numpy>1.16.0 astropy matplotlib +mpi4py From 52dcc96d22c9bb33721900c68bc7b00e295eed81 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 10:16:24 +0100 Subject: [PATCH 3/7] removed commented code, correctly named conversion directory and formatted --- .../{convert => conversion}/convertBeeston2018.py | 0 .../{convert => conversion}/convertPozzi2020.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename data/GalaxyDustMassFunction/{convert => conversion}/convertBeeston2018.py (100%) rename data/GalaxyDustMassFunction/{convert => conversion}/convertPozzi2020.py (100%) diff --git a/data/GalaxyDustMassFunction/convert/convertBeeston2018.py b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py similarity index 100% rename from data/GalaxyDustMassFunction/convert/convertBeeston2018.py rename to data/GalaxyDustMassFunction/conversion/convertBeeston2018.py diff --git a/data/GalaxyDustMassFunction/convert/convertPozzi2020.py b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py similarity index 100% rename from data/GalaxyDustMassFunction/convert/convertPozzi2020.py rename to data/GalaxyDustMassFunction/conversion/convertPozzi2020.py From 8580471aff6a67cfc515e96918761e9aeb2175e2 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 10:22:27 +0100 Subject: [PATCH 4/7] cleaned conversion script --- .../conversion/convertBeeston2018.py | 34 ++++-------------- .../conversion/convertPozzi2020.py | 35 ++++--------------- 2 files changed, 12 insertions(+), 57 deletions(-) diff --git a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py index d74852ce..ac07a58a 100644 --- a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py +++ b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py @@ -9,6 +9,7 @@ ORIGINAL_H = 0.7 + def load_file_and_split_by_z(raw_file_name): """ Read the data file and do all the mucking around needed to extract a list of the @@ -20,38 +21,15 @@ def load_file_and_split_by_z(raw_file_name): raw_file_name: the file name of the raw data file to extract the GSMF from """ - data = np.genfromtxt(raw_file_name, comments='#') + data = np.genfromtxt(raw_file_name, comments="#") # array of the lower redshift bin edges for each GDMF - z_bins_arr = np.unique(data[:,-2]) - + z_bins_arr = np.unique(data[:, -2]) + gsmf_arr = [] for zlow in z_bins_arr: - bdx = data[:,-2] == zlow - gsmf_arr.append(data[bdx,:-2]) - - - # # find header lines indicating the start of each block of data - # header_line_nos = [i for i, line in enumerate(lines) if "1/Vmax" in line] - # header_line_nos.append(len(lines)) - - # # split the full loist of lines into one block of lines per redshift bin - # split_lines = [] - # for l1, l2 in pairwise(header_line_nos): - # split_lines.append(lines[l1:l2]) - - # # The datafile uses '-99' to indicate missing data; we convert these to NaNs - # handle_bad_value_converter = ( - # lambda s: float(s.strip()) if b"-99" not in s else np.nan - # ) - # converter_dict = dict(zip(range(2, 5), it.repeat(handle_bad_value_converter))) - - # # figure out the redshift bins - # z_bins_arr = np.zeros_like(split_lines) - # gsmf_arr = [] - # for isl, lines in enumerate(split_lines): - # z_bins_arr[isl] = float(re.search("z=\[(\d.\d)", lines[0]).group(1)) - # gsmf_arr.append(np.loadtxt(lines, converters=converter_dict, usecols=range(5))) + bdx = data[:, -2] == zlow + gsmf_arr.append(data[bdx, :-2]) return z_bins_arr, gsmf_arr diff --git a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py index 6174e796..cc88515b 100644 --- a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py +++ b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py @@ -9,6 +9,7 @@ ORIGINAL_H = 0.7 + def load_file_and_split_by_z(raw_file_name): """ Read the data file and do all the mucking around needed to extract a list of the @@ -20,39 +21,15 @@ def load_file_and_split_by_z(raw_file_name): raw_file_name: the file name of the raw data file to extract the GSMF from """ - data = np.genfromtxt(raw_file_name, comments='#') + data = np.genfromtxt(raw_file_name, comments="#") # array of the lower redshift bin edges for each GDMF - z_bins_arr = np.unique(data[:,-2]) - + z_bins_arr = np.unique(data[:, -2]) + gsmf_arr = [] for zlow in z_bins_arr: - bdx = data[:,-2] == zlow - gsmf_arr.append(data[bdx,:-2]) - - - # # find header lines indicating the start of each block of data - # header_line_nos = [i for i, line in enumerate(lines) if "1/Vmax" in line] - # header_line_nos.append(len(lines)) - - # # split the full loist of lines into one block of lines per redshift bin - # split_lines = [] - # for l1, l2 in pairwise(header_line_nos): - # split_lines.append(lines[l1:l2]) - - # # The datafile uses '-99' to indicate missing data; we convert these to NaNs - # handle_bad_value_converter = ( - # lambda s: float(s.strip()) if b"-99" not in s else np.nan - # ) - # converter_dict = dict(zip(range(2, 5), it.repeat(handle_bad_value_converter))) - - # # figure out the redshift bins - # z_bins_arr = np.zeros_like(split_lines) - # gsmf_arr = [] - # for isl, lines in enumerate(split_lines): - # z_bins_arr[isl] = float(re.search("z=\[(\d.\d)", lines[0]).group(1)) - # gsmf_arr.append(np.loadtxt(lines, converters=converter_dict, usecols=range(5))) - + bdx = data[:, -2] == zlow + gsmf_arr.append(data[bdx, :-2]) return z_bins_arr, gsmf_arr From 158fdedcb18e33c909a3329bc8afb33a14b5f9fe Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 10:38:13 +0100 Subject: [PATCH 5/7] undo debugging changes --- convert.sh | 1 - requirements.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/convert.sh b/convert.sh index cd9ff194..86f6e9eb 100644 --- a/convert.sh +++ b/convert.sh @@ -8,7 +8,6 @@ do for convert in ./*.py; do - echo $convert python3 $convert ../../../cosmology.py; this_return_code=$? return_code=$(( $return_code > $this_return_code ? $return_code : $this_return_code )) diff --git a/requirements.txt b/requirements.txt index 4076ee5c..2e86fcae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ velociraptor numpy>1.16.0 astropy matplotlib -mpi4py From 5e389d7f55d6ed5a681d5c61522be1cea078f4a3 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 10:51:41 +0100 Subject: [PATCH 6/7] changed GSMF -> GDMF everywhere in conversion scripts --- .../conversion/convertBeeston2018.py | 12 ++++++------ .../conversion/convertPozzi2020.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py index ac07a58a..5bc371fa 100644 --- a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py +++ b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py @@ -13,12 +13,12 @@ def load_file_and_split_by_z(raw_file_name): """ Read the data file and do all the mucking around needed to extract a list of the - redshift bins for which the GSMF is tabulated, along with the corresponding GSMF + redshift bins for which the GDMF is tabulated, along with the corresponding GDMF values and their errors. The number and spacing of the stellar mass bins vary with z; they are given in the first column of the returned array. - raw_file_name: the file name of the raw data file to extract the GSMF from + raw_file_name: the file name of the raw data file to extract the GDMF from """ data = np.genfromtxt(raw_file_name, comments="#") @@ -36,12 +36,12 @@ def load_file_and_split_by_z(raw_file_name): def process_for_redshift(z, gsmf_and_Mstar_at_z): """ - Output an HDF5 file containing the GSMF at a given redshift. + Output an HDF5 file containing the GDMF at a given redshift. - z: the redshift to produce the GSMF for. The given value corresponds to the lower + 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 - gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the + gsmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the chosen redshift """ @@ -129,7 +129,7 @@ def stringify_z(z): # z_bins is a 1-D ndarray containing the lower edges of the redshift bins # gsmf_and_Mstar is a list of 2D ndarrays, one per redshift # Each contains five columns as follows: -# log(Mstar) bins, Mstar errors, log(GSMF), GSMF +- errors +# log(Mstar) bins, Mstar errors, log(GDMF), GDMF +- errors z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): diff --git a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py index cc88515b..465df38c 100644 --- a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py +++ b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py @@ -13,12 +13,12 @@ def load_file_and_split_by_z(raw_file_name): """ Read the data file and do all the mucking around needed to extract a list of the - redshift bins for which the GSMF is tabulated, along with the corresponding GSMF + redshift bins for which the GDMF is tabulated, along with the corresponding GDMF values and their errors. The number and spacing of the stellar mass bins vary with z; they are given in the first column of the returned array. - raw_file_name: the file name of the raw data file to extract the GSMF from + raw_file_name: the file name of the raw data file to extract the GDMF from """ data = np.genfromtxt(raw_file_name, comments="#") @@ -35,12 +35,12 @@ def load_file_and_split_by_z(raw_file_name): def process_for_redshift(z, gsmf_and_Mstar_at_z): """ - Output an HDF5 file containing the GSMF at a given redshift. + Output an HDF5 file containing the GDMF at a given redshift. - z: the redshift to produce the GSMF for. The given value corresponds to the lower + 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 - gsmf_and_mstar_at_z: the array containing stellar mass bins and the GSMF at the + gsmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the chosen redshift """ @@ -129,7 +129,7 @@ def stringify_z(z): # z_bins is a 1-D ndarray containing the lower edges of the redshift bins # gsmf_and_Mstar is a list of 2D ndarrays, one per redshift # Each contains five columns as follows: -# log(Mstar) bins, Mstar errors, log(GSMF), GSMF +- errors +# log(Mstar) bins, Mstar errors, log(GDMF), GDMF +- errors z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): From 21bc871944a2a40cb5d5a456678309adfcf5c588 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 31 Mar 2020 10:55:05 +0100 Subject: [PATCH 7/7] also changed lowercase gsmf->gdmf in the conversion script --- .../conversion/convertBeeston2018.py | 30 +++++++++---------- .../conversion/convertPozzi2020.py | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py index 5bc371fa..e0e67f4a 100644 --- a/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py +++ b/data/GalaxyDustMassFunction/conversion/convertBeeston2018.py @@ -26,22 +26,22 @@ def load_file_and_split_by_z(raw_file_name): # array of the lower redshift bin edges for each GDMF z_bins_arr = np.unique(data[:, -2]) - gsmf_arr = [] + gdmf_arr = [] for zlow in z_bins_arr: bdx = data[:, -2] == zlow - gsmf_arr.append(data[bdx, :-2]) + gdmf_arr.append(data[bdx, :-2]) - return z_bins_arr, gsmf_arr + return z_bins_arr, gdmf_arr -def process_for_redshift(z, gsmf_and_Mstar_at_z): +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 - gsmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the + gdmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the chosen redshift """ @@ -58,18 +58,18 @@ def process_for_redshift(z, gsmf_and_Mstar_at_z): redshift = z h = cosmology.h - Mstar_bins = gsmf_and_Mstar_at_z[:, 0] + Mstar_bins = gdmf_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) + 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 ** gsmf_and_Mstar_at_z[:, 2][:, None] + 10 ** gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) - * gsmf_and_Mstar_at_z[:, [2, 3]] + * gdmf_and_Mstar_at_z[:, [2, 3]] ).T * (h / ORIGINAL_H) ** 3 * unyt.Solar_Mass @@ -77,9 +77,9 @@ def process_for_redshift(z, gsmf_and_Mstar_at_z): Phi_err = ( ( - 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + 10 ** gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) - * gsmf_and_Mstar_at_z[:, [4, 5]] + * gdmf_and_Mstar_at_z[:, [4, 5]] ).T * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) @@ -127,13 +127,13 @@ def stringify_z(z): os.mkdir(output_directory) # z_bins is a 1-D ndarray containing the lower edges of the redshift bins -# gsmf_and_Mstar is a list of 2D ndarrays, one per redshift +# gdmf_and_Mstar is a list of 2D ndarrays, one per redshift # Each contains five columns as follows: # log(Mstar) bins, Mstar errors, log(GDMF), GDMF +- errors -z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) +z_bins, gdmf_and_Mstar = load_file_and_split_by_z(input_filename) -for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): - processed = process_for_redshift(z, gsmf_and_Mstar_at_z) +for z, gdmf_and_Mstar_at_z in zip(z_bins, gdmf_and_Mstar): + processed = process_for_redshift(z, gdmf_and_Mstar_at_z) output_path = f"{output_directory}/{output_filename.format(stringify_z(z))}" diff --git a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py index 465df38c..3cac27ec 100644 --- a/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py +++ b/data/GalaxyDustMassFunction/conversion/convertPozzi2020.py @@ -26,21 +26,21 @@ def load_file_and_split_by_z(raw_file_name): # array of the lower redshift bin edges for each GDMF z_bins_arr = np.unique(data[:, -2]) - gsmf_arr = [] + gdmf_arr = [] for zlow in z_bins_arr: bdx = data[:, -2] == zlow - gsmf_arr.append(data[bdx, :-2]) - return z_bins_arr, gsmf_arr + gdmf_arr.append(data[bdx, :-2]) + return z_bins_arr, gdmf_arr -def process_for_redshift(z, gsmf_and_Mstar_at_z): +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 - gsmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the + gdmf_and_mstar_at_z: the array containing stellar mass bins and the GDMF at the chosen redshift """ @@ -58,18 +58,18 @@ def process_for_redshift(z, gsmf_and_Mstar_at_z): redshift = z h = cosmology.h - Mstar_bins = gsmf_and_Mstar_at_z[:, 0] + Mstar_bins = gdmf_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) + 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 ** gsmf_and_Mstar_at_z[:, 2][:, None] + 10 ** gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) - * gsmf_and_Mstar_at_z[:, [2, 3]] + * gdmf_and_Mstar_at_z[:, [2, 3]] ).T * (h / ORIGINAL_H) ** 3 * unyt.Solar_Mass @@ -77,9 +77,9 @@ def process_for_redshift(z, gsmf_and_Mstar_at_z): Phi_err = ( ( - 10 ** gsmf_and_Mstar_at_z[:, 2][:, None] + 10 ** gdmf_and_Mstar_at_z[:, 2][:, None] * np.log(10) - * gsmf_and_Mstar_at_z[:, [4, 5]] + * gdmf_and_Mstar_at_z[:, [4, 5]] ).T * (h / ORIGINAL_H) ** 3 * unyt.Mpc ** (-3) @@ -127,13 +127,13 @@ def stringify_z(z): os.mkdir(output_directory) # z_bins is a 1-D ndarray containing the lower edges of the redshift bins -# gsmf_and_Mstar is a list of 2D ndarrays, one per redshift +# gdmf_and_Mstar is a list of 2D ndarrays, one per redshift # Each contains five columns as follows: # log(Mstar) bins, Mstar errors, log(GDMF), GDMF +- errors -z_bins, gsmf_and_Mstar = load_file_and_split_by_z(input_filename) +z_bins, gdmf_and_Mstar = load_file_and_split_by_z(input_filename) -for z, gsmf_and_Mstar_at_z in zip(z_bins, gsmf_and_Mstar): - processed = process_for_redshift(z, gsmf_and_Mstar_at_z) +for z, gdmf_and_Mstar_at_z in zip(z_bins, gdmf_and_Mstar): + processed = process_for_redshift(z, gdmf_and_Mstar_at_z) output_path = f"{output_directory}/{output_filename.format(stringify_z(z))}"