{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Reading SNOwGLoBES-Format Model Files\n", "\n", "Demonstrate how `snewpy` can read files in the tabular `.dat` input format used by `SNOwGLoBES` and plot the data.\n", "\n", "Note: These files only contain time-integrated fluences, not the full information that is available in all other models. Accordingly, much of the functionality of `snewpy` is not available for these files.\n", "\n", "At the moment the class only reads the NoOsc files inside the tarfiles." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from snewpy.models.ccsn import SNOwGLoBES\n", "\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "\n", "mpl.rc('font', size=14)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting Functions\n", "\n", "Two functions are provided:\n", "1. One to plot the spectrum (number flux, actually fluence) at a given time.\n", "1. One to plot the fluence in 2D vs. energy and time." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def plot_spectrum(snmodel, time=0.):\n", " \"\"\"Plot spectrum (count/cm2) from SNOwGLoBES model at a given time.\n", " \"\"\"\n", " fig, axes = plt.subplots(2,3, figsize=(14,8), sharex=True, sharey=True,\n", " gridspec_kw={'wspace':0, 'hspace':0})\n", "\n", " for ax, (flavor, fl) in zip(axes.flatten(), snmodel.get_fluence(time).items()): \n", " ax.plot(snmodel.energy, fl, label=flavor)\n", " ax.legend()\n", " ax.grid(ls=':')\n", "\n", " axes[0,0].set(ylabel='fluence [cm$^{-2}$ (0.2 MeV)$^{-1}$]')\n", " axes[1,0].set(xlabel='energy [MeV]', xlim=(-0.5,10.5))\n", " fig.tight_layout()\n", " return fig\n", "\n", "def plot_fluence(snmodel, log=False):\n", " \"\"\"Plot the fluence (count/cm2) vs energy and time.\n", " \"\"\"\n", " fig, axes = plt.subplots(2,3, figsize=(14,8), sharex=True, sharey=True,\n", " gridspec_kw={'wspace':0, 'hspace':0})\n", "\n", " if log:\n", " norm = mpl.colors.LogNorm(vmin=1., vmax=snmodel.fmax)\n", " else:\n", " norm = mpl.colors.Normalize(vmin=0., vmax=snmodel.fmax)\n", " \n", " for ax, (flavor, fl) in zip(axes.flatten(), snmodel.flux.items()): \n", " im = ax.imshow(fl, extent=[snmodel.time[0], snmodel.time[-1], snmodel.energy[0], snmodel.energy[-1]],\n", " origin='lower', cmap='Blues', norm=norm,\n", " aspect='auto')\n", " ax.text(0.8,0.9, flavor, fontsize=12, transform=ax.transAxes)\n", " ax.grid(ls=':')\n", "\n", " axes[0,0].set(xlim=(snmodel.time[0], snmodel.time[-1]),\n", " ylim=(0,10), ylabel='energy [MeV]')\n", " axes[1,0].set(xlabel='time [s]')\n", "\n", " fig.tight_layout()\n", " fig.subplots_adjust(right=0.8)\n", " cb_ax = fig.add_axes([0.82, 0.1, 0.02, 0.85])\n", " cb = fig.colorbar(im, cax=cb_ax)\n", " cb.set_label('fluence [cm$^{-2}$ (0.2 MeV)$^{-1}$]')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PISN Models\n", "\n", "Plot the spectrum at $t=0$ and the total fluence for some of the PISN models.\n", "\n", "### 150$M_{\\odot}$ Progenitor, Helm EOS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**May 2026: the following cells are BROKEN and need to be fixed in a new PR**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn1 = SNOwGLoBES('../../models/PISN/PISN_150Msun_EOS=Helm_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn1, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn1, time=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 150$M_\\odot$ Progenitor, SFHo EOS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn2 = SNOwGLoBES('../../models/PISN/PISN_150Msun_EOS=SFHo_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn2, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn2, time=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 250$M_\\odot$ Progenitor, Helm EOS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn3 = SNOwGLoBES('../../models/PISN/PISN_250Msun_EOS=Helm_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn3, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn3, time=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 250$M_\\odot$ Progenitor, SFHo EOS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn4 = SNOwGLoBES('../../models/PISN/PISN_250Msun_EOS=SFHo_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn4, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn4, time=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Type Ia Models\n", "\n", "### GCD" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn5 = SNOwGLoBES('../../models/Type_Ia/GCD_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn5, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn5, time=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### DDT" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn6 = SNOwGLoBES('../../models/Type_Ia/DDT_NeutrinoFlux.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn6)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn6, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn6, time=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Nakazato CCSN Model\n", "\n", "Load the Nakazato CCSN model written to SNOwGLoBES format using the `generate_*` functions in `snewpy.snowglobes`.\n", "\n", "Note that the Nakazato SNOwGLoBES tarball is not uploaded to GitHub. If you want to repeat this, generate it yourself the converter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sn7 = SNOwGLoBES('../../models/Nakazato_2013/nakazato-LS220-BH-z0.004-s30.0.SNOformat.tar.bz2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn7)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_fluence(sn7, log=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# fig = plot_spectrum(sn7, time=0)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.13" } }, "nbformat": 4, "nbformat_minor": 4 }