gtsimulation.magnetic_field.galaxy#

class gtsimulation.magnetic_field.galaxy.JF12mod(use_turb=True, turbulence_file=None)[source]#

Modified Jansson–Farrar 2012 model of the Galactic magnetic field.

This class implements the regular (disk, toroidal halo, X‑field) and optional turbulent (striated and isotropic) components of the Milky Way’s magnetic field. The isotropic turbulent part is based on a synthetic Kolmogorov-like spectrum generated on a grid.

Parameters:
use_turbbool, optional

If True, include turbulent magnetic field components. Default is True.

turbulence_filestr or path-like, optional

Path to a pre-computed turbulent-field .mat file. When omitted, the model looks for the default realization in the Data directory next to this module.

Notes

The regular field follows the prescription of Jansson & Farrar (2012) with modifications described in [1], [2]. The model parameters (e.g., b_disk, r_arms, pitch, B_n, bX, etc.) are hard‑coded to the best‑fit values given in publications. For a detailed description of each parameter, please refer to the original publications. The realization of an isotropic turbulent field follows from [3].

The regular field consists of:
  • a spiral disk field with pitch angle 11.5°,

  • a toroidal halo field (north/south asymmetry),

  • an X‑shaped halo field.

The turbulent field (if enabled) includes:
  • an anisotropic (striated) component with parameter beta_str,

  • an isotropic component combining a thin disk and a halo term.

The turbulent-field realization is not distributed with GTsimulation due to its size. It can be generated with python -m gtsimulation.magnetic_field.galaxy.Scripts.generate_jf12_turbulence. The script writes the file to the current working directory; move it to the model’s Data directory or pass its path through turbulence_file. Alternatively, construct the model with use_turb=False.

Coordinates are expected in kiloparsecs (kpc). The returned field components are in nanotesla (nT).

References

[1]

Jansson, Ronnie, and Glennys R. Farrar. “A new model of the galactic magnetic field.” The Astrophysical Journal 757.1 (2012): 14.

[2]

Jansson, Ronnie, and Glennys R. Farrar. “The galactic magnetic field.” The Astrophysical Journal Letters 761.1 (2012): L11.

[3]

Beck, Marcus C., et al. “New constraints on modelling the random magnetic field of the MW.” Journal of Cosmology and Astroparticle Physics 2016.05 (2016): 056-056.

Examples

>>> from gtsimulation.magnetic_field.galaxy import JF12mod
>>> model = JF12mod(use_turb=False)
>>> Bx, By, Bz = model.calc_field(x=-8.5, y=0.0, z=0.0)  # Sun's position
>>> print(f"B = ({Bx:.3f}, {By:.3f}, {Bz:.3f}) nT")
calc_field(x, y, z)[source]#

Compute the magnetic field vector at a given Galactic position.

Parameters:
xfloat

Galactic X‑coordinate (kpc).

yfloat

Galactic Y‑coordinate (kpc).

zfloat

Galactic Z‑coordinate (kpc).

Returns:
tuple of (float, float, float)

The three components of the magnetic field \((B_x, B_y, B_z)\) in nanotesla (nT).

Notes

If use_turb was set to False at construction, the turbulent contributions are zero; otherwise they are interpolated from the pre‑computed Gaussian random field.

The position is expected to be within the Galactic disk (roughly \(r < 20\) kpc and \(|z| < 20\) kpc); outside this region the field strength equal to zero.

to_meters = 3.08567758149e+19#
update_state(new_date)[source]#

Update the model for a new date.

Models that do not depend on the date implement this method as a no-op.

Parameters:
new_datedatetime.datetime

New date.

class gtsimulation.magnetic_field.galaxy.UF23(model_type: UF23ModelType | str = UF23ModelType.base, use_turb=True)[source]#

Unger–Farrar 2023 model of the Galactic magnetic field.

This class implements a comprehensive model of the Milky Way’s magnetic field, including a logarithmic spiral disk, a toroidal halo, and a poloidal (X‑shaped) halo component. Several variants of the model are available, corresponding to different astrophysical constraints or physical assumptions.

Parameters:
model_typeUF23ModelType or str, optional

The specific variant of the UF23 model to use. Can be given as an enum member (e.g., UF23ModelType.base) or as its name (e.g., "base"). The following strings are accepted:

  • "base" : baseline best‑fit model

  • "expX" : exponential suppression of the poloidal field

  • "neCL" : no extra‑galactic cosmic‑ray constraints

  • "nebCor" : nebula‑corrected model

  • "cre10" : model with CR electron constraints at 10 GeV

  • "synCG" : model fitted to synchrotron data and CMB foregrounds

The variant "twistX" (twisted poloidal field) is listed in the original work but is not yet implemented. Default is UF23ModelType.base.

use_turbbool, optional

If True, turbulent field components are enabled. Currently not implemented – the parameter is accepted but has no effect. Default is True.

Notes

The magnetic field model is implemented in accordance with [1]; all parameters for each variant are hard‑coded to the best‑fit values given in Table 1 of the publication.

The regular field consists of:
  • a logarithmic spiral disk field,

  • a toroidal halo field (north/south asymmetric),

  • a poloidal (X‑shaped) halo field.

Coordinates are expected in kiloparsecs (kpc). The returned field components are in nanotesla (nT).

References

[1]

Unger, Michael, and Glennys R. Farrar. “The coherent magnetic field of the Milky Way.” The Astrophysical Journal 970.1 (2024): 95.

Examples

>>> from gtsimulation.magnetic_field.galaxy import UF23
>>> model = UF23(model_type="base", use_turb=False)
>>> Bx, By, Bz = model.calc_field(x=-8.2, y=0.0, z=0.0)  # Sun's position
>>> print(f"B = ({Bx:.3f}, {By:.3f}, {Bz:.3f}) nT")
calc_field(x, y, z)[source]#

Compute the magnetic field vector at a given Galactic position.

Parameters:
xfloat

Galactic X‑coordinate (kpc).

yfloat

Galactic Y‑coordinate (kpc).

zfloat

Galactic Z‑coordinate (kpc).

Returns:
tuple of (float, float, float)

The three components \((B_x, B_y, B_z)\) of the magnetic field in nanotesla (nT).

Notes

The field is evaluated using the parameters of the model variant selected at instantiation. The calculation includes the disk, toroidal halo, and poloidal halo contributions. No turbulent component is added even if use_turb was set to True.

The position is expected to lie within the Galactic disk region (typically \(r < 20\) kpc and \(|z| < 10\) kpc); outside this range the field may be poorly constrained.

to_meters = 3.08567758149e+19#
update_state(new_date)[source]#

Update the model for a new date.

Models that do not depend on the date implement this method as a no-op.

Parameters:
new_datedatetime.datetime

New date.

class gtsimulation.magnetic_field.galaxy.UF23ModelType(*values)[source]#

Available UF23 magnetic field models.

base = 1#
cre10 = 6#
expX = 2#
neCL = 3#
nebCor = 5#
synCG = 7#
twistX = 4#