plasma_plots.gvec
Read GVEC’s evaluation Datasets in plasma-plots’ conventions.
GVEC <https://gvec.readthedocs.io>_ evaluates an equilibrium into xarray Datasets
(state.evaluate(...), state.evaluate_sfl(...), gvec.Evaluations) with the dimensions
rad, pol, tor, the flux coordinates rho, theta, zeta (or the Boozer angles
theta_B, zeta_B, or the PEST angle theta_P) over them, vectors along xyz, the
position as the variable pos and LaTeX symbol attributes. from_gvec() returns the
same data the way the rest of plasma-plots reads it:
- the dimensions are the flux coordinates themselves:
rho,theta/theta_B/theta_Pandzeta/zeta_B, sorho=0.5orzeta=0selects andx="zeta"draws; posbecomes the physical coordinatesX,Y,Zof every variable (forcoords="physical", 3-D views and the vector calculus on the mapped domain), andX1,X2(GVEC’s reference coordinates,RandZfor the cylindrical map),theta_Pand the logical angles of a Boozer or PEST grid become coordinates as well;xyzbecomescomponent;- each
symbolbecomes alabel($\iota$), which plots use for axes and color bars; - the angles get a
periodattribute (2π, and 2π/nfp toroidally), from which the mode spectra take their periods and full-torus mode numbers, and thecoordinate_linesoverlay its lines; - GVEC’s quadrature weights (
rad_weight,pol_weight,tor_weight) becomerho_weight,theta_weight,zeta_weight, which integrals use. GVEC’s toroidal weight counts every field period;zeta_weightis divided by nfp, so that an integral covers the sampled grid (one field period) as on every other grid: multiply by nfp for the device; - the number of field periods (
N_FP) is thenfpattribute of the Dataset and of every variable.
The .plasma accessor applies from_gvec() by itself to GVEC data, so
ev.mod_B.plasma.plot.slice(x="zeta", y="theta", rho=1.0) needs no call. Call it once on the
whole Dataset to attach the geometry to every variable first: a single variable such as
ev.mod_B doesn’t carry pos. GVEC itself is not needed.
Examples
>>> import plasma_plots>>> ev = plasma_plots.from_gvec(... state.evaluate(... "mod_B", "pos", "iota", "N_FP", rho=11, theta=32, zeta=24... )... )>>> ev.mod_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
| Name | Description |
|---|---|
AXES | No description. |
GRID_VARIABLES | No description. |
GVEC_DIMS | No description. |
POLOIDAL | No description. |
TOROIDAL | No description. |
AXESattributemodule attribute#
AXES = {'rad': ('rho'), 'pol': ('theta_B', 'theta_P', 'theta'), 'tor': ('zeta_B', 'zeta')}GRID_VARIABLESattributemodule attribute#
GRID_VARIABLES = ('X1', 'X2', 'theta_P', 'theta', 'zeta', 'theta_B', 'zeta_B')GVEC_DIMSattributemodule attribute#
GVEC_DIMS = ('rad', 'pol', 'tor')POLOIDALattributemodule attribute#
POLOIDAL = ('theta', 'theta_B', 'theta_P')TOROIDALattributemodule attribute#
TOROIDAL = ('zeta', 'zeta_B')from_gvecfunction#
def from_gvec(data: xr.DataArray | xr.Dataset, *, nfp: int | None = None) -> xr.DataArray | xr.DatasetReturn GVEC evaluations in plasma-plots’ conventions; see plasma_plots.gvec.
Data that is not in GVEC’s layout (see is_gvec()) comes back with only the steps that
apply, so calling it twice is harmless.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
data | xarray.Dataset or xarray.DataArray | required | A Dataset from state.evaluate(...), state.evaluate_sfl(...) or gvec.Evaluations
(also after to_netcdf and open_dataset), or one of its variables. |
nfp | int | None | The number of field periods. Default: the N_FP variable (evaluate "N_FP" with the
rest), else an nfp attribute, else from a toroidal grid that spans one field period
uniformly (GVEC’s default grid); without one, the toroidal angle gets no period. |
Returns
xarray.Dataset or xarray.DataArray- The same data, of the same type, with the dimensions
rho,theta/theta_B/theta_P,zeta/zeta_Bandcomponent, the coordinatesX,Y,Z(frompos),X1,X2, labels from thesymbolattributes, the angles’periodand thenfpattribute.
Examples
>>> ev = from_gvec(... state.evaluate("mod_B", "pos", "N_FP", rho=11, theta=32, zeta=24)... )>>> ev.mod_B.plasma.plot.panels(... sweep="zeta", coords="physical", plane="RZ", nrows=1, ncols=3... )>>> boozer = from_gvec(... state.evaluate_sfl(... "mod_B", "pos", rho=[0.5], theta=32, zeta=24, sfl="boozer"... )... )>>> boozer.mod_B.plasma.plot.slice(x="zeta_B", y="theta_B", rho=0.5)is_gvecfunction#
def is_gvec(data: xr.DataArray | xr.Dataset) -> boolWhether data is still in GVEC’s layout.
That is a rad, pol or tor dimension with one of GVEC’s flux coordinates on it.
Parameters
| Name | Type | Description |
|---|---|---|
data | xarray.DataArray or xarray.Dataset | The data. |
Returns
boolTruefor GVEC’s evaluations (beforefrom_gvec()),Falseotherwise.