Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 21 additions & 12 deletions doc/scripts/TimeSeries.py
Original file line number Diff line number Diff line change
@@ -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)<<u.MeV
distance = 10*u.kpc

# An additional, optional argument in simulate() is the detector name, if one wants to only run 1 detector, rather than all of them.
flux = model.get_flux(t=times, E=energies, distance=distance, flavor_xform=transformation)
fluence = flux.integrate('time')

detector = "wc100kt30prct"
rc = RateCalculator()
events = rc.run(fluence, detector, detector_effects=True)

filename = f"{model}.{transformation}.{times[0]:.3f}-{times[-1]:.3f},{energies[0]:.3f}-{energies[-1]:.3f},{distance:.3f}.{detector}.npz"
np.savez(filename,**events)
273 changes: 241 additions & 32 deletions doc/source/nb/dev/Detector_demo.ipynb

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions python/snewpy/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions python/snewpy/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading