Skip to content

Commit

Permalink
Merge pull request #313 from SNEWS2/JostMigenda/restoreModelNotebooks
Browse files Browse the repository at this point in the history
Restore Model Notebooks
  • Loading branch information
JostMigenda authored Apr 29, 2024
2 parents 715246c + 6eb9c88 commit 745114f
Show file tree
Hide file tree
Showing 23 changed files with 4,332 additions and 950 deletions.
602 changes: 0 additions & 602 deletions doc/nb/Fornax_2022.ipynb

This file was deleted.

346 changes: 0 additions & 346 deletions doc/nb/Mori_2023.ipynb

This file was deleted.

6 changes: 5 additions & 1 deletion doc/nb/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SNEWPY Usage Examples

The Jupyter notebooks in this directory contain different examples for how to use SNEWPY. Please see also the example notebooks for each supernova model, which are included in the same directory as the model files when downloading them via `python -c 'import snewpy; snewpy.get_models()'`.
The Jupyter notebooks in this directory contain different examples for how to use SNEWPY.

## `ccsn` and `presn` Directories

These directories contain notebooks demonstrating how to use the core-collapse and pre-supernova models available through SNEWPY.

## AnalyticFluence

Expand Down
File renamed without changes.
189 changes: 189 additions & 0 deletions doc/nb/ccsn/Bollig_2016.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bollig 2016 Models\n",
"\n",
"Data from Mirizzi et al., particular the models that go into Figure 17. Models (s11.2c and s27.0c) taken from the Garching Supernova archive (https://wwwmpa.mpa-garching.mpg.de/ccsnarchive/data/Bollig2016/) with permission for use in SNEWS2.0.\n",
"\n",
"Reference: Mirizzi et al. Rivista del Nuovo Cimento Vol 39 N. 1-2 (2016)\n",
"- doi:10.1393/ncr/i2016-10120-8\n",
"- arXiv:1508.00785"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from astropy import units as u \n",
"\n",
"from snewpy.neutrino import Flavor, MassHierarchy\n",
"from snewpy.models.ccsn import Bollig_2016\n",
"from snewpy.flavor_transformation import NoTransformation, AdiabaticMSW, ThreeFlavorDecoherence\n",
"\n",
"mpl.rc('font', size=16)\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize Models\n",
"\n",
"To start, let’s see what progenitors are available for the `Bollig_2016` model. We can use the `param` property to view all physics parameters and their possible values:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Bollig_2016.param"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We’ll initialise both of these progenitors. If this is the first time you’re using a progenitor, snewpy will automatically download the required data files for you."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m11 = Bollig_2016(progenitor_mass=11.2*u.solMass)\n",
"m27 = Bollig_2016(progenitor_mass=27*u.solMass)\n",
"\n",
"m11"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, let’s plot the luminosity of different neutrino flavors for this model. (Note that the `Bollig_2016` simulations didn’t distinguish between $\\nu_x$ and $\\bar{\\nu}_x$, so both have the same luminosity.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(1, 2, figsize=(12, 5), sharex=True, sharey=True, tight_layout=True)\n",
"\n",
"for i, model in enumerate([m11, m27]):\n",
" ax = axes[i]\n",
" for flavor in Flavor:\n",
" ax.plot(model.time, model.luminosity[flavor]/1e51, # Report luminosity in units foe/s\n",
" label=flavor.to_tex(),\n",
" color='C0' if flavor.is_electron else 'C1',\n",
" ls='-' if flavor.is_neutrino else ':',\n",
" lw=2)\n",
" ax.set(xlim=(0.0, 0.35),\n",
" xlabel=r'$t-t_{\\rm bounce}$ [s]',\n",
" title=r'{}: {} $M_\\odot$'.format(model.metadata['EOS'], model.metadata['Progenitor mass'].value))\n",
" ax.grid()\n",
" ax.legend(loc='upper right', ncol=2, fontsize=18)\n",
"\n",
"axes[0].set(ylabel=r'luminosity [foe s$^{-1}$]');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initial and Oscillated Spectra\n",
"\n",
"Plot the neutrino spectra at the source and after the requested flavor transformation has been applied.\n",
"\n",
"### Adiabatic MSW Flavor Transformation: Normal mass ordering"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Adiabatic MSW effect. NMO is used by default.\n",
"xform_nmo = AdiabaticMSW()\n",
"\n",
"# Energy array and time to compute spectra.\n",
"# Note that any convenient units can be used and the calculation will remain internally consistent.\n",
"E = np.linspace(0,100,201) * u.MeV\n",
"t = 50*u.ms\n",
"\n",
"ispec = model.get_initial_spectra(t, E)\n",
"ospec_nmo = model.get_transformed_spectra(t, E, xform_nmo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(1,2, figsize=(12,5), sharex=True, sharey=True, tight_layout=True)\n",
"\n",
"for i, spec in enumerate([ispec, ospec_nmo]):\n",
" ax = axes[i]\n",
" for flavor in Flavor:\n",
" ax.plot(E, spec[flavor],\n",
" label=flavor.to_tex(),\n",
" color='C0' if flavor.is_electron else 'C1',\n",
" ls='-' if flavor.is_neutrino else ':', lw=2,\n",
" alpha=0.7)\n",
"\n",
" ax.set(xlabel=r'$E$ [{}]'.format(E.unit),\n",
" title='Initial Spectra: $t = ${:.1f}'.format(t) if i==0 else 'Oscillated Spectra: $t = ${:.1f}'.format(t))\n",
" ax.grid()\n",
" ax.legend(loc='upper right', ncol=2, fontsize=16)\n",
"\n",
"ax = axes[0]\n",
"ax.set(ylabel=r'flux [erg$^{-1}$ s$^{-1}$]')\n",
"\n",
"fig.tight_layout();"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.5 ('snews')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
},
"vscode": {
"interpreter": {
"hash": "e2528887d751495e023d57d695389d9a04f4c4d2e5866aaf6dc03a1ed45c573e"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 745114f

Please sign in to comment.