Skip to content

Commit

Permalink
also changed lowercase gsmf->gdmf in the conversion script
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrayford committed Mar 31, 2020
1 parent 5e389d7 commit 21bc871
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions data/GalaxyDustMassFunction/conversion/convertBeeston2018.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand All @@ -58,28 +58,28 @@ 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
)

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)
Expand Down Expand Up @@ -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))}"

Expand Down
30 changes: 15 additions & 15 deletions data/GalaxyDustMassFunction/conversion/convertPozzi2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand All @@ -58,28 +58,28 @@ 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
)

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)
Expand Down Expand Up @@ -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))}"

Expand Down

0 comments on commit 21bc871

Please sign in to comment.