darkhistory.spec.spectools.discretize¶
-
darkhistory.spec.spectools.
discretize
(eng, func_dNdE, *args)¶ Discretizes a continuous function.
The function is integrated between the bin boundaries specified by eng to obtain the discretized spectrum, so that the final spectrum conserves number and energy between the bin boundaries.
Parameters: - eng : ndarray
Both the bin boundaries to integrate between and the new abscissa after discretization (bin centers).
- func_dNdE : function
A single variable function that takes in energy as an input, and then returns a dN/dE spectrum value.
- *args : optional
Additional arguments and keyword arguments to be passed to func_dNdE.
Returns: - Spectrum
The discretized spectrum. rs is set to -1, and must be set manually.
See also
Notes
Given a spectrum \(dN/dE\), represented by the function
func_dNdE
, this function calculates the following quantities at the energy values \(E_i\) specified ineng
:\[N[i] = \int_{E_i}^{E_{i+1}} \frac{dN}{dE} \, dE\]\[\epsilon[i] = \frac{1}{N[i]} \int_{E_i}^{E_{i+1}} E \frac{dN}{dE} \, dE\]We can now treat \(N[i]\) and \(\epsilon[i]\) as a list of bins with energies \(\epsilon[i]\) and number of particles \(N[i]\). This is now rebinned into the abscissa specified by
eng
usingrebin_N_arr()
, which conserves the total number.