Spectra
Spectrum
A collection of spectrum functions.
Translate from/to MEGAlib’s format
- class bctools.spectra.spectrum.BandFunction(norm, lower_index, upper_index, break_energy)[source]
\(F(E) = A \begin{cases} \left(\frac{E}{1 \mathrm{keV}}\right)^{\alpha_1} \cdot e^{-E/E_{\text{break}}}, & E < E_{\text{trans}} \\ \left[ (\alpha_1-\alpha_2) \cdot \left(\frac{E_{\text{break}}}{1 \mathrm{keV}}\right) \right]^{(\alpha_1-\alpha_2)} \cdot e^{(\alpha_2-\alpha_1)} \cdot \left(\frac{E}{1 \mathrm{keV}}\right)^{\alpha_2} , & E \geq E_{\text{trans}} \end{cases}\)
\(E_{\text{trans}} = (\alpha_1 - \alpha_2) \cdot E_{\text{break}}\)
- Parameters:
norm (float) – normalization \(A\)
lower_index (float) – spectral index if \(E<\) transition_energy \(\alpha_1\)
upper_index (float) – spectral index if \(E>\) transition_energy \(\alpha_2\)
break_energy (float) – scale energy of the exponential cutoff \(E_{\text{break}}\)
- Attributes:
norm (float) – normalization \(A\)
lower_index (float) – spectral index if \(E<\) transition_energy \(\alpha_1\)
upper_index (float) – spectral index if \(E>\) transition_energy \(\alpha_2\)
break_energy (float) – scale energy of the exponential cutoff \(E_{\text{break}}\)
transition_energy (float) – transition value between the low- and high-energy ranges \(E_{\text{transition}}\)
min_energy (float) – \(F=0\) if \(E<\) min_energy
max_energy (float) – \(F=0\) if \(E>\) max_energy
- property eflux
Returns the energy flux in erg cm^-2 s^-1.
- eval(energy)[source]
Evaluate the spectrum F(E)=dN/dE (E) in keV^-1 cm^-2 s^-1.
- Parameters:
energy (iterable) – energy \(E\) values in keV.
- Returns:
dNdE \(F\) values. F = 0 outside of the min/max_energy bounds
- Return type:
array
- eval_E2dNdE(energy)[source]
Evaluate the energy spectrum E**2 * dN/dE (E) in erg cm^-2 s^-1.
- Parameters:
energy (iterable) – energy \(E\) values in keV.
- Returns:
dNdE \(F\) values. F = 0 outside of the min/max_energy bounds.
- Return type:
array
- property flux
Returns the photon flux in cm^-2 s^-1.
- integrate(bounds, func=None)[source]
Evaluate the integral between two energy bounds.
Note that the spectrum evaluates to 0 out of the overall min/max_energy bounds.
- Parameters:
bound (array) – Energy bounds in keV. Either an array with 2 elements or 2D array with 2 columns
func – function The function to integrate. If default (func=None), it is self.eval.
- Returns:
Integral photon flux between bounds in cm^-2 s^-1.
- Return type:
float or array
- normalize(flux, min_energy=None, max_energy=None)[source]
Change norm based on the total emission between min_enegy and max_energy.
- Parameters:
flux (float) – new integral flux between min_energy and max_energy in cm^-2 s^-1.
min_energy (float) – Lower integration bound in keV. Defaults to self.min_energy.
max_energy (float) – Upper integration bound in keV. Defaults to self.max_energy.
- to_megalib()[source]
Return equivalent parameters of MEGAlib’s Source.Spectrum and Source.Flux
- Returns:
Spectrum type and parameteters for Source.Spectrum (i.e. BandFunction min_energy max_energy lower_index upper_index break_energy) str: Parameter for Source.Flux
- Return type:
list of str
- property transition_energy
Energy of the exponential cutoff
- class bctools.spectra.spectrum.Comptonized(norm, index, peak_energy)[source]
\(F(E) = A \bigl(\frac{E}{1 \mathrm{keV}}\bigr)^{\alpha} \cdot e^{- E (2+\alpha)/E_{\text{peak}}}\)
\(E_{\text{cutoff}} = E_{\text{peak}} / (2+\alpha)\)
- Parameters:
norm (float) – normalization \(A\)
alpha (float) – spectral index \(\alpha\)
peak_energy (float) – peak energy before exponential cutoff \(E_{\text{peak}}\)
- Attributes:
norm (float) – normalization \(A\)
alpha (float) – spectral index \(\alpha\)
peak_energy (float) – peak energy before exponential cutoff \(E_{\text{peak}}\)
cutoff_energy (float) – scale energy of the exponential cutoff \(E_{\text{cutoff}}\)
min_energy (float) – \(F=0\) if \(E<\) min_energy
max_energy (float) – \(F=0\) if \(E>\) max_energy
- property cutoff_energy
Energy of the exponential cutoff
- property eflux
Returns the energy flux in erg cm^-2 s^-1.
- eval(energy)[source]
Evaluate the spectrum F(E)=dN/dE (E) in keV^-1 cm^-2 s^-1.
- Parameters:
energy (iterable) – energy \(E\) values in keV.
- Returns:
dNdE \(F\) values. F = 0 outside of the min/max_energy bounds
- Return type:
array
- eval_E2dNdE(energy)[source]
Evaluate the energy spectrum E**2 * dN/dE (E) in erg cm^-2 s^-1.
- Parameters:
energy (iterable) – energy \(E\) values in keV.
- Returns:
dNdE \(F\) values. F = 0 outside of the min/max_energy bounds.
- Return type:
array
- property flux
Returns the photon flux in cm^-2 s^-1.
- integrate(bounds, func=None)[source]
Evaluate the integral between two energy bounds.
Note that the spectrum evaluates to 0 out of the overall min/max_energy bounds.
- Parameters:
bound (array) – Energy bounds in keV. Either an array with 2 elements or 2D array with 2 columns
func – function The function to integrate. If default (func=None), it is self.eval.
- Returns:
Integral photon flux between bounds in cm^-2 s^-1.
- Return type:
float or array
- normalize(flux, min_energy=None, max_energy=None)[source]
Change norm based on the total emission between min_enegy and max_energy.
- Parameters:
flux (float) – new integral flux between min_energy and max_energy in cm^-2 s^-1.
min_energy (float) – Lower integration bound in keV. Defaults to self.min_energy.
max_energy (float) – Upper integration bound in keV. Defaults to self.max_energy.
- class bctools.spectra.spectrum.Mono(flux, energy)[source]
Mono energetic beam
- Parameters:
flux (float) – Flux
energy (float) – Energy
- eval(energy)[source]
Evaluate the spectrum F(E)
- Parameters:
energy (iterable) – energy \(E\) values
- Returns:
flux \(F\) values
- Return type:
array
- class bctools.spectra.spectrum.PowerLaw(norm, index)[source]
\(F(E) = A \bigl(\frac{E}{1 \mathrm{keV}}\bigr)^{-\alpha}\)
- Parameters:
norm (float) – normalization \(A\)
index (float) – spectral index \(\alpha\)
- Attributes:
norm (float) – normalization \(A\)
index (float) – spectral index \(\alpha\)
min_energy (float) – \(F=0\) if \(E<\) min_energy
max_energy (float) – \(F=0\) if \(E>\) max_energy
- eval(energy)[source]
Evaluate the spectrum F(E)
- Parameters:
energy (iterable) – energy \(E\) values
- Returns:
flux \(F\) values. F = 0 outside of the min/max_energy bounds
- Return type:
array
- property flux
Total integrated flux between energy bounds
- integrate(bounds)[source]
Evaluate the integral between two energy bounds.
Note that the spectrum evaluates to 0 out of the overall min/max_energy bounds.
- Parameters:
bound (array) – Energy bounds. Either an array with 2 elements or 2D array with 2 columns
- Returns:
Integral flux between bounds
- Return type:
float or array
- normalize(flux, min_energy=None, max_energy=None)[source]
Change norm based on the total emission between min_enegy and max_energy
- Parameters:
flux (float) – new integral flux between min_energy and max_energy
min_energy (float) – Lower integration bound. Defaults to self.min_energy
max_energy (float) – Upper integration bound. Defaults to self.max_energy
- class bctools.spectra.spectrum.Spectrum[source]
Abstract class representing an spectral model
Child classes need to implement eval(), integrate(), _from_megalib(), to_megalib(), __str__(), __eq__() and normalize() and property flux
- abstract eval(energy)[source]
Evaluate the spectrum F(E)
- Parameters:
energy (iterable) – energy \(E\) values
- Returns:
flux \(F\) values
- Return type:
array
- abstract property flux
Total integrated flux between energy bounds
- classmethod from_megalib(params, flux)[source]
Get object from MEGAlibs format.
- Parameters:
params (list) – List of paramters. See str_megalib_format
flux (str) – Flux value (In MEGAlib the spectrum refers only to the shape)
- classmethod from_name(name, *args, **kwargs)[source]
Instantiate a spectrum from the subclass name. e.g.:
Spectrum.from_name('PowerLaw', *args, **kwargs) <==> PowerLaw(*args, **kwargs)
- abstract integrate(bounds)[source]
Evaluate the integral between two energy bounds
- Parameters:
bound (array) – Energy bounds. Either an array with 2 elements or 2D array with 2 columns
- Returns:
Integral flux between bounds
- Return type:
float or array
- abstract normalize(flux, *args, **kwargs)[source]
Change normalization parameters based on an integrated flux.