freegsnke.magnetic_probes module

Class to implement magnetic probes (flux loops and pick ups at the moment): - sets up probe object, containing the types and locations of the probes - methods to extract the ‘measurements’ by each probe from an equilibrium.

Copyright 2025 UKAEA, UKRI-STFC, and The Authors, as per the COPYRIGHT and README files.

This file is part of FreeGSNKE.

FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.

class freegsnke.magnetic_probes.Probes(coils_dict: dict, magnetic_probe_data: dict | None, magnetic_probe_path: str | None)[source]

Bases: object

Representation of magnetic diagnostics for a tokamak equilibrium.

This class implements synthetic magnetic probe signals, including:

  • Flux loops: measure poloidal flux ψ(R, Z)

  • Pickup coils: measure magnetic field components projected onto a probe orientation vector (B · n̂)

The signals are computed from contributions of both coil currents and plasma current distributions via precomputed Green’s functions.

floops

Flux loop definitions (positions, identifiers, etc.).

Type:

dict

pickups

Pickup coil definitions (positions, orientations, etc.).

Type:

dict

coil_names

Ordered list of coil identifiers.

Type:

list of str

coils_dict

Input coil dictionary.

Type:

dict

Notes

The class also stores multiple Green’s function caches used to compute:

  • Flux loop signals from coils and plasma

  • Pickup coil signals (Br, Bz projections)

  • Combined diagnostic outputs

These are populated during later setup routines.

Br(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the total radial magnetic field (Br) from both coils and plasma at a set of probe locations.

The total field is the sum of contributions from discrete coils and the distributed plasma current:

Br_total[j] = sum_i G_coil[i, j] * I_coil[i]
  • sum_k G_plasma[k, j] * I_plasma[k]

where:
  • i indexes coils

  • k indexes plasma grid points

  • j indexes probe locations

Green’s functions for the plasma contribution are cached per equilibrium using eq_key and computed lazily if not already available.

Parameters:
  • eq (object) – Equilibrium object containing coil and plasma current information, as well as grid definitions.

  • probe (str, optional) – Probe set at which the field is evaluated. Currently only “pickups” is implemented (default).

Returns:

br_total – Total radial magnetic field at probe locations, shape (n_probes,).

Return type:

np.ndarray

BrBz_coils(eq: object, probe: str = 'pickups') → tuple[ndarray, ndarray][source]

Compute magnetic field components (Br, Bz) produced by all coils at a set of probe locations.

The fields are obtained by contracting precomputed Green’s functions with the coil current vector:

Br[j] = sum_i G_br[i, j] * I_i Bz[j] = sum_i G_bz[i, j] * I_i

where:
  • i indexes coils

  • j indexes probe locations

  • I_i is the current in coil i

Parameters:
  • eq (object) – Equilibrium object containing the tokamak configuration.

  • probe (str, optional) – Probe set at which fields are evaluated. Currently only “pickups” is implemented (default).

Returns:

  • br_coil (np.ndarray) – Radial magnetic field at probe locations, shape (n_probes,).

  • bz_coil (np.ndarray) – Vertical magnetic field at probe locations, shape (n_probes,).

BrBz_plasma(eq: object, probe: str = 'pickups') → tuple[ndarray, ndarray][source]

Compute magnetic field components (Br, Bz) generated by plasma currents at a set of probe locations.

This function uses precomputed (or lazily generated) Green’s functions mapping plasma grid current elements to probe measurements, then contracts them with the plasma current distribution.

The field is computed as:

Br[j] = sum_i G_br[i, j] * I_i Bz[j] = sum_i G_bz[i, j] * I_i

where:
  • i indexes plasma grid points

  • j indexes probe locations

  • I_i is the plasma current at grid point i

The Green’s functions are cached per equilibrium via eq_key to avoid recomputation when the plasma grid is unchanged.

Parameters:
  • eq (object) – Equilibrium object containing plasma current and grid information.

  • probe (str, optional) – Probe set at which fields are evaluated. Currently only “pickups” is implemented (default).

Returns:

  • br_plasma (np.ndarray) – Radial magnetic field at probe locations, shape (n_probes,).

  • bz_plasma (np.ndarray) – Vertical magnetic field at probe locations, shape (n_probes,).

Btor(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the toroidal magnetic field (Btor) at probe locations.

The toroidal field is assumed to follow the vacuum scaling law:

Btor(R) = f_vac / R

where:
  • f_vac is the vacuum toroidal field function from the equilibrium

  • R is the major radius of the probe location

This approximation assumes probes are located outside the plasma, where the toroidal field is purely vacuum-like.

Parameters:
  • eq (object) – Equilibrium object providing the vacuum toroidal field profile via eq._profiles.fvac().

  • probe (str, optional) – Probe set at which the field is evaluated. Currently only “pickups” is implemented (default).

Returns:

btor – Toroidal magnetic field at probe locations, shape (n_probes,).

Return type:

np.ndarray

Bz(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the total vertical magnetic field (Bz) from both coils and plasma at a set of probe locations.

The total field is the sum of contributions from discrete coils and the distributed plasma current:

Bz_total[j] = sum_i G_coil[i, j] * I_coil[i]
  • sum_k G_plasma[k, j] * I_plasma[k]

where:
  • i indexes coils

  • k indexes plasma grid points

  • j indexes probe locations

Plasma Green’s functions are cached per equilibrium using eq_key and are computed lazily if not already available.

Parameters:
  • eq (object) – Equilibrium object containing coil and plasma current information, as well as grid definitions.

  • probe (str, optional) – Probe set at which the field is evaluated. Currently only “pickups” is implemented (default).

Returns:

bz_total – Total vertical magnetic field at probe locations, shape (n_probes,).

Return type:

np.ndarray

__init__(coils_dict: dict, magnetic_probe_data: dict | None, magnetic_probe_path: str | None) → None[source]

Set up the magnetic probes object from probe data or a pickle file.

At most one of magnetic_probe_data or magnetic_probe_path may be provided. If neither is provided, no probe geometry is initialised.

Parameters:
  • coils_dict (dict) – Dictionary describing the coils, including geometry and identifiers used for Green’s function evaluation.

  • magnetic_probe_data (dict or None) – Dictionary containing the magnetic probes data. Must include the keys “flux_loops” and “pickups”.

  • magnetic_probe_path (str or None) – Path to the pickle file containing the magnetic probe data (same structure as magnetic_probe_data).

Raises:

ValueError – If both magnetic_probe_data and magnetic_probe_path are given.

calculate_fluxloop_value(eq: object) → ndarray[source]

Compute the total flux loop signals by combining coil and plasma contributions.

This method returns the full synthetic flux loop measurement at all diagnostic locations by summing the magnetic response from coil currents and plasma current distribution.

Parameters:

eq (object) – Equilibrium object containing both coil currents and plasma current density.

Returns:

Total poloidal flux ψ at each flux loop location.

Return type:

np.ndarray

Notes

  • Coil contribution:

psi_floop_all_coils(eq) - Plasma contribution: psi_from_plasma(eq) - Assumes linear superposition of magnetic fields.

calculate_pickup_value(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the magnetic field projection (B · n) at pickup probes.

This function evaluates the total magnetic field at pickup locations and projects it onto the local probe orientation vector n.

The total pickup signal is composed of three contributions:

(B · n)_j = (B_coil · n)_j + (B_plasma · n)_j + (B_tor · n)_j

where:
  • j indexes pickup probes

  • coil and plasma terms are computed using precomputed oriented

Green’s functions - the toroidal field contribution is projected via the pickup orientation component in the toroidal direction

Parameters:
  • eq (object) – Equilibrium object containing coil currents, plasma currents, and magnetic field profiles.

  • probe (str, optional) – Probe set at which the signal is evaluated. Currently only “pickups” is implemented (default).

Returns:

signal – Scalar pickup signal (B · n) at each probe location, shape (n_probes,).

Return type:

np.ndarray

create_eq_key(eq: object) → tuple[float, float, float, float, int, int][source]

Generate a hashable identifier for an equilibrium grid configuration.

The key uniquely encodes the spatial domain and resolution of the equilibrium, and is used to cache and retrieve precomputed Green’s functions associated with a specific grid.

Parameters:

eq (object) – Equilibrium object containing grid metadata (domain bounds and discretisation).

Returns:

A hashable key of the form: (R_min, R_max, Z_min, Z_max, nx, ny)

Return type:

tuple

Notes

  • nx and ny are inferred from eq.R_1D and eq.Z_1D.

  • This key assumes that Green’s functions are valid only when both

spatial bounds and resolution match exactly. - Small floating-point differences in bounds will produce distinct keys.

create_green_psi_plasma(eq: object, probe: str = 'floops') → ndarray[source]

Compute the Green’s function mapping plasma current density to probe measurements of poloidal flux ψ.

This constructs the response of each diagnostic probe to unit plasma current sources distributed over the equilibrium grid (restricted to the limiter-allowed region).

Parameters:
  • eq (object) – Equilibrium object containing the plasma current grid and limiter mapping.

  • probe (str, optional) – Diagnostic type. Currently only flux loops (“floops”, the default) are supported.

Returns:

Green’s function array mapping plasma current elements to flux loop measurements. Shape is typically (n_plasma_cells, n_probes).

Return type:

np.ndarray

Notes

  • Plasma source points are taken from:

eq.limiter_handler.plasma_pts - Probe positions are taken from self.floop_pos. - The returned object represents a linear operator for:

ψ_probe = G_plasma → probe · I_plasma

  • Only in-limiter plasma points are included in the computation.

create_greens_B_oriented_coils(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the directional Green’s function for coils projected onto probe orientations.

This function evaluates the magnetic field Green’s functions (Br, Bz) from all coils and projects them onto the local orientation of each probe. This yields the component of the magnetic field aligned with the probe direction.

Mathematically, for each coil i and probe j:

G_oriented[i, j] = Br[i, j] * or_R[j] + Bz[i, j] * or_Z[j]

where (or_R, or_Z) defines the unit orientation vector of the probe in (R, Z).

Parameters:
  • eq (object) – Equilibrium object containing the tokamak configuration.

  • probe (str, optional) – Probe set at which the field is evaluated. Currently only “pickups” is implemented (default).

Returns:

prod – Oriented Green’s function matrix of shape (n_coils, n_probes), representing the projection of (Br, Bz) onto probe orientations.

Return type:

np.ndarray

create_greens_B_oriented_plasma(eq: object, probe: str = 'pickups') → ndarray[source]

Compute the oriented Green’s function for plasma current contributions projected onto probe directions.

This function first computes the plasma-to-probe Green’s functions for the magnetic field components (Br, Bz), and then projects them onto the local orientation of each probe.

The resulting kernel represents the magnetic field component aligned with the probe orientation:

G_oriented[i, j] = Br[i, j] * or_R[j] + Bz[i, j] * or_Z[j]

where:
  • i indexes plasma grid points

  • j indexes probe locations

  • (or_R, or_Z) is the unit orientation vector at each probe

Parameters:
  • eq (object) – Equilibrium object containing plasma grid information.

  • probe (str, optional) – Not used; the pickup probes are always evaluated.

Returns:

prod – Oriented Green’s function matrix mapping plasma currents to field components aligned with probe orientation.

Return type:

np.ndarray

create_greens_BrBz_plasma(eq: object, probe: str = 'pickups') → tuple[ndarray, ndarray][source]

Compute Green’s functions for magnetic field components (Br, Bz) produced by plasma current elements and evaluated at probe locations.

This constructs the plasma-to-probe coupling matrices by evaluating the Biot–Savart kernel between discrete plasma grid points and probes.

The resulting Green’s functions map plasma current density (at grid points) to magnetic field at probes:

Br[j] = sum_i G_br[i, j] * J_i Bz[j] = sum_i G_bz[i, j] * J_i

where:
  • i indexes plasma grid / limiter-handler points

  • j indexes probe locations

  • J_i represents plasma current contribution at grid point i

Parameters:
  • eq (object) – Equilibrium object containing: - plasma grid points in eq.limiter_handler.plasma_pts

  • probe (str, optional) – Probe set where fields are evaluated. Currently only “pickups” is implemented (default).

Returns:

  • greens_br (np.ndarray) – Green’s function for radial field component Br mapping plasma grid points to probes.

  • greens_bz (np.ndarray) – Green’s function for vertical field component Bz mapping plasma grid points to probes.

create_greens_BrBz_single_coil(eq: object, coil_key: str, probe: str = 'pickups') → tuple[ndarray, ndarray][source]

Compute Green’s functions for the magnetic field (Br, Bz) from a single coil, evaluated at a set of probe locations.

This function: - Evaluates the radial (Br) and vertical (Bz) magnetic field contributions from all filaments in the specified coil. - Computes these contributions at the chosen probe positions (default: pickup coils). - Returns the Green’s functions (field per unit coil current) for Br and Bz at the probe locations.

Parameters:
  • eq (object) – Equilibrium object containing the tokamak configuration.

  • coil_key (str) – Key identifying the coil within eq.tokamak.

  • probe (str, optional) – Location set where the field is evaluated. Currently only “pickups” is implemented (default).

Returns:

  • greens_br_coil (np.ndarray) – Green’s function for Br at the probe locations, shape (n_probes,).

  • greens_bz_coil (np.ndarray) – Green’s function for Bz at the probe locations, shape (n_probes,).

create_greens_psi_all_coils(eq: object, probe: str = 'floops') → ndarray[source]

Compute the Green’s function matrix relating all coils to all probe locations for poloidal flux measurements.

This builds a full response matrix where each entry represents the contribution of a unit current in a coil to the flux measured at a specific diagnostic probe.

Parameters:
  • eq (object) – Equilibrium object containing coil geometry and Green’s function evaluation methods.

  • probe (str, optional) – Type of diagnostic probe. Currently only flux loops (“floops”, the default) are supported.

Returns:

2D array of shape (n_coils, n_probes), where entry [i, j] gives the poloidal flux ψ at probe j due to a unit current in coil i.

Return type:

np.ndarray

Notes

  • Each row corresponds to a coil in self.coils_dict.

  • Each column corresponds to a flux loop in self.floop_pos.

  • The matrix assumes linear superposition of coil contributions.

  • Computation is performed via repeated calls to

create_greens_psi_single_coil.

create_greens_psi_single_coil(eq: object, coil_key: str, probe: str = 'floops') → ndarray[source]

Compute the Green’s function contribution of a single coil to probe signals.

This method evaluates the poloidal flux response ψ at all probe locations due to a unit current in a specified coil.

Parameters:
  • eq (object) – Equilibrium object containing the tokamak model and coil definitions.

  • coil_key (str) – Identifier of the coil in eq.tokamak for which the Green’s function is computed.

  • probe (str, optional) – Type of diagnostic probe to evaluate. Currently only flux loops (“floops”, the default) are supported.

Returns:

Array of ψ values at each probe location due to a unit current in the specified coil.

Return type:

np.ndarray

Notes

  • Probe positions are taken from self.floop_pos when probe=”floops”.

  • The computation is delegated to:

eq.tokamak[coil_key].controlPsi(R, Z) - The result corresponds to a linear response (unit current assumption).

get_coil_currents(eq: object) → ndarray[source]

Extract coil current values from an equilibrium object in a fixed ordering.

This method builds a vector of coil currents corresponding to self.coil_names, ensuring a consistent ordering between the probe model and the equilibrium representation.

Parameters:

eq (object) – Equilibrium object containing a tokamak attribute with coil objects indexed by name.

Returns:

Array of coil currents in A, ordered according to self.coil_names.

Return type:

np.ndarray

Notes

  • The ordering of currents is determined by self.coil_names, which is

fixed during probe initialisation. - Each coil is accessed via eq.tokamak[label].current. - This could be replaced by a vectorised call such as eq.tokamak.getcurrents() if ordering consistency is guaranteed.

get_plasma_current(eq: object) → ndarray[source]

Extract the toroidal plasma current distribution from an equilibrium object.

The returned quantity is the grid-based plasma current density mapped to the physically valid domain (typically restricted by the limiter region).

Parameters:

eq (object) – Equilibrium object containing the plasma current density profile and limiter geometry.

Returns:

Toroidal current distribution mapped onto the limiter-constrained grid.

Return type:

np.ndarray

Notes

  • The current density is taken from eq._profiles.jtor.

  • The mapping to circuit-relevant currents is performed via:

eq.limiter_handler.Iy_from_jtor(…) - This ensures only physically valid (in-limiter) contributions are used.

greens_BrBz_all_coils(eq: object, probe: str = 'pickups') → tuple[ndarray, ndarray][source]

Compute Green’s function matrices for (Br, Bz) contributions from all coils evaluated at a set of probe locations.

This function assembles the coil-wise Green’s functions into global matrices: - Each row corresponds to a coil in self.coils_dict - Each column corresponds to a probe location - Entries represent the magnetic field response (Br or Bz) at a probe due to a given coil

Parameters:
  • eq (object) – Equilibrium object containing the tokamak configuration.

  • probe (str, optional) – Set of probe locations where fields are evaluated. Currently only “pickups” is implemented (default).

Returns:

  • array_r (np.ndarray) – Global Green’s function matrix for radial field component Br, shape (n_coils, n_probes).

  • array_z (np.ndarray) – Global Green’s function matrix for vertical field component Bz, shape (n_coils, n_probes).

initialise_setup(eq: object) → None[source]

Initialise probe geometry and precompute Green’s functions for a given equilibrium configuration.

This method validates compatibility between the probe set and the supplied equilibrium, then constructs all probe-related quantities (positions, orientations, and Green’s function caches) required for synthetic diagnostic evaluation.

Parameters:

eq (object) – Equilibrium object providing tokamak geometry, coil configuration, and (optionally) plasma state information.

Raises:

AssertionError – If the coil configuration in eq.tokamak does not match the coil configuration used to define the probes.

Notes

All results are stored in-place as object attributes. This routine performs expensive precomputation of Green’s functions and should typically be called once per equilibrium setup.

Flux Loops

  • Extracts flux loop positions and ordering from self.floops

  • Computes coil contribution Green’s functions:

    greens_psi_coils_floops

  • Computes plasma contribution Green’s functions:

    greens_psi_plasma_floops (cached per equilibrium key)

Pickup Coils

  • Extracts pickup positions and orientation vectors

  • Computes coil contributions:

    greens_br_coils_pickup, greens_bz_coils_pickup

  • Computes oriented magnetic field responses:

    greens_B_coils_oriented, greens_B_plasma_oriented

Caching

All plasma-dependent Green’s functions are stored in dictionaries keyed by an equilibrium identifier (eq_key) to avoid recomputation when possible.

plot(axis: object | None = None, show: bool = True, floops: bool = True, pickups: bool = True, pickups_scale: float = 0.05) → object[source]

Plot magnetic diagnostic probes (fluxloops and pickup coils).

This is a convenience wrapper around freegsnke.plotting.plotProbes.

Parameters:
  • axis (matplotlib.axes.Axes, optional) – Matplotlib axis to draw on. If None, a new figure/axis is created.

  • show (bool, optional) – If True, calls matplotlib.pyplot.show() before returning.

  • floops (bool, optional) – If True, plots fluxloop diagnostics.

  • pickups (bool, optional) – If True, plots pickup coil diagnostics.

  • pickups_scale (float, optional) – Scaling factor for visual representation of pickup coil orientation.

Returns:

Matplotlib axis containing the plotted probes.

Return type:

matplotlib.axes.Axes

psi_floop_all_coils(eq: object, probe: str = 'floops') → ndarray[source]

Compute the total poloidal flux at all flux loop locations due to all coils.

This method forms the linear superposition of coil contributions using the precomputed Green’s function matrix and the current coil state from the equilibrium.

Parameters:
  • eq (object) – Equilibrium object providing the current coil state via get_coil_currents.

  • probe (str, optional) – Diagnostic type. Currently only flux loops (“floops”, the default) are supported.

Returns:

Total poloidal flux ψ at each flux loop location due to all coils.

Return type:

np.ndarray

Notes

  • Uses the Green’s function matrix:

self.greens_psi_coils_floops - Coil contributions are combined via linear superposition: ψ_total = Σ_i I_i G_i - The ordering of coils is defined by self.coil_names.

psi_from_plasma(eq: object, probe: str = 'floops') → ndarray[source]

Compute the contribution of plasma current to poloidal flux measurements at diagnostic probes.

This evaluates the linear mapping from distributed plasma current density to flux loop signals using precomputed or lazily generated Green’s functions.

Parameters:
  • eq (object) – Equilibrium object containing plasma current distribution and limiter mapping information.

  • probe (str, optional) – Diagnostic type. Currently only flux loops (“floops”, the default) are supported.

Returns:

Contribution to poloidal flux ψ at each probe due to plasma current.

Return type:

np.ndarray

Notes

  • Plasma current distribution is obtained via:

get_plasma_current(eq) - Green’s functions are cached per equilibrium grid using: create_eq_key(eq) - If no cached plasma Green’s function exists for the given equilibrium, it is computed on demand via create_green_psi_plasma. - The final signal is computed by linear superposition:

ψ = Σ_i G_i I_i