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).

class fgspectra.cross.CorrelatedDustSynchrotron(**kwargs)[source]

Bases: fgspectra.cross.CorrelatedFactorizedCrossSpectrum

Correlated power law and modified black body, both with power law amplitude

class fgspectra.cross.CorrelatedFactorizedCrossSpectrum(sed, cl, **kwargs)[source]

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 be fgspectra.frequency.SED.

  • cl_args (callable) – \(C_\ell\). It returns an array with shape (..., comp, comp, ell). It can, for example, any of the models in fgspectra.power.

Note

The two (optional) sets of extra dimensions ... must be broadcast-compatible.

eval(sed_kwargs={}, cl_kwargs={})[source]

Compute the model at frequency and ell combinations.

Parameters
  • sed_args (list) – Arguments for which the sed is evaluated.

  • cl_args (list) – Arguments for which the cl is evaluated.

Returns

cross – Cross-spectrum. The shape is (..., freq, freq, ell).

Return type

ndarray

class fgspectra.cross.CorrelatedPowerLaw(**kwargs)[source]

Bases: fgspectra.cross.CorrelatedFactorizedCrossSpectrum

Correlated Power law in both fequency and multipoles

See fgspectra.frequency.PowerLaw for the frequency dependence and fgspectra.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 be fgspectra.frequency.SED.

  • cl_args (callable) – \(C_\ell\). It returns an array with shape (..., ell). It can be fgspectra.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
eval(sed_kwargs={}, cl_kwargs={})[source]

Compute the model at frequency and ell combinations.

Parameters
  • sed_args (list) – Arguments for which the sed is evaluated.

  • cl_args (list) – Arguments for which the cl is evaluated.

Returns

cross – Cross-spectrum. The shape is (..., freq, freq, ell).

Return type

ndarray

set_defaults(**kwargs)[source]

Change the defaults of the evaluation

Call set_defaults with the same arguments (or a subset) of eval (or __call__). This will change the default value of those arguments in eval. 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 and fgspectra.power.PowerLaw for the ell-dependence.

class fgspectra.cross.SZxCIB(**kwargs)[source]

Bases: fgspectra.cross.CorrelatedFactorizedCrossSpectrum

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 the i-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 the i-th cross-spectrum.

set_defaults(**kwargs)[source]

Change the defaults of the evaluation

Call set_defaults with the same arguments (or a subset) of eval (or __call__). This will change the default value of those arguments in eval. 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

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.

eval(nu=None, amp=1.0)[source]

Evaluation of the SED

Parameters
  • nu (float or array) – It just determines the shape of the output.

  • amp (float or array) – Amplitude (or set of amplitudes) of the constant SED.

Returns

sed – If nu is an array, the shape is amp.shape + (freq). If nu is scalar, the shape is amp.shape + (1). Note that the last dimension is guaranteed to be the frequency.

Return type

ndarray

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
  • nu (float or array) – Frequency in the same units as nu_0. If array, the shape is (freq).

  • EM (float or array) – Emission measure in cm^-6 pc (usually around 300). If array, the shape is (...).

  • Te (float or array) – Electron temperature (typically around 7000). If array, the shape is (...).

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 the i-th SED.

set_defaults(**kwargs)[source]

Change the defaults of the evaluation

Call set_defaults with the same arguments (or a subset) of eval (or __call__). This will change the default value of those arguments in eval. 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.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\)

eval(nu=None, nu_0=None, temp=None, beta=None)[source]

Evaluation of the SED

Parameters
  • nu (float or array) – Frequency in GHz.

  • beta (float or array) – Spectral index.

  • temp (float or array) – Dust temperature.

  • nu_0 (float) – Reference frequency in Hz.

Returns

sed – The last dimension is the frequency dependence. The leading dimensions are the broadcast between the hypothetic dimensions of beta and temp.

Return type

ndarray

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
  • nu (float or array) – Frequency in the same units as nu_0. If array, the shape is (freq).

  • beta (float or array) – Spectral index. If array, the shape is (...).

  • nu_0 (float or array) – Reference frequency in the same units as nu. If array, the shape is (...).

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\)

eval(nu=None, nu_0=None)[source]

Compute the SED with the given frequency and parameters.

nufloat

Frequency in GHz.

T_CMB (optional) : float

static f(nu)[source]

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

array2kwargs(x)[source]
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
abstract eval(**kwargs)[source]

Evaluation of the model

Note

The signature must contain

  • only keyword arguments (except for self)

  • no variadic argument (*args, **kwargs)

and

  • no decoration

eval_array(x)[source]
kwargs2array(kwargs)[source]

(Nested) dictionaries to float array

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) of eval (or __call__). This will change the default value of those arguments in eval. 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

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).

class fgspectra.power.CorrelatedPowerLaws(**kwargs)[source]

Bases: fgspectra.power.PowerLaw

As PowerLaw, but requires only the diagonal of the component-component dimensions and the correlation coefficient between TWO PL

eval(ell=None, alpha=None, ell_0=None, amp=None, rho=None)[source]
Parameters
  • ell (float or array) – Multipole

  • amp (array) – amplitude of the auto-spectra. Shape must be (..., 2), which means that for time being we support only two correlated components

  • alpha (float or array) – Spectral index. Shape must be broadcast-compatible with amp

  • ell_0 (float) – Reference ell

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\]
eval(ell=None, alpha=None, ell_0=None, amp=1.0)[source]
Parameters
  • ell (float or array) – Multipole

  • alpha (float or array) – Spectral index.

  • ell_0 (float) – Reference ell

  • amp (float or array) – Amplitude, shape must be compatible with alpha.

Returns

cl – The last dimension is ell. The leading dimensions are the hypothetic dimensions of alpha

Return type

ndarray

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 the i-th SED.

set_defaults(**kwargs)[source]

Change the defaults of the evaluation

Call set_defaults with the same arguments (or a subset) of eval (or __call__). This will change the default value of those arguments in eval. 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 the i-th SED.

set_defaults(**kwargs)[source]

Change the defaults of the evaluation

Call set_defaults with the same arguments (or a subset) of eval (or __call__). This will change the default value of those arguments in eval. 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)
eval(ell=None, ell_0=None, amp=1.0)[source]

Compute the power spectrum with the given ell and parameters.

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).

Module contents