Magnetic field of Galaxy clusters with Gaussian Turbulence

This module implements a divergence-free homogeneous and isotropic Gaussian turbulent magnetic field with zero mean and variance \(\mathcal{B}^2\) as described in detail in [Meyer2014] and also used, e.g., in [Ajello2016]. The power spectrum of the turbulence follows a power law in terms of wave numbers \(k\),

\[M(k) \propto k^q\]

between \(k_L \leqslant k \leqslant k_H\) and zero otherwise.

The Fourier transform of the correlation function of the transversal B-field components is

\[\tilde\epsilon_\perp(k) = \frac{\pi\mathcal{B}^2}{4} F_q(k ; k_L, k_H),\]

where the function \(F_q(k; k_L,k_H)\) is defined in the appendix of [Meyer2014].

A new single realization of the magnetic field along the line of sight is computed with gammaALPs.bfields.gauss.Bgaussian.Bgaus and the transversal component (relevant to photon-ALP mixing) for potentially many realizations is calculated with gammaALPs.bfields.gauss.Bgaussian.new_Bn(). There are also two convenience functions to calculate the spatial correlation and the the rotation measure induced by the field (provided that an electron density is provided as well).

Reference / API

class gammaALPs.bfields.gauss.Bgaussian(B, kH, kL, q, **kwargs)[source]

Bases: object

Class to calculate a magnetic field with gaussian turbulence and power-law spectrum

property B
Bgaus(z, longitudinal=False)[source]

Calculate the magnetic field for a gaussian turbulence field along the line of sight direction, denoted by z.

Parameters:
  • z (array-like) – m-dim array with distance traversed in magnetic field in kpc

  • longitudinal (bool) – if True, calculate the longitudinal B field component and the transversal component otherwise. Default: False

Returns:

B – m-dim array with values of transversal field

Return type:

numpy.ndarray

Fq(x)[source]

Calculate the \(F_q\) function for given \(x, k_L\), and \(k_H\) for the transversal components of the B field

Parameters:

x (array-like) – Ratio between k and _kH

Returns:

F – n-dim array with \(F_q(x)\) values

Return type:

array-like

Fq_longitudinal(x)[source]

Calculate the \(F_q\) function for given \(x, k_L\), and \(k_H\) for the longitudinal component of the B field

Parameters:

x (array-like) – Ratio between k and _kH

Returns:

F – n-dim array with \(F_q(x)\) values

Return type:

array-like

Fq_old(x)[source]

Calculate the \(F_q\) function for given \(x, k_L\), and \(k_H\) Deprecated version.

Parameters:

x (array-like) – Ratio between k and _kH

Returns:

F – n-dim array with \(F_q(x)\) values

Return type:

array-like

__init__(B, kH, kL, q, **kwargs)[source]

Initialize gaussian turbulence B field spectrum. Defaults assume values typical for a galaxy cluster.

Parameters:
  • B (float) – rms B field strength, energy is \(B^2 / 4 \pi\) (default = 1 muG)

  • kH (float) – upper wave number cutoff, should be at at least > 1. / osc. wavelength (default = 1 / (1 kpc))

  • kL (float) – lower wave number cutoff, should be of same size as the system (default = 1 / (100 kpc))

  • q (float) – power-law turbulence spectrum (default: q = 11/3 is Kolmogorov type spectrum)

  • kMin (float) – minimum wave number in 1. / kpc, defualt 1e-3 * kL (the k interval runs from kMin to kH)

  • dkType (string) – either linear, log, or random. Determine the spacing of the dk intervals

  • dkSteps (int) – number of dkSteps. For log spacing, number of steps per decade / number of decades ~ 10 should be chosen.

  • seed (int or None) – random seed

property kH
property kL
new_Bn(z, Bscale=None, nsim=1)[source]

Calculate two components of a turbulent magnetic field and the angle between the the two.

Parameters:
  • z (array-like) – m-dim array with distance traversed in magnetic field

  • Bscale (array-like or float or None) – if not None, float or m-dim array with scaling factor for magnetic field along distance travelled

Returns:

B, Psin – Two squeezed (nsim,m)-dim array with absolute value of transversal field, as well as angles between total transversal magnetic field and the \(y\) direction.

Return type:

tuple with ndarray

new_random_numbers()[source]

Generate new random numbers for Un,Vn, and kn if knType == random

normalization_B()[source]

Calculate the normalization constant \(A\) for the turbulent magnetic field. See Eq. A15 in [Meyer2014]

Return type:

B-field normalization as a scalar, depending on turbulence index \(q\)

property q
rotation_measure(z, n_el, Bscale=None, nsim=1)[source]

Calculate the rotation measure of a random Gaussian field.

Parameters:
  • z (array-like) – m-dim array with distance traversed in magnetic field, in kpc

  • n_el (array-like) – m-dim array with electron density in cm^-3

  • nsim (int) – number of B-field simulations

  • Bscale (array-like or None) – if given, this array is multiplied with the B field for an additional scaling depending on r, e.g., (n_el(r) / n_el(0))^eta

Returns:

rm – Rotation measure for each simulated B field. Returned as array if nsim > 1

Return type:

ndarray or float

spatial_correlation(z, steps=10000, longitudinal=False)[source]

Calculate the spatial correlation of the turbulent field

Parameters:
  • z (array-like) – distance traversed in magnetic field

  • steps (int) – number of integration steps

  • longitudinal (bool) – if True, calculate the longitudinal B field component and the transversal component otherwise. Default: False

Returns:

corr – array with spatial correlation

Return type:

array-like

gammaALPs.bfields.gauss.rand(d0, d1, ..., dn)

Random values in a given shape.

Note

This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Parameters:
  • d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • ... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Returns:

out – Random values.

Return type:

ndarray, shape (d0, d1, ..., dn)

See also

random

Examples

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
gammaALPs.bfields.gauss.randint(low, high=None, size=None, dtype=int)

Return random integers from low (inclusive) to high (exclusive).

Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).

Note

New code should use the ~numpy.random.Generator.integers method of a ~numpy.random.Generator instance instead; please see the Quick Start.

Parameters:
  • low (int or array-like of ints) – Lowest (signed) integers to be drawn from the distribution (unless high=None, in which case this parameter is one above the highest such integer).

  • high (int or array-like of ints, optional) – If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None). If array-like, must contain integer values

  • size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

  • dtype (dtype, optional) –

    Desired dtype of the result. Byteorder must be native. The default value is int.

    New in version 1.11.0.

Returns:

outsize-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.

Return type:

int or ndarray of ints

See also

random_integers

similar to randint, only for the closed interval [low, high], and 1 is the lowest value if high is omitted.

random.Generator.integers

which should be used for new code.

Examples

>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Generate a 2 x 4 array of ints between 0 and 4, inclusive:

>>> np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1], # random
       [3, 2, 2, 0]])

Generate a 1 x 3 array with 3 different upper bounds

>>> np.random.randint(1, [3, 5, 10])
array([2, 2, 9]) # random

Generate a 1 by 3 array with 3 different lower bounds

>>> np.random.randint([1, 5, 7], 10)
array([9, 8, 7]) # random

Generate a 2 by 4 array using broadcasting with dtype of uint8

>>> np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
array([[ 8,  6,  9,  7], # random
       [ 1, 16,  9, 12]], dtype=uint8)