-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Update the SNIa rate plots in the pipeline #242
base: master
Are you sure you want to change the base?
Changes from all commits
52a7b08
d171d92
aed82c1
cc035b9
f5a1eda
599ed8e
db6805a
07e56a9
3ce2cb4
ce9a2ac
535dd24
7f7e784
f476f93
faf16f9
ab26d85
dfb2aed
3d75338
0e167e1
fc42d50
31fdbe7
7c1b118
3a1e380
2f488c4
cb47568
a0dda86
bd80b52
196a695
3b42698
6927f19
df13395
9f55395
e454ddf
15a108d
257dc7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,99 @@ <h4>Chemistry</h4> | |
</tr> | ||
</table> | ||
|
||
<h4>SNIa DTD</h4> | ||
{% if data.metadata.parameters.get("SNIaDTD:normalization_timescale_Gyr", False) %} | ||
<table> | ||
<tr> | ||
<th>Parameter</th> | ||
<th>Value</th> | ||
</tr> | ||
{% if data.metadata.parameters.get("SNIaDTD:SNIa_efficiency_gauss_p_Msun", False) %} | ||
<tr> | ||
<td>Model</td> | ||
<td>Gaussian</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa efficiency per Msun (Gaussian part)</td> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be clearer to just give units of The same comment also applies to the other lines of the code below whose text contains There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right, I will change this |
||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_efficiency_gauss_p_Msun") }}</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa efficiency per Msun (constant part)</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_efficiency_const_p_Msun") }}</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa delay time</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_delay_time_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Normalisation time scale (constant part)</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:normalization_timescale_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Characteristic time of the Guassian</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:characteristic_time_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Standard deviation time of the Guassian</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:STD_characteristic_time_Gyr") }} Gyr</td> | ||
</tr> | ||
{% else %} | ||
<tr> | ||
<td>Model</td> | ||
<td>Power law</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa efficiency per Msun</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_efficiency_p_Msun") }}</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa delay time</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_delay_time_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Normalisation time scale</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:normalization_timescale_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Power law slope</td> | ||
{% if data.metadata.parameters.get("SNIaDTD:power_law_slope", False) %} | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:power_law_slope") }}</td> | ||
{% else %} | ||
<td>1.0</td> | ||
{% endif %} | ||
</tr> | ||
{% endif %} | ||
</table> | ||
|
||
{% else %} | ||
{% if data.metadata.parameters.get("SNIaDTD:SNIa_timescale_Gyr", False) %} | ||
<table> | ||
<tr> | ||
<th>Parameter</th> | ||
<th>Value</th> | ||
</tr> | ||
<tr> | ||
<td>Model</td> | ||
<td>exponential</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa efficiency per Msun</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_efficiency_p_Msun") }}</td> | ||
</tr> | ||
<tr> | ||
<td>SNIa delay time</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_delay_time_Gyr") }} Gyr</td> | ||
</tr> | ||
<tr> | ||
<td>Exponential delay time</td> | ||
<td>{{ data.metadata.parameters | get_if_present_float("SNIaDTD:SNIa_timescale_Gyr") }} Gyr</td> | ||
</tr> | ||
</table> | ||
{% else %} | ||
<p>DTD model is not found</p> | ||
{% endif %} | ||
{% endif %} | ||
|
||
<h4>AGN feedback</h4> | ||
{% if data.metadata.parameters.get("COLIBREAGN:AGN_delta_T_K", False) %} | ||
<table> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
""" | ||
Plots the cosmic CCSN rate history. | ||
""" | ||
import unyt | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import glob | ||
|
||
from swiftsimio import load | ||
|
||
from velociraptor.observations import load_observations | ||
|
||
from astropy.cosmology import z_at_value | ||
from astropy.units import Gyr | ||
|
||
from swiftpipeline.argumentparser import ScriptArgumentParser | ||
|
||
arguments = ScriptArgumentParser( | ||
description="Creates a CC SN rate history plot, with added observational data." | ||
) | ||
|
||
snapshot_filenames = [ | ||
f"{directory}/{snapshot}" | ||
for directory, snapshot in zip(arguments.directory_list, arguments.snapshot_list) | ||
] | ||
|
||
CCSN_filenames = [f"{directory}/SNII.txt" for directory in arguments.directory_list] | ||
|
||
names = arguments.name_list | ||
output_path = arguments.output_directory | ||
|
||
plt.style.use(arguments.stylesheet_location) | ||
|
||
simulation_lines = [] | ||
simulation_labels = [] | ||
|
||
fig, ax = plt.subplots() | ||
|
||
ax.semilogx() | ||
|
||
log_multiplicative_factor = 4 | ||
multiplicative_factor = 10 ** log_multiplicative_factor | ||
CC_SN_rate_output_units = 1.0 / (unyt.yr * unyt.Mpc ** 3) | ||
|
||
for idx, (snapshot_filename, CCSN_filename, name) in enumerate( | ||
zip(snapshot_filenames, CCSN_filenames, names) | ||
): | ||
data = np.loadtxt( | ||
CCSN_filename, | ||
usecols=(4, 6, 11), | ||
dtype=[("a", np.float32), ("z", np.float32), ("CC SN rate", np.float32)], | ||
) | ||
|
||
snapshot = load(snapshot_filename) | ||
|
||
# Read cosmology from the first run in the list | ||
if idx == 0: | ||
cosmology = snapshot.metadata.cosmology | ||
|
||
units = snapshot.units | ||
CC_SN_rate_units = 1.0 / (units.time * units.length ** 3) | ||
|
||
# a, Redshift, SFR | ||
scale_factor = data["a"] | ||
CC_SN_rate = (data["CC SN rate"] * CC_SN_rate_units).to(CC_SN_rate_output_units) | ||
|
||
# High z-order as we always want these to be on top of the observations | ||
simulation_lines.append( | ||
ax.plot(scale_factor, CC_SN_rate.value * multiplicative_factor, zorder=10000)[0] | ||
) | ||
simulation_labels.append(name) | ||
|
||
|
||
observation_lines = [] | ||
observation_labels = [] | ||
|
||
path_to_obs_data = f"{arguments.config.config_directory}/{arguments.config.observational_data_directory}" | ||
observational_data = load_observations( | ||
sorted(glob.glob(f"{path_to_obs_data}/data/CosmicCCSNRate/*.hdf5")) | ||
) | ||
|
||
for obs_data in observational_data: | ||
observation_lines.append( | ||
ax.errorbar( | ||
obs_data.x.value, | ||
obs_data.y.value * multiplicative_factor, | ||
yerr=obs_data.y_scatter.value * multiplicative_factor, | ||
label=obs_data.citation, | ||
linestyle="none", | ||
marker="o", | ||
elinewidth=0.5, | ||
markeredgecolor="none", | ||
markersize=2, | ||
zorder=-10, | ||
) | ||
) | ||
observation_labels.append(f"{obs_data.citation}") | ||
|
||
redshift_ticks = np.array([0.0, 0.2, 0.5, 1.0, 2.0, 3.0, 5.0, 10.0, 20.0, 50.0, 100.0]) | ||
redshift_labels = [ | ||
"$0$", | ||
"$0.2$", | ||
"$0.5$", | ||
"$1$", | ||
"$2$", | ||
"$3$", | ||
"$5$", | ||
"$10$", | ||
"$20$", | ||
"$50$", | ||
"$100$", | ||
] | ||
a_ticks = 1.0 / (redshift_ticks + 1.0) | ||
|
||
ax.set_xticks(a_ticks) | ||
ax.set_xticklabels(redshift_labels) | ||
|
||
observation_legend = ax.legend( | ||
observation_lines, observation_labels, markerfirst=True, loc="center right", fontsize="xx-small" | ||
) | ||
|
||
simulation_legend = ax.legend( | ||
simulation_lines, simulation_labels, markerfirst=False, loc="upper right" | ||
) | ||
|
||
ax.add_artist(observation_legend) | ||
|
||
# Create second X-axis (to plot cosmic time alongside redshift) | ||
ax2 = ax.twiny() | ||
ax2.set_xscale("log") | ||
|
||
# Cosmic-time ticks (in Gyr) along the second X-axis | ||
t_ticks = np.array([0.5, 1.0, 2.0, 4.0, 6.0, 8.0, 10.0, cosmology.age(1.0e-5).value]) | ||
|
||
# To place the new ticks onto the X-axis we need to know the corresponding scale factors | ||
a_ticks_2axis = [ | ||
1.0 / (1.0 + z_at_value(cosmology.age, t_tick * Gyr)) for t_tick in t_ticks | ||
] | ||
|
||
# Attach the ticks to the second X-axis | ||
ax2.set_xticks(a_ticks_2axis) | ||
|
||
# Format the ticks' labels | ||
ax2.set_xticklabels(["$%2.1f$" % t_tick for t_tick in t_ticks]) | ||
|
||
# Final adjustments | ||
ax.tick_params(axis="x", which="minor", bottom=False) | ||
ax2.tick_params(axis="x", which="minor", top=False) | ||
|
||
ax.set_ylim(0.0, 26.0) | ||
ax.set_xlim(1.02, 0.07) | ||
ax2.set_xlim(1.02, 0.07) | ||
|
||
ax.set_xlabel("Redshift $z$") | ||
ax.set_ylabel( | ||
f"CC SN rate [$10^{{-{log_multiplicative_factor}}}$ yr$^{{-1}}$ cMpc$^{{-3}}$]" | ||
) | ||
ax2.set_xlabel("Cosmic time [Gyr]") | ||
|
||
fig.savefig(f"{output_path}/CC_SN_rate_history.png") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have plots that show different things (e.g. log vs. linear SNIa rate). But you use the same caption and title for both plots, as if it was the same plot. Please be more specific and reflect in the caption and in the title what is different between the plots. E.g. if the plot is in long, then I would write
log
both in the caption and in the title.The same comment applies also to the cosmic CC SN rate. And also SNIa / CC SN both CSFH based and not CSFH based.