Skip to content

plasma_plots.desc

Evaluate DESC equilibria into Datasets in plasma-plots’ conventions.

DESC <https://desc-docs.readthedocs.io>_ computes a quantity of an equilibrium on a grid of flux coordinates, eq.compute(names, grid), and returns flat arrays over the grid’s nodes. from_desc() evaluates an equilibrium on a tensor-product grid and returns an xarray.Dataset that the rest of plasma-plots reads the way it reads GVEC’s:

  • the dimensions are the flux coordinates rho, theta (DESC’s poloidal angle, or the PEST angle theta_P with sfl="pest") and zeta (the cylindrical toroidal angle), so rho=0.5 selects and x="zeta" draws;
  • X, Y, Z are coordinates of every variable (for coords="physical", 3-D views and the vector calculus on the mapped domain), and theta_P too when "theta_PEST" is among the names (for the coordinate_lines overlay);
  • vectors, which DESC gives in cylindrical components, are Cartesian (x, y, z) along component, as on every other grid;
  • profiles (DESC’s quantities over rho only) are over rho, and global quantities such as "V" are scalars;
  • each quantity keeps DESC’s name (ds["|B|"]) and gets DESC’s LaTeX label, its units and its description as long_name;
  • the angles get a period attribute (2π, and 2π/nfp toroidally), from which the mode spectra take their periods and full-torus mode numbers, and the coordinate_lines overlay its lines;
  • the number of field periods is the nfp attribute of the Dataset and of every variable.

Integrals over the grid cover the sampled toroidal range, one field period by default, as for GVEC: multiply by nfp for the device. DESC’s Jacobian is "sqrt(g)". Unlike GVEC’s, the evaluation needs DESC itself (pip install desc-opt); the Dataset it returns does not (to_netcdf saves it).

Examples

>>> import desc.examples
>>> import plasma_plots
>>> eq = desc.examples.get("W7-X")
>>> ev = plasma_plots.from_desc(
... eq, ["|B|", "iota", "sqrt(g)"], rho=11, theta=64, zeta=40
... )
>>> ev["|B|"].plasma.plot.slice(
... coords="physical",
... plane="RZ",
... zeta=0.0,
... overlays={"coordinate_lines": {"rho": 5, "theta": 8}},
... )
>>> ev.iota.plasma.plot.lineout(rationals=4)

Attributes

NameDescription
CARTESIANNo description.
GEOMETRYNo description.
GRID_QUANTITIESNo description.
POLOIDALNo description.

Functions

NameDescription
from_descEvaluate DESC quantities on a grid, as a Dataset in plasma-plots' conventions.

CARTESIANattributemodule attribute#

CARTESIAN = ['x', 'y', 'z']

GEOMETRYattributemodule attribute#

GEOMETRY = ('X', 'Y', 'Z', 'phi', 'rho', 'zeta')

GRID_QUANTITIESattributemodule attribute#

GRID_QUANTITIES = {'theta_PEST': 'theta_P'}

POLOIDALattributemodule attribute#

POLOIDAL = {None: 'theta', 'pest': 'theta_P'}

from_descfunction#

def from_desc(eq, names: str | Sequence[str], *, rho: int | float | Sequence[float] = 11, theta: int | float | Sequence[float] = 32, zeta: int | float | Sequence[float] = 24, sfl: str | None = None) -> xr.Dataset

Evaluate DESC quantities on a grid, as a Dataset in plasma-plots’ conventions.

See plasma_plots.desc for what the Dataset contains.

Parameters

NameTypeDefaultDescription
eqdesc.equilibrium.EquilibriumrequiredThe equilibrium, e.g. desc.io.load("eq.h5") or desc.examples.get("W7-X").
namesstr or sequence of strrequiredDESC’s names of the quantities ("|B|", "iota", "sqrt(g)", "B", "J", "p", "D_Mercier", "V", …; see DESC’s list of variables). "theta_PEST" becomes the coordinate theta_P. Quantities that are not scalars, profiles, fields or 3-vectors (such as "grad(B)") are not supported, nor "x": the position is X, Y, Z.
rhoint, float or sequence of float11The flux surfaces: an integer as that many points from 0 to 1, a float or a sequence as the values. Default: 11 points.
thetaint, float or sequence of float32The poloidal angles (PEST angles with sfl="pest"): an integer as that many points over [0, 2π), else the values. Default: 32 points.
zetaint, float or sequence of float24The toroidal angles: an integer as that many points over one field period [0, 2π/nfp), else the values, which may cover the whole torus. Default: 24 points.
sfl(None, 'pest')None"pest" for a grid in the straight-field-line PEST angle theta_P (DESC’s own theta becomes a coordinate, found by eq.map_coordinates) rather than in DESC’s poloidal angle. Default: None.

Returns

xarray.Dataset
The quantities over rho, theta (or theta_P) and zeta, vectors along component, with the coordinates X, Y, Z, labels, units, the angles’ period and the nfp attribute.

Raises

ValueError
For an unknown sfl, a name DESC doesn’t know, a quantity of an unsupported shape or a coordinate triplet such as "x".

Examples

>>> ev = from_desc(eq, ["|B|", "iota", "sqrt(g)"], rho=11, theta=64, zeta=40)
>>> ev["|B|"].plasma.plot.panels(
... sweep="zeta", coords="physical", plane="RZ", nrows=1, ncols=3
... )
>>> pest = from_desc(eq, "|B|", rho=[0.5], theta=64, zeta=48, sfl="pest")
>>> pest["|B|"].plasma.plot.slice(x="zeta", y="theta_P", rho=0.5)