Skip to content

Commit

Permalink
Closes #342: adding the function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheshuk committed Jun 17, 2024
1 parent 1ca49cb commit 4e2be8e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion python/snewpy/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#list of units which will be used as units for decomposition inside the Container
snewpy_unit_bases = [u.MeV, u.m, u.s, u.kg]

import matplotlib.pyplot as plt

class Axes(IntEnum):
"""Enum to keep the number number of the array dimension for each axis"""
flavor=0, #Flavor dimension
Expand Down Expand Up @@ -442,7 +444,27 @@ def __class_getitem__(cls, args):
name = name or f'{cls.__name__}[{unit}]'
cls._unit_classes[unit] = type(name,(cls,),{'unit':unit})
return cls._unit_classes[unit]


def plot(flux, projection='energy', styles=None, **kwargs):
if projection=='energy':
fP = flux.integrate_or_sum('time')
else:
fP = flux.integrate_or_sum('energy')
x = fP.__dict__[projection]
if isinstance(styles, dict):
styles = styles.get
elif styles==None:
styles = lambda flv: {'ls':'-' if flv.is_neutrino else ':',
'color':f'C{flv//2:d}'}
for flv in fP.flavor:
style = styles(flv)
style.update(kwargs)
y = fP[flv].array.squeeze()
plt.plot(x,y,label=flv.to_tex(), **style)
plt.legend(ncols=2)
plt.xlabel(f'{projection}, {x.unit._repr_latex_()}')
plt.ylabel(f'{fP.__class__.__name__}, {x.unit._repr_latex_()}')
return

#some standard container classes that can be used for
Flux = Container['1/(MeV*s*m**2)', "d2FdEdT"]
Expand Down

0 comments on commit 4e2be8e

Please sign in to comment.