fgspectra package¶
Submodules¶
fgspectra.cross module¶
Models of cross-spectra
This module draws inspiration from FGBuster (Davide Poletti and Josquin Errard) and BeFoRe (David Alonso and Ben Thorne).
Bases:
fgspectra.cross.CorrelatedFactorizedCrossSpectrum
Correlated power law and modified black body, both with power law amplitude
Bases:
fgspectra.cross.FactorizedCrossSpectrum
Factorized cross-spectrum of correlated components
Cross-spectrum of multiple correlated components for which the scaling in frequency and in multipoles are factorizable.
\[xC_\ell^{\nu_i\ \nu_j} = \sum_{kn} f^k(\nu_j) f^n(\nu_i) C^{kn}_\ell\]where \(k\) and \(n\) are component indices.
- Parameters
sed (callable) – \(f(\nu)\). It returns an array with shape
(comp, ..., freq)
. It can befgspectra.frequency.SED
.cl_args (callable) – \(C_\ell\). It returns an array with shape
(..., comp, comp, ell)
. It can, for example, any of the models infgspectra.power
.
Note
The two (optional) sets of extra dimensions
...
must be broadcast-compatible.
Bases:
fgspectra.cross.CorrelatedFactorizedCrossSpectrum
Correlated Power law in both fequency and multipoles
See
fgspectra.frequency.PowerLaw
for the frequency dependence andfgspectra.power.PowerLaw
for the ell-dependence.
-
class
fgspectra.cross.
FactorizedCrossSpectrum
(sed, cl, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Factorized cross-spectrum
Cross-spectrum of one component for which the scaling in frequency and in multipoles are factorizable
\[xC_{\ell}^{(ij)} = f(\nu_j) f(\nu_i) C_{\ell}\]- Parameters
sed (callable) – \(f(\nu)\). It returns an array with shape
(..., freq)
. It can befgspectra.frequency.SED
.cl_args (callable) – \(C_\ell\). It returns an array with shape
(..., ell)
. It can befgspectra.power.PowerSpectrum
Note
The two (optional) sets of extra dimensions
...
must be broadcast-compatible.-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
class
fgspectra.cross.
PowerLaw
(**kwargs)[source]¶ Bases:
fgspectra.cross.FactorizedCrossSpectrum
Single Power law in both fequency and multipoles
See
fgspectra.frequency.PowerLaw
for the frequency dependence andfgspectra.power.PowerLaw
for the ell-dependence.
-
class
fgspectra.cross.
Sum
(*crosses, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Sum the cross-spectra of uncorrelated components
-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
eval
(kwseq=None)[source]¶ Compute the sum of the cross-spectra
- *kwseq:
The length of
kwseq
has to be equal to the number of cross-spectra summed.kwseq[i]
is a dictionary containing the keyword arguments of thei
-th cross-spectrum.
-
eval_terms
(kwseq=None)[source]¶ Compute the sum of the cross-spectra
- *kwseq:
The length of
kwseq
has to be equal to the number of cross-spectra summed.kwseq[i]
is a dictionary containing the keyword arguments of thei
-th cross-spectrum.
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
property
fgspectra.frequency module¶
Frequency-dependent foreground components.
This module implements the frequency-dependent component of common foreground contaminants.
This package draws inspiration from FGBuster (Davide Poletti and Josquin Errard) and BeFoRe (David Alonso and Ben Thorne).
-
class
fgspectra.frequency.
CIB
(**kwargs)[source]¶ Bases:
fgspectra.frequency.ModifiedBlackBody
Alias of
ModifiedBlackBOdy
-
class
fgspectra.frequency.
ConstantSED
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Frequency-independent component.
-
class
fgspectra.frequency.
FreeFree
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Free-free
\[f(\nu) = EM * ( 1 + log( 1 + (\nu_{ff} / \nu)^{3/\pi} ) )\]\[\nu_{ff} = 255.33e9 * (Te / 1000)^{3/2}\]-
eval
(nu=None, EM=None, Te=None)[source]¶ Evaluation of the SED
- Parameters
- Returns
sed – If nu is an array, the shape is
(..., freq)
. If nu is scalar, the shape is(..., 1)
. Note that the last dimension is guaranteed to be the frequency.- Return type
ndarray
Note
The extra dimensions
...
in the output are the broadcast of the...
in the input (which are required to be broadcast-compatible).Examples
Free-free emission in temperature.
-
-
class
fgspectra.frequency.
Join
(*seds, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Join several SED models together
-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
eval
(kwseq=None)[source]¶ Compute the SED with the given frequency and parameters.
- *kwseq
The length of
kwseq
has to be equal to the number of SEDs joined.kwseq[i]
is a dictionary containing the keyword arguments of thei
-th SED.
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
property
-
class
fgspectra.frequency.
ModifiedBlackBody
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Modified black body in K_RJ
\[f(\nu) = (\nu / \nu_0)^{\beta + 1} / (e^x - 1)\]where \(x = h \nu / k_B T_d\)
-
class
fgspectra.frequency.
PowerLaw
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Power Law
\[f(\nu) = (\nu / \nu_0)^{\beta}\]-
eval
(nu=None, beta=None, nu_0=None)[source]¶ Evaluation of the SED
- Parameters
- Returns
sed – If nu is an array, the shape is
(..., freq)
. If nu is scalar, the shape is(..., 1)
. Note that the last dimension is guaranteed to be the frequency.- Return type
ndarray
Note
The extra dimensions
...
in the output are the broadcast of the...
in the input (which are required to be broadcast-compatible).Examples
T, E and B synchrotron SEDs with the same reference frequency but different spectral indices. beta is an array with shape
(3)
, nu_0 is a scalar.SEDs of synchrotron and dust (approximated as power law). Both beta and nu_0 are arrays with shape
(2)
-
-
class
fgspectra.frequency.
Synchrotron
(**kwargs)[source]¶ Bases:
fgspectra.frequency.PowerLaw
Alias of
PowerLaw
-
class
fgspectra.frequency.
ThermalSZ
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Thermal Sunyaev-Zel’dovich in K_CMB
This class implements the
\[f(\nu) = x \coth(x/2) - 4\]where \(x = h \nu / k_B T_CMB\)
fgspectra.model module¶
-
class
fgspectra.model.
Model
(**kwargs)[source]¶ Bases:
abc.ABC
Abstract class for model definition
A model is a class that has one purpose: evaluating the model. What evaluation means is defined by the eval method that any child class has to override.
If the eval method of a hypotetical
Child
class calls the eval method of other Model`s, it is likely that ``Child` has also to override set_defaults, defaults and _get_repr-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
prepare_for_arrays
(template_kwargs)[source]¶ Preapre for using arrays
reference_kwargs are necessary to define the shape you expect for each argument, which are necessary to convert from array to nested dictionaries of arguments. They are required to have at least all the arguments for which the default is None.
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
property
fgspectra.power module¶
Power spectrum
This module implements the ell-dependent component of common foreground contaminants.
This module draws inspiration from FGBuster (Davide Poletti and Josquin Errard) and BeFoRe (David Alonso and Ben Thorne).
Bases:
fgspectra.power.PowerLaw
As PowerLaw, but requires only the diagonal of the component-component dimensions and the correlation coefficient between TWO PL
- Parameters
- Returns
cl – The dimensions are
(..., comp1, comp2, ell)
. The leading dimensions are the hypothetic dimensions of alpha and amp.- Return type
ndarray
-
class
fgspectra.power.
PowerLaw
(**kwargs)[source]¶ Bases:
fgspectra.model.Model
Power law
\[C_\ell = (\ell / \ell_0)^\alpha\]
-
class
fgspectra.power.
PowerSpectraAndCorrelation
(*power_spectra, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Components’ spectra and their correlation
Spectrum of correlated components defined by the spectrum of each component and their correlation
- Parameters
*power_spectra (series of PowerSpectrum) – The series has lenght \(N (N + 1) / 2\), where \(N\) is the number of components. They specify the upper (or lower) triangle of the component-component cross spectra, which is symmetric. The series stores a PowerSpectrum for each component-component combination. The main diagonal (i.e. the autospectra) goes first, the second diagonal of the correlation matrix follows, then the third, etc. The ordering is similar to the one returned by healpy.anafast.
-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
eval
(kwseq=None)[source]¶ Compute the SED with the given frequency and parameters.
- Parameters
*argss – The length of argss has to be equal to the number of SEDs joined.
argss[i]
is the argument list of thei
-th SED.
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
class
fgspectra.power.
PowerSpectraAndCovariance
(*power_spectra, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Components’ spectra and their covariance
Spectrum of correlated components defined by the spectrum of each component and their correlation
- Parameters
*power_spectra (series of PowerSpectrum) – The series has length \(N (N + 1) / 2\), where \(N\) is the number of components. They specify the upper (or lower) triangle of the component-component cross spectra, which is symmetric. The series stores a PowerSpectrum for each component-component combination. The main diagonal (i.e. the autospectra) goes first, the second diagonal of the covariance matrix follows, then the third, etc. The ordering is similar to the one returned by healpy.anafast.
-
property
defaults
¶ The current defaults
The current defaults as you would pass them to the eval method.
In particular, since all the arguments have to be keyword arguments, it is a nested set of dictionaries with a key for each argument of the eval methods in the model.
>>> model.eval() == model.eval(**model_child.defaults) True
-
eval
(kwseq=None)[source]¶ Compute the Cl with the given frequency and parameters.
- kwseq
The length of argss has to be equal to the number of SEDs joined.
kwseq[i]
is the argument list of thei
-th SED.
-
set_defaults
(**kwargs)[source]¶ Change the defaults of the evaluation
Call
set_defaults
with the same arguments (or a subset) ofeval
(or__call__
). This will change the default value of those arguments ineval
. If kwargs has keys that are not arguments of eval, these keys are ignored.Examples
>>> class PrintABC(Model): ... def eval(self, a=1, b=2, c=3): ... print(a, b, c) ... >>> print_abc = PrintABC() >>> print_abc.eval() 1 2 3 >>> print_ab10c = PrintABC() >>> print_ab10c.set_defaults(b=10) >>> print_ab10c.eval() # The default of b has changed 1 10 3 >>> print_abc.eval() # Without affecting other instances 1 2 3
-
class
fgspectra.power.
PowerSpectrumFromFile
(filenames, **kwargs)[source]¶ Bases:
fgspectra.model.Model
Power spectrum loaded from file(s)
- Parameters
filenames (array_like of strings) – File(s) to load. It can be a string or any (nested) sequence of strings
Examples
>>> ell = range(5)
Power spectrum of a single file
>>> my_file = 'cl.dat' >>> ps = PowerSpectrumFromFile(my_file) >>> ps(ell).shape (5) >>> ps = PowerSpectrumFromFile([my_file]) # List >>> ps(ell).shape (1, 5)
Two correlated components
>>> my_files = [['cl_comp1.dat', 'cl_comp1xcomp2.dat'], ... ['cl_comp1xcomp2.dat', 'cl_comp2.dat']] >>> ps = PowerSpectrumFromFile(my_files) >>> ps(ell).shape (2, 2, 5)
-
class
fgspectra.power.
SZxCIB_Addison2012
(**kwargs)[source]¶ Bases:
fgspectra.power.PowerSpectraAndCovariance
PowerSpectrum for SZxCIB (Dunkley et al. 2013).
-
class
fgspectra.power.
SZxCIB_Reichardt2012
(**kwargs)[source]¶ Bases:
fgspectra.power.PowerSpectraAndCorrelation
PowerSpectrum for SZxCIB (Dunkley et al. 2013).
-
class
fgspectra.power.
kSZ_bat
[source]¶ Bases:
fgspectra.power.PowerSpectrumFromFile
PowerSpectrum for Kinematic Sunyaev-Zel’dovich (Dunkley et al. 2013).
-
class
fgspectra.power.
tSZ_150_bat
[source]¶ Bases:
fgspectra.power.PowerSpectrumFromFile
PowerSpectrum for Thermal Sunyaev-Zel’dovich (Dunkley et al. 2013).