Skip to content

Plots

dexter.machine.plot

Plotting functions for machine objects.

Some methods are also available as command line project scripts.

Functions:

plot_qfactor(obj: Machine | QfactorObject, points: int = 1000, data: bool = False, show: bool = True) -> tuple[Figure, tuple[Axes, Axes, Axes, Axes]]

Plots a QfactorObject's $q(\psi_t)$, $q(\psi_p)$, $q'(\psi_t)$, $q'(\psi_p)$, $\psi_p(\psi_t)$ and $\psi_t(\psi_p)$.

The derivatives $d\psi_t/d\psi_p$ and $(d\psi_p/d\psi_t)^{-1}$ are calculated independently from $q(\psi_p)$ and $\iota(\psi_t)$. It is a good sanity check to ensure the two curves coincide.

Parameters:

  • obj (Machine | QfactorObject) –

    The qfactor object or the machine containing it.

  • points (int, default: 1000 ) –

    The number of points on which to evaluate the flux in each plot.

  • data (bool, default: False ) –

    Whether or not to plot the data points, if machine.current.machine_type == "Numerical".

  • show (bool, default: True ) –

    Whether or not to call plt.show().

Example
Qfactor plot
>>> machine = dex.Machine.FromNetcdf(path, "Akima", "Bicubic")
>>> fig, ax = dex.plot_qfactor(machine, data=True)
From command line
dexter-plot-qfactor ./netcdf.nc -i Cubic

plot_current(machine: Machine, flux: MagneticFluxKind = 'Toroidal', points: int = 1000, data: bool = False, show: bool = True) -> tuple[Figure, tuple[Axes, Axes]]

Plots a CurrentObject's $g$, $I$ and their derivatives, with respect to $\psi_t$ and $\psi_p$.

The second order derivatives of $g$ and $I$ are plotted as well, but in arbitrary units and origin.

Parameters:

  • machine (Machine) –

    The machine containing the current object.

  • flux (MagneticFluxKind, default: 'Toroidal' ) –

    The kind of magnetic flux with respect to which to plot. If the toroidal flux is not a good coordinate, the poloidal flux is attempted.

  • points (int, default: 1000 ) –

    The number of points on which to evaluate the flux in each plot.

  • data (bool, default: False ) –

    Whether or not to plot the data points, if machine.current.machine_type == "Numerical".

  • show (bool, default: True ) –

    Whether or not to call plt.show().

Example
Current plot
>>> machine = dex.Machine.FromNetcdf(path, "Akima", "Bicubic")
>>> fig, ax = dex.plot_current(machine, data=True)
From command line
dexter-plot-current ./netcdf.nc -d -f Poloidal

plot_bfield(machine: Machine, levels: int = 15, contour_points: bool = False, show: bool = True) -> tuple[Figure, tuple[Axes, Axes, Axes]]

Plots a BfieldObject's $B$ and its derivatives on the $R-Z$ plane.

Parameters:

  • machine (Machine) –

    The machine containing the current object.

  • levels (int, default: 15 ) –

    The number of contour levels.

  • contour_points (bool, default: False ) –

    Whether or not to plot the $\partial B/\partial \theta = 0$ points as calculated from the StationaryCurve.

  • show (bool, default: True ) –

    Whether or not to call plt.show().

Example
Bfield plot
>>> machine = dex.Machine.FromNetcdf(path, "Akima", "Bicubic")
>>> fig, ax = dex.plot_bfield(machine, levels=20)
From command line
dexter-plot-bfield ./netcdf.nc -l 30

plot_mode(mode: ModeObject, flux: MagneticFluxKind = 'Toroidal', points: int = 1000, data: bool = False, show: bool = True) -> tuple[Figure, tuple[Axes, Axes]]

Plots a ModeObject's $\alpha$, $\phi$ and its derivatives with respect to $\psi_t$ or $\psi_p$.

Parameters:

  • mode (ModeObject) –

    The ModeObject.

  • flux (MagneticFluxKind, default: 'Toroidal' ) –

    The kind of magnetic flux with respect to which to plot. If the toroidal flux is not a good coordinate, the poloidal flux is attempted.

  • points (int, default: 1000 ) –

    The number of points on which to evaluate the flux in each plot.

  • data (bool, default: False ) –

    Whether or not to plot the data points, if machine.current.machine_type == "Numerical".

  • show (bool, default: True ) –

    Whether or not to call plt.show().

Example
Mode plot
>>> mode = dex.NcFluteMode(path, "Cubic", 3, 2)
>>> fig, ax = dex.plot_mode(mode, data=True)
From command line
dexter-plot-mode ./netcdf.nc 2 1

plot_efield(machine: Machine, flux: MagneticFluxKind = 'Toroidal', points: int = 1000, show: bool = True) -> tuple[Figure, tuple[Axes, Axes]]

Plots an EfieldObject's $E$, $Φ$, with respect to $\psi_t$ or $\psi_p$.

The first and second derivatives of $\Phi$ are plotted as well, but in arbitrary units and origin.

Parameters:

  • machine (Machine) –

    The machine containing the electric field object.

  • flux (MagneticFluxKind, default: 'Toroidal' ) –

    The kind of magnetic flux with respect to which to plot. If the toroidal flux is not a good coordinate, the poloidal flux is attempted.

  • points (int, default: 1000 ) –

    The number of points on which to evaluate the flux in each plot.

  • show (bool, default: True ) –

    Whether or not to call plt.show().

Example
Electric field plot
>>> machine = dex.Machine.FromNetcdf(path, "Akima", "Bicubic")
>>> geometry = machine.geometry
>>> LCFS = geometry.psit_last
>>>
>>> strength = machine.quantity(75, "kiloVolt / meter")
>>> rmean = 0.96 * machine.rlast
>>> mean = dex.MagneticFlux.Toroidal(float(machine.geometry.eval_psit_of_r(rmean)))
>>> waist = LCFS.value * 0.02
>>> efield = dex.GaussianEfield(strength, mean, waist)
>>> machine.efield = efield
>>>
>>> fig, ax = dex.plot_current(machine, data=True)