diff --git a/doc/scripts/TimeSeries.py b/doc/scripts/TimeSeries.py index a9fc21c35..1c2c7a726 100644 --- a/doc/scripts/TimeSeries.py +++ b/doc/scripts/TimeSeries.py @@ -1,18 +1,27 @@ #!/usr/bin/env python -from snewpy import snowglobes +from snewpy.models.ccsn import Nakazato_2013 +from snewpy.neutrino import MassHierarchy, MixingParameters +from snewpy.flavor_transformation import AdiabaticMSW +from snewpy.rate_calculator import RateCalculator -SNOwGLoBES_path = None # change to SNOwGLoBES directory if using a custom detector configuration +import numpy as np +import astropy.units as u -# arguments for generate_time_series -model_file = "/path/to/snewpy/models/Nakazato_2013/nakazato-LS220-BH-z0.004-s30.0.fits" -modeltype = 'Nakazato_2013' -transformation = 'AdiabaticMSW_NMO' -d = 10 # Supernova distance in kpc +model = Nakazato_2013(progenitor_mass=30*u.solMass, revival_time=0*u.ms, metallicity=0.004, eos='LS220') -# Running the modules -outfile = snowglobes.generate_time_series(model_file, modeltype, transformation, d) -snowglobes.simulate(SNOwGLoBES_path, outfile, detector_input="icecube") -snowglobes.collate(SNOwGLoBES_path, outfile) +transformation = AdiabaticMSW(MixingParameters('NORMAL')) # Desired flavor transformation + +times = model.get_time() +energies = np.linspace(0,100,501)<" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#plot all the channels cross-sections\n", "E = np.linspace(0,50,101)<" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "rates = det.run(flux)\n", "plot_rate(sum_rates(list(rates.values())), axis='energy', label='Total', lw=2, color='k')\n", "for chan,rate in rates.items():\n", " plot_rate(rate, axis='energy', label=chan)\n", @@ -284,6 +433,43 @@ "plt.show()" ] }, + { + "cell_type": "markdown", + "id": "f40d1760-1973-4b32-a6b6-f01c6cf4df87", + "metadata": {}, + "source": [ + "### Save the rates to file" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "bc2095a2-0cbd-4b41-8caa-39a5e3562ec0", + "metadata": {}, + "outputs": [], + "source": [ + "np.savez(\"Bollig_2016.scint20kt.npz\", **rates)" + ] + }, + { + "cell_type": "markdown", + "id": "76fa09c6-bf83-4d86-9499-04eec7454c13", + "metadata": {}, + "source": [ + "### To load the rates from file" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "1b6b6c9d-f724-4f8d-a10c-f431b4f65d12", + "metadata": {}, + "outputs": [], + "source": [ + "with np.load(\"Bollig_2016.scint20kt.npz\", allow_pickle=True) as data:\n", + " rates = {key: data[key].item() for key in data.files}" + ] + }, { "cell_type": "markdown", "id": "dafb09b7-5626-475b-9176-49d01b76a830", @@ -294,10 +480,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "af612683-0bc4-4f2e-8262-8b678b82d84e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Detector(name=\"scint_det\", mass=20.0 kt, channels=['ibd', 'nc_C12'])" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from snewpy.neutrino import Flavor\n", "from snewpy.rate_calculator import Detector, DetectionChannel\n", @@ -344,10 +541,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "53304732-d047-44e8-86e4-6a4b82af19d0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'ibd': DetectionChannel (flavor=NU_E_BAR, smearing=True, weight=0.1429),\n", + " 'nc_C12': DetectionChannel (flavor=NU_E,NU_E_BAR,NU_MU,NU_MU_BAR,NU_TAU,NU_TAU_BAR, smearing=True, weight=0.07)}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "det.channels" ] @@ -366,7 +575,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "499c21ce-d1d7-45ab-8a2b-92f2894e9340", "metadata": {}, "outputs": [], @@ -399,7 +608,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "c531d8f8-d08f-418b-98d9-2fe260be9bbc", "metadata": {}, "outputs": [], @@ -426,7 +635,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "7ae1ce70-4acd-4e48-953e-48c71407080a", "metadata": {}, "outputs": [], @@ -451,7 +660,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "818f56cc-fc42-4ef2-814e-f6735bb51351", "metadata": {}, "outputs": [], @@ -473,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "1ec39528-b29a-4e5c-9a19-8bbfd76684ee", "metadata": {}, "outputs": [], @@ -506,7 +715,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.13" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/python/snewpy/flux.py b/python/snewpy/flux.py index 53ce54331..9bb7c9896 100644 --- a/python/snewpy/flux.py +++ b/python/snewpy/flux.py @@ -108,7 +108,7 @@ def __init__(self, *, integrable_axes: set[Axes] | None = None, flavor_scheme: FlavorScheme | None = None - ): + ): """A container class storing the physical quantity (flux, fluence, rate...), which depends on flavor, time and energy. Parameters @@ -484,8 +484,7 @@ def project_to(self, axis='energy', squeeze=False): if squeeze: return x, fP.array.squeeze().T else: - return x, fP - + return x, fP def plot(flux, projection='energy', styles=None, **kwargs): x, fP = flux.project_to(projection, squeeze=False) @@ -511,6 +510,27 @@ def plot(flux, projection='energy', styles=None, **kwargs): plt.ylabel(f'{fP.__class__.__name__}, {x.unit._repr_latex_()}') return lines + @staticmethod + def _reconstruct(array, flavor, time, energy, integrable_axes, flavor_scheme): + return Container(array, + flavor, + time, + energy, + integrable_axes=integrable_axes, + flavor_scheme=flavor_scheme, + ) + + def __reduce__(self): + return ( Container._reconstruct, + ( self.array, + self.flavor, + self.time, + self.energy, + self._integrable_axes, + self.flavor_scheme, + ), + ) + #some standard container classes that can be used for Flux = Container['1/(MeV*s*m**2)', "d2FdEdT"] Fluence = Container[Flux.unit*u.s, "dFdE"] diff --git a/python/snewpy/models/base.py b/python/snewpy/models/base.py index c8b153008..bbdf35706 100644 --- a/python/snewpy/models/base.py +++ b/python/snewpy/models/base.py @@ -133,9 +133,9 @@ def get_initial_spectra(self, t, E): """ spectra_dict = self._get_initial_spectra_dict(t, E, flavors=ThreeFlavor) initial_spectra = flux.Container['1/(MeV*s)'].from_dict(spectra_dict, - time=t, - energy=E, - flavor_scheme=ThreeFlavor) + time=t, + energy=E, + flavor_scheme=ThreeFlavor) return initial_spectra def get_transformed_spectra(self, t, E, flavor_xform):