darkhistory.spec.spectools.rebin_N_arr¶
-
darkhistory.spec.spectools.
rebin_N_arr
(N_arr, in_eng, out_eng=None, spec_type='dNdE', log_bin_width=None)¶ Rebins an array of particle number with fixed energy.
Returns an array or a Spectrum object. The rebinning conserves both total number and total energy.
Parameters: - N_arr : ndarray
An array of number of particles in each bin.
- in_eng : ndarray
An array of the energy abscissa for each bin. The total energy in each bin i should be N_arr[i]*in_eng[i].
- out_eng : ndarray, optional
The new abscissa to bin into. If unspecified, assumed to be in_eng.
- spec_type : {‘N’, ‘dNdE’}, optional
The spectrum type to be output. Default is ‘dNdE’.
- log_bin_width : ndarray, optional
The bin width of the output abscissa.
Returns: - Spectrum
The output Spectrum with appropriate dN/dE, with abscissa out_eng.
Raises: - OverflowError
The maximum energy in out_eng cannot be smaller than any bin in self.eng.
See also
spectrum.Spectrum.rebin
Notes
The total number and total energy is conserved by assigning the number of particles N in a bin of energy eng to two adjacent bins in new_eng, with energies eng_low and eng_upp such that eng_low < eng < eng_upp. Then dN_low_dE_low = (eng_upp - eng)/(eng_upp - eng_low)*(N/(E * dlogE_low)), and dN_upp_dE_upp = (eng - eng_low)/(eng_upp - eng_low)*(N/(E*dlogE_upp)).
If a bin in in_eng is below the lowest bin in out_eng, then the total number and energy not assigned to the lowest bin are assigned to the underflow. Particles will only be assigned to the lowest bin if there is some overlap between the bin index with respect to out_eng bin centers is larger than -1.0.
If a bin in in_eng is above the highest bin in out_eng, then an OverflowError is thrown.