Skip to content
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

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
52a7b08
Update the observational data to the most recent one
Fonotec Mar 1, 2023
d171d92
Update the config file and add the cosmic CC SN rate plot
Fonotec Mar 1, 2023
aed82c1
Include more cosmic SN rate plots into the pipeline
Fonotec Mar 6, 2023
cc035b9
Add description for the SNIa DTD models
Fonotec Mar 8, 2023
f5a1eda
Update the CEJSN, NSM and collapsar rate plots
Fonotec Mar 8, 2023
599ed8e
Incorparate new ordered plots and improve the ordering of the plots
Fonotec Mar 14, 2023
db6805a
Add scripts to use the CSFH to calculate the CC SN and SNIa rate
Fonotec Mar 16, 2023
07e56a9
Improve the CEJSN and collapsar plot script
Fonotec Mar 16, 2023
3ce2cb4
Add the Brown+2019 data to the specific SNIa rate versus stellar mass…
Fonotec Mar 21, 2023
ce9a2ac
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec Apr 28, 2023
535dd24
Update colibre/description.html
Fonotec Apr 28, 2023
7f7e784
Update colibre/description.html
Fonotec Apr 28, 2023
f476f93
Update colibre/description.html
Fonotec Apr 28, 2023
faf16f9
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec May 22, 2023
ab26d85
Update colibre/auto_plotter/snia_rates.yml
Fonotec May 22, 2023
dfb2aed
Update colibre/auto_plotter/snia_rates.yml
Fonotec May 22, 2023
3d75338
Update colibre/auto_plotter/snia_rates.yml
Fonotec May 22, 2023
0e167e1
Update the description string
Fonotec May 22, 2023
fc42d50
Remove out commented code
Fonotec May 22, 2023
31fdbe7
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec May 22, 2023
7c1b118
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec May 22, 2023
3a1e380
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec May 22, 2023
2f488c4
Update colibre/scripts/cosmic_log_CC_SN_rate.py
Fonotec May 22, 2023
cb47568
Update colibre/scripts/cosmic_log_CC_SN_rate.py
Fonotec May 22, 2023
a0dda86
Update colibre/scripts/cosmic_log_SNIa_rate.py
Fonotec May 22, 2023
bd80b52
Update colibre/scripts/cosmic_log_SNIa_rate.py
Fonotec May 22, 2023
196a695
Update colibre/scripts/cosmic_log_SNIa_rate_CSFH_based.py
Fonotec May 22, 2023
3b42698
Update colibre/scripts/cosmic_log_SNIa_rate_CSFH_based.py
Fonotec May 22, 2023
6927f19
Update colibre/scripts/cosmic_SNIa_rate_CSFH_based.py
Fonotec May 22, 2023
df13395
Update colibre/scripts/cosmic_SNIa_rate_CSFH_based.py
Fonotec May 22, 2023
9f55395
Update colibre/scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
Fonotec May 22, 2023
e454ddf
Apply suggestions from code review
Fonotec May 22, 2023
15a108d
Improve Evgeniis comments on the description
Fonotec May 23, 2023
257dc7e
Include further suggestions from Evgenii to the code
Fonotec May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 152 additions & 105 deletions colibre/auto_plotter/snia_rates.yml

Large diffs are not rendered by default.

65 changes: 60 additions & 5 deletions colibre/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,66 @@ description_template: description.html

# Location and description of additional figures
scripts:
- filename: scripts/cosmic_log_SNIa_rate_CSFH_based.py
title: 'Cosmic SNIa rate'
caption: SNIa rate history calculated from the SFR.txt file produced by SWIFT.
section: SN Rate (cosmic - CSFH based)
output_file: log_SNIa_rate_history_based_on_CSFH.png
- filename: scripts/cosmic_SNIa_rate_CSFH_based.py
title: 'Cosmic SNIa rate'
caption: SNIa rate history calculated from the SFR.txt file produced by SWIFT.
section: SN Rate (cosmic - CSFH based)
output_file: SNIa_rate_history_based_on_CSFH.png
- filename: scripts/cosmic_log_CC_SN_rate_CSFH_based.py
title: 'Cosmic CC SN rate'
caption: CC SN rate history calculated from the SFR.txt file produced by SWIFT.
section: SN Rate (cosmic - CSFH based)
output_file: log_CC_SN_rate_history_based_on_CSFH.png
- filename: scripts/cosmic_CC_SN_rate_CSFH_based.py
title: 'Cosmic CC SN rate'
caption: CC SN rate history calculated from the SFR.txt file produced by SWIFT.
section: SN Rate (cosmic - CSFH based)
output_file: CC_SN_rate_history_based_on_CSFH.png
- filename: scripts/cosmic_SNIa_over_CC_SN_rate_CSFH_based.py
title: 'Cosmic SNIa rate / CC SN rate'
caption: SNIa rate over CC SN rate history calculated from the SFR.txt file produced by SWIFT.
section: SN Rate (cosmic - CSFH based)
output_file: SNIa_over_CC_rate_history_based_on_CSFH.png
- filename: scripts/cosmic_SNIa_rate.py
title: 'Cosmic SNIa rate'
caption: SNIa rate history plotted directly from the SNIa.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: SNIa_rate_history.png
- filename: scripts/cosmic_log_SNIa_rate.py
title: 'Cosmic SNIa rate'
caption: SNIa rate history plotted directly from the SNIa.txt file produced by SWIFT.
Comment on lines +49 to +55
Copy link
Collaborator

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.

section: SN Rate (cosmic - stochastic)
output_file: log_SNIa_rate_history.png
- filename: scripts/cosmic_CC_SN_rate.py
title: 'Cosmic CC SN rate'
caption: CC SN rate history plotted directly from the SNII.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: CC_SN_rate_history.png
- filename: scripts/cosmic_log_CC_SN_rate.py
title: 'Cosmic CC SN rate'
caption: CC SN rate history plotted directly from the SNII.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: log_CC_SN_rate_history.png
- filename: scripts/cosmic_log_NSM_rate.py
title: 'Cosmic NS-NS merger rate'
caption: NS-NS merger rate or short GRB rate plotted directly from the r_processes.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: log_NSM_rate_history.png
- filename: scripts/cosmic_log_CEJSN_rate.py
title: 'Cosmic common-envelop jets SN rate'
caption: Common-envelop (CE) jets SN rate plotted directly from the r_processes.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: log_CEJSN_rate_history.png
- filename: scripts/cosmic_log_collapsar_rate.py
title: 'Cosmic collapsar rate'
caption: Collapsar rate plotted directly from the r_processes.txt file produced by SWIFT.
section: SN Rate (cosmic - stochastic)
output_file: log_collapsar_rate_history.png
- filename: scripts/density_temperature.py
caption: Density-temperature diagram. If present, dashed line represents the entropy floor (equation of state).
output_file: density_temperature.png
Expand Down Expand Up @@ -503,8 +563,3 @@ scripts:
section: Column Densities
additional_arguments:
parallel: True
- filename: scripts/cosmic_SNIa_rate.py
title: 'Cosmic SNIa rate'
caption: SNIa rate history plotted directly from the SNIa.txt file produced by SWIFT.
section: SNIa Rate
output_file: SNIa_rate_history.png
93 changes: 93 additions & 0 deletions colibre/description.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be clearer to just give units of $\rm M_\odot^{-1}$ after the value of this parameter in the right column of the table, instead of saying per Msun in the name of this parameter?

The same comment also applies to the other lines of the code below whose text contains SNIa efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down
162 changes: 162 additions & 0 deletions colibre/scripts/cosmic_CC_SN_rate.py
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")

Loading