snf_simulations.spec#
Functions for loading and manipulating spectra.
Module Contents#
Classes#
Class to represent an antineutrino spectrum. |
API#
- class snf_simulations.spec.Spectrum(energy: numpy.ndarray, flux: numpy.ndarray, errors: numpy.ndarray, name: str = 'Spectrum')[source]#
Class to represent an antineutrino spectrum.
- Variables:
energy – Array of energy values (keV), representing histogram bin edges.
flux – Array of antineutrino flux values (keV^-1) for each energy bin. Note for N energy bin edges there should be N-1 flux values, with each pair of adjacent energy values defining the upper and lower edges of each bin.
errors – Array of uncertainties for the flux values. Array length should be the same as flux.
name – Name of the spectrum.
- equalise(width: float = 1, min_energy: float | None = None, max_energy: float | None = None) None[source]#
Convert the spectrum to have equal bin widths.
Bins are spaced from min_energy to max_energy with the requested width.
- Parameters:
width – Target bin width (keV). Must be positive.
min_energy – Minimum energy for the new spectrum (keV). If None, uses the current minimum energy edge.
max_energy – Maximum energy for the new spectrum (keV). If None, uses the current maximum energy edge.
- classmethod from_file(filename: pathlib.Path | str) snf_simulations.spec.Spectrum[source]#
Create a Spectrum object from a CSV file written using write_csv.
- classmethod from_isotope(name: str) snf_simulations.spec.Spectrum[source]#
Create a Spectrum object from an isotope name.
- integrate(lower_energy: float | None = None, upper_energy: float | None = None) float[source]#
Integrate the spectrum over an energy range.
This provides the Spectrum-class equivalent of integrating a ROOT histogram for flux calculations.
- Parameters:
lower_energy – Lower energy bound in keV. If None, uses the minimum energy from the spectrum.
upper_energy – Upper energy bound in keV. If None, uses the maximum energy from the spectrum.
- Returns:
Integrated spectrum value over the requested range.
- sample(samples: int = 100, seed: int | None = None) numpy.ndarray[source]#
Sample the spectrum to simulate what a detector could observe.
- Parameters:
samples – Number of samples to draw from the spectrum.
seed – Random seed for reproducibility.
- Returns:
Array of sampled energies.
- write_csv(output_filename: pathlib.Path | str = '') None[source]#
Output energy and flux data to CSV file.
Output format is: energy_lower, energy_upper, flux, error for each bin, where energy_lower and energy_upper are the lower and upper edges of the energy bin (in keV), flux is the flux value for that bin (in keV^-1), and error is the uncertainty for that flux value.
- Parameters:
output_filename – The name of the output CSV file.