Conversation
Fixed Fornax_2019._get_initial_spectra_dict to correctly handle array time input and return a number spectrum [1/(MeV*s)] rather than a differential luminosity [erg/(MeV*s)]. Also fixed Python 3.10+ import error in flavor.py caused by FlavorEnumMeta not supporting the | type union annotation syntax.
Type annotationsI cannot reproduce this issue on Python 3.13: >>> from snewpy.flavor import FlavorMatrix, FlavorScheme
>>> FlavorMatrix.convert_to_flavor.__annotations__
{'flavor_out': snewpy.flavor.FlavorScheme | None, 'flavor_in': snewpy.flavor.FlavorScheme | None}
>>> type(FlavorScheme | None)
<class 'types.UnionType'>Similarly, all unit tests (under 3.10–3.13) on the latest commit to
|
|
@JostMigenda Hi Jost, apologies as this PR was definitely rushed on my end, without going through proper verification so long as it worked and produced agreeable results. I will convert this to a draft as I would like to ensure this commit is reliable before any review. With regards to flavor_xform, this was intrinsic to a script, and indeed not a part of the diff. |
Fix Fornax_2019 array time input, unit conversion, and Python 3.10+ import error
flavor.py: add
from __future__ import annotationsto defer evaluationof
FlavorScheme | Nonetype annotations, which caused a TypeError atimport time on Python 3.10+ due to FlavorEnumMeta.or not supporting
NoneType (Issue 1)
flavor_xform=AdiabaticMSW(mh=MassHierarchy.NORMAL) ->
flavor_xform=AdiabaticMSW(MixingParameters(MassHierarchy.NORMAL)) (Issue 2) (for converting flux to events)
ccsn_loaders.py: fix Fornax_2019._get_initial_spectra_dict to handle
array time input correctly. Previously _get_binnedspectra was called with
the full time array instead of a scalar, causing either a broadcast
ValueError or silently wrong results (all time steps mapped to the same
model index). Now finds nearest time indices upfront, uses bulk HDF5
reads per (ebin, l, m) across unique time steps, and remaps to the full
time array via j_inverse (Issue 3a)
ccsn_loaders.py: fix unit conversion in _get_initial_spectra_dict —
divide luminosity spectrum [erg/(MeVs)] by neutrino energy E to obtain
the number spectrum [1/(MeVs)] required by flux.Container (Issue 3b)