This is the full developer documentation for plasma-plots # Getting started > Install plasma-plots and make your first plot. ## Installation [Section titled “Installation”](#installation) Python **3.10 or newer** is required; CI tests Python 3.10 to 3.14. The base install plots in-memory xarray data. Install extras for file formats and optional renderers: ```bash pip install plasma-plots pip install "plasma-plots[netcdf]" pip install "plasma-plots[netcdf,plotly]" ``` | Extra | Enables | Dependencies | | ----------- | ---------------------------------------------------------------- | ---------------------------------------------------- | | `netcdf` | Read netCDF3/netCDF4 files through xarray and the CLI | `netCDF4` | | `plotly` | Interactive browser plots and static Plotly exports | `plotly`, `kaleido` | | `tikz` | TikZ/pgfplots versions of the plots for LaTeX (`backend="tikz"`) | `maxplotlibx` (and `pdflatex` to compile) | | `pyvista` | 3-D scenes and rendering | `pyvista`, `imageio` | | `profiling` | Timing summaries and profiling plots | `scope-profiler[pproc]` | | `desc` | Evaluate DESC equilibria | `desc-opt` | | `gallery` | Export Struphy example-gallery figures and profiling | `plotly`, `kaleido`, `scope-profiler[pproc]>=0.6.1` | | `dev` | Tests, linting and documentation tooling | `pytest`, `ruff`, `h5py`, `griffe`, `struphy>=3.4.0` | Struphy is installed by the `dev` extra; otherwise install it separately as described below. GVEC and Zarr are separate installations. Install `gvec` for GVEC evaluation or `zarr` to open Zarr stores. MP4 export requires system `ffmpeg`; Matplotlib windows require a working GUI/display, and static Plotly exports through Kaleido require a compatible Chrome installation. ## Struphy compatibility [Section titled “Struphy compatibility”](#struphy-compatibility) Struphy integration requires **Struphy 3.4.0 or newer** from PyPI: ```bash pip install "struphy>=3.4.0" ``` Struphy is optional when working with ordinary xarray data. ## Loading plasma-plots [Section titled “Loading plasma-plots”](#loading-plasma-plots) Creating a Struphy `Output` loads plasma-plots, so there is nothing to import: ```python from struphy.post_processing.output import Output out = Output("path/to/run") out.plot.energies() # whole-run plots and diagnostics field = out.evaluate("em_fields/phi") field.plasma.plot.slice(x="eta1", y="eta2", t=-1) # .plasma on every product ``` Loading it registers the accessors: * `.plasma` on every `xarray.DataArray` and `xarray.Dataset`, including the products of Struphy’s `Output` and every array derived from them * `out.plot` and `out.analysis` on Struphy’s `Output` object Other xarray data: `import plasma_plots` For xarray data that doesn’t come from an `Output` (your own arrays, or files opened with xarray), import the package first: ```python import plasma_plots # noqa: F401 (registers DataArray.plasma) ``` Without it, `.plasma` does not exist and you get `AttributeError: 'DataArray' object has no attribute 'plasma'`. The import alone does the work, so linters may flag it as unused. ## Data from other codes [Section titled “Data from other codes”](#data-from-other-codes) plasma-plots reads labeled `xarray` objects, not a file format, so the output of any code works once it is an array with named dimensions and coordinates. The names follow Struphy’s: | Name | What | | ---------------------- | ------------------------------------------------------------------------------------------------------------ | | `t` | time | | `eta1`, `eta2`, `eta3` | logical coordinates in \[0, 1] | | `X`, `Y`, `Z` | mapped (physical) coordinates, as coordinates over the logical dimensions; all three for `coords="physical"` | | `component` | the components of a vector field | | `marker` | the markers of particle Datasets | [GVEC](https://gvec.readthedocs.io)’s evaluations (dimensions `rad`, `pol`, `tor`) are read in these conventions by themselves, with the flux coordinates `rho`, `theta`, `zeta` as the logical dimensions; see [GVEC equilibria](/plasma-plots/guides/gvec/). Other dimension names work wherever you name the dimensions yourself (`x="z"`, `y="t"`); only the physical views and the mapped-domain analysis need `X`/`Y`/`Z`. The `label` and `units` attributes of the array and the `long_name` and `units` of its coordinates become the axis labels: ```python import numpy as np import xarray as xr import plasma_plots # noqa: F401 t, eta1, eta2 = ( np.linspace(0, 10, 41), np.linspace(0, 1, 32), np.linspace(0, 1, 24, endpoint=False), ) r, theta = 0.2 + 0.8 * eta1[:, None], 2 * np.pi * eta2[None, :] phi = xr.DataArray( np.exp(-0.1 * t)[:, None, None] * np.cos(2 * np.pi * eta1)[None, :, None] * np.cos(theta)[None], dims=("t", "eta1", "eta2"), coords={ "t": t, "eta1": eta1, "eta2": eta2, "X": (("eta1", "eta2"), r * np.cos(theta)), "Y": (("eta1", "eta2"), r * np.sin(theta)), "Z": (("eta1", "eta2"), np.zeros((32, 24))), }, attrs={"label": r"$\phi$", "units": "V"}, ) phi.plasma.plot.slice(x="eta1", y="eta2", t=-1) # logical # mapped, through X and Y phi.plasma.plot.slice(coords="physical", plane="XY", t=-1) ``` ## Finding your way in Python [Section titled “Finding your way in Python”](#finding-your-way-in-python) Printing an accessor lists its methods with a one-line summary each, and `help()` on a method shows every parameter: ```python print(field.plasma.plot) # every plot, e.g. slice, animation, dispersion, ... help(field.plasma.plot.slice) # its parameters, returns and examples print(out.plot) # whole-run plots import plasma_plots help(plasma_plots) # an overview: the pipeline, selection, what is where ``` `plasma-plots guide` prints the same overview in a terminal, and the `plasma-plots` command saves figures without any Python (see [Command line](/plasma-plots/guides/command-line/)). For language models and coding agents, the documentation is also available as plain text at [`/llms.txt`](/plasma-plots/llms.txt), with the full text in [`/llms-full.txt`](/plasma-plots/llms-full.txt). ## Where to look next [Section titled “Where to look next”](#where-to-look-next) * **`array.plasma.plot`** — plotting methods for a single labeled array: [Field plots](/plasma-plots/guides/field-plots/), [Time series & comparisons](/plasma-plots/guides/timeseries/), and [Particles & distributions](/plasma-plots/guides/particles/). * **`array.plasma.analysis`** — numerical diagnostics on a single labeled array (see [Diagnostics](/plasma-plots/guides/analysis/)). * **`array.plasma.data`** — the selected data behind every plot, as a labeled `xarray` object, for your own analysis, other plotting libraries and exports (see [Selecting data](/plasma-plots/guides/data/)). * **`plasma_plots.output_accessors.OutputPlots`** — overview plots for a whole simulation run (see [Whole-run plots](/plasma-plots/guides/output-plots/)). Lower-level, function-based versions of everything above are also available directly from `plasma_plots.plotting` and `plasma_plots.analysis`, if you’d rather call a function on a plain `xarray.DataArray` than go through the accessor. ## Getting the data instead of a plot [Section titled “Getting the data instead of a plot”](#getting-the-data-instead-of-a-plot) Every method on `array.plasma.plot` has a twin on `array.plasma.data`. It does the same selection and returns the labeled `xarray` object instead of a figure, for your own analysis, another plotting library or an export: ```python # what plot.slice(...) draws last = field.plasma.data.slice(x="eta1", y="eta2", t=-1) float(last.max()), last.to_dataframe() ``` See [Selecting data](/plasma-plots/guides/data/). ## Running under MPI [Section titled “Running under MPI”](#running-under-mpi) A post-processing script can run on several ranks, e.g. right after the simulation in the same `mpirun -n 4 python script.py`. Plots are then drawn and saved on rank 0 only; the other ranks get a `SkippedPlot` placeholder whose methods do nothing, so the same script works in serial and in parallel without `if rank == 0:` guards: ```python out = sim.run() # or Output(path) phi = out.evaluate("em_fields/phi") # on every rank # written once, by rank 0 phi.plasma.plot.slice(x="eta1", y="eta2", t=-1, eta3=0).save("phi.png") # [] on ranks > 0 phi.plasma.plot.frames("frames/", x="eta1", y="eta2", eta3=0) ``` Struphy processes the run on first use, collectively: call `evaluate()` on every rank until the run is processed. Analysis (`array.plasma.analysis.*`) runs on every rank. The rank is read from `mpi4py` once MPI is initialized (Struphy does that), and otherwise from the MPI launcher’s environment, so plasma-plots never needs `mpi4py` itself. Set `STRUPHY_MPI=0` to make every process plot. Nothing waits for rank 0: call `MPI.COMM_WORLD.Barrier()` before other ranks read a file rank 0 wrote. `plasma_plots.is_plotting_rank()` tells whether the current process draws. # Selecting data > array.plasma.data returns the data behind every plot, for your own analysis, plots and exports. Where the accessors come from The examples on this page use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). Every plot on `array.plasma.plot` has a twin on `array.plasma.data`. The twin takes the same arguments and does the same selection, but returns the `xarray` object the plot would draw instead of a figure. The result keeps the coordinates (including the physical `X`, `Y`, `Z`), the units and the labels, so you can work with it directly: * analyze it: take maxima, means and cuts, or compare two times * plot it with plain matplotlib, Plotly, HoloViews or any other library * export it with `.to_dataframe()`, `.to_netcdf()` or `.values` ```python # 2-D, with X and Y last = n.plasma.data.slice(coords="physical", plane="XY", t=-1, eta3=0) # 1-D, along eta1 cut = n.plasma.data.lineout(x="eta1", t=-1, eta2=0.3, eta3=0) ``` ## Selecting by name [Section titled “Selecting by name”](#selecting-by-name) Name each dimension you don’t plot, as for every plot: | Value | Selects | | -------------------------------- | ---------------------------------- | | an integer, e.g. `t=0` or `t=-1` | that position: the first, the last | | a float, e.g. `t=0.35` | the nearest coordinate value | An integer and a float differ: `t=0` is the first sample, `t=0.0` the one nearest to time zero. An unknown name raises an error that lists the array’s dimensions, and a static slice asks you to select one time if you haven’t. `coords="physical"` with a `plane` (`"XY"`, `"XZ"`, `"YZ"` or `"RZ"`) selects for a slice in physical space. Struphy’s cell-centered grids leave out the periodic seam (e.g. θ = 1 ≡ 0), and the physical slice closes it again, so `data.slice` and `data.view` return one more point along a periodic angle than the field has. The 2-D slice comes back ordered `(x, y)`, the order you asked for. Many libraries read an array as `(row, column)`, i.e. `(y, x)`, so transpose it for those (`selected.transpose("eta2", "eta1")`, or `.T`). ## The data behind each plot [Section titled “The data behind each plot”](#the-data-behind-each-plot) | Plot | Data | Returns | | ---------------------------------------------- | ---------------------------------------- | ------------------------------------------------------- | | `plot.lineout(...)` | `data.lineout(...)` | the 1-D profile | | `plot.slice(...)` | `data.slice(...)` | the 2-D slice, ordered `(x, y)` | | `plot.panels`, `viewer`, `animation`, `frames` | `data.view(...)` | the slice over the whole sweep, e.g. `(t, x, y)` | | `plot.vector(...)` | `data.vector(...)` | the selected, strided components | | `plot.volume_slices(...)` | `data.volume_slices(...)` | the three midplanes, as a dict | | `plot.compare(other)` | `data.compare(other)` | the aligned difference or ratio | | `plot.timeseries(*others)` | `data.timeseries(*others)` | the validated list of series | | `plot.dispersion(...)` | `data.dispersion(...)` | the `(omega, k)` power | | `plot.overlay_orbits(...)` | `data.overlay_orbits(...)` | the field slice and the orbit subset | | `plot.slices_3d(...)` | `data.slices_3d(...)` | the logical cuts | | every 3-D view | `data.grid(...)`, `data.to_vtk(...)` | a PyVista grid, or VTK files for ParaView | | `dataset.plot.scatter(...)` | `dataset.data.scatter(...)` | the positions and colors per marker | | `plot.trajectories(...)` | `data.trajectories(...)` | the marker subset | | `plot.poincare(...)` | `data.poincare(...)` | the punctures of the traced field lines | | `plot.critical_points(...)` | `data.critical_points(...)` | the O- and X-points of a flux function | | `dataset.plot.poincare()`, `footprint()` | `dataset.data.poincare()`, `footprint()` | the punctures, the exit points of traced lines | | `dataset.plot.loss_map(...)` | `dataset.data.loss_map(...)` | each marker’s initial position, loss flag and loss time | The full signatures are in the [`struphy.data` reference](/plasma-plots/reference/data/). ## Analysis on the selection [Section titled “Analysis on the selection”](#analysis-on-the-selection) The selection is an ordinary `DataArray`, so xarray and numpy work on it directly. For the ring from the [contour-line example](/plasma-plots/guides/field-plots/#contour-lines): ```python last = n.plasma.data.slice(coords="physical", plane="XY", t=-1, eta3=0) densest = last.isel(last.argmax(...)) # the densest point, with its X and Y print(float(densest.X), float(densest.Y)) cut = n.plasma.data.lineout(x="eta1", t=-1, eta2=0.3, eta3=0) radius = 0.1 + 0.9 * cut.eta1 # this mapping's minor radius inside = radius.where(cut >= 0.2) width = float(inside.max() - inside.min()) # the ring's width along the cut # (t, eta1, eta2) frames = n.plasma.data.view(coords="physical", plane="XY", eta3=0) peak_over_time = frames.max("t") # the largest density each point reached ``` The same selections drawn with plain matplotlib: ```python fig, (ax_map, ax_cut) = plt.subplots(1, 2) ax_map.contourf(last.X, last.Y, last, levels=12) ax_map.plot(densest.X, densest.Y, "w*") ax_cut.plot(radius, cut) ax_cut.axvspan(float(inside.min()), float(inside.max()), alpha=0.25) ``` ![A physical slice from data.slice drawn with contourf, and a radial cut from data.lineout](/plasma-plots/_astro/data_selection.CSf26HGC_1ziXy3.webp) ## Exports [Section titled “Exports”](#exports) ```python last.to_dataframe() # a pandas table, one row per point, with X and Y last.to_netcdf("ring_last.nc") # a self-describing file with all coordinates np.save("ring_last.npy", last.values) # the bare numbers n.plasma.data.to_vtk("ring") # one .vts per time and a .pvd for ParaView ``` ## Other plotting libraries [Section titled “Other plotting libraries”](#other-plotting-libraries) `plasma-plots` never depends on another plotting library. The selected data goes to any of them; for Plotly there is also a shortcut, `backend="plotly"`, which draws every plot as an interactive Plotly figure (see [Interactive plots with Plotly](/plasma-plots/guides/plotly/)). Built by hand, a 2-D slice as a Plotly heatmap: ```python import plotly.express as px selected = field.plasma.data.slice(x="eta1", y="eta2", t=-1) px.imshow( selected.transpose("eta2", "eta1"), x=selected.eta1, y=selected.eta2, origin="lower", color_continuous_scale="viridis", ) ``` Loading interactive chart… # API reference > Every accessor, function and class of plasma-plots, generated from the docstrings. The reference is generated from the docstrings, so it always matches the code. The guides show the same functionality with figures. Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## Accessors [Section titled “Accessors”](#accessors) Most of plasma-plots is reached through accessors on the objects Struphy returns: | Accessor | What it does | | ---------------------------------------------------------------- | ------------------------------------------------------------------------------- | | [`array.plasma.plot`](/plasma-plots/reference/plot/) | Plots of one labeled array: time series, slices, animations, spectra, 3-D views | | [`array.plasma.analysis`](/plasma-plots/reference/analysis/) | Diagnostics of one labeled array: fits, norms, errors, spectra, vector calculus | | [`array.plasma.data`](/plasma-plots/reference/data/) | The selected data behind every plot, without drawing it | | [`dataset.plasma`](/plasma-plots/reference/dataset/) | Plots, diagnostics and data of marker Datasets such as orbits | | [`out.plot` and `out.analysis`](/plasma-plots/reference/output/) | Whole-run plots and diagnostics of a Struphy `Output` | A method’s page lists every parameter, including those it shares with the function it wraps. ## Modules [Section titled “Modules”](#modules) The functions behind the accessors, to call on a plain `xarray.DataArray`, and the analytic theory: | Module | Contents | | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [`plasma_plots.plotting`](/plasma-plots/api/plasma_plots/plotting/) | Plotting functions for labeled Struphy output | | [`plasma_plots.analysis`](/plasma-plots/api/plasma_plots/analysis/) | Numerical diagnostics: fits, norms, errors, integrals, vector calculus, orbits | | [`plasma_plots.spectral`](/plasma-plots/api/plasma_plots/spectral/) | Fourier transforms, filters, peaks, mode spectra, matrix pencil | | [`plasma_plots.spectral_plots`](/plasma-plots/api/plasma_plots/spectral_plots/) | Plots of spectra, filters, modes and fits | | [`plasma_plots.pyvista_plots`](/plasma-plots/api/plasma_plots/pyvista_plots/) | Three-dimensional PyVista views and VTK export | | [`plasma_plots.arrays`](/plasma-plots/api/plasma_plots/arrays/) | Labels, validation and helpers for labeled arrays | | [`plasma_plots.theory`](/plasma-plots/api/plasma_plots/theory/) | Analytic theory: kinetic, wave, orbit, exact-solution and numerics results (see the [Theory guide](/plasma-plots/guides/theory/)) | | [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) | `backend="plotly"`: the conversion of Matplotlib figures into interactive Plotly figures (see [Interactive plots](/plasma-plots/guides/plotly/)) | | [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/) | `backend="tikz"`: the conversion into TikZ/pgfplots figures for LaTeX, by maxplotlib (see [LaTeX figures](/plasma-plots/guides/latex/)) | | [`plasma_plots.gallery`](/plasma-plots/api/plasma_plots/gallery/) | Output helpers of the [example gallery](https://struphy-hub.github.io/examples/): Plotly figure files, profiling exports and metadata (`pip install "plasma-plots[gallery]"`) | The full module tree is under **All modules** in the sidebar. For other tools, each package also has an `objects.inv` (for Sphinx and mkdocstrings links) and an `llms.txt` at [`/api/plasma_plots/`](/plasma-plots/api/plasma_plots/). # array.plasma.analysis > Diagnostics of one labeled array: fits, norms, errors, spectra, vector calculus. Numerical diagnostics of one labeled `xarray.DataArray`, as `array.plasma.analysis.(...)`. They return labeled arrays and Datasets, so their results can be plotted with `.plasma.plot` in turn. Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## array.plasma.analysis [Section titled “array.plasma.analysis”](#arrayplasmaanalysis) Quantitative diagnostics of one array, as `array.plasma.analysis.(...)`. ### `growth_rate` [Section titled “growth\_rate”](#growth_rate) ### `growth_rate`method[#](#plasma_plots.accessors.ArrayAnalysis.growth_rate) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3041-L3079 "src/plasma_plots/accessors.py:3041-3079") ``` def growth_rate(window: tuple[float | None, float | None] = (None, None), amplitude: bool = False) ``` Fit `exp(rate * t + intercept)` to this time series within `window`. Parameters | Name | Type | Default | Description | | ----------- | -------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------- | | `window` | `(float or None, float or None)` | `(None, None)` | The time interval `(t0, t1)` of the fitted samples; `None` for an open end. Default: every sample. | | `amplitude` | `bool` | `False` | The series is quadratic in an amplitude (e.g. an energy): return the amplitude’s rate. Default: `False`. | Returns * `FitResult or None` `.rate`, `.intercept`, `.time` and `.fitted`; `None` with fewer than two valid samples. See Also [`plasma_plots.analysis.growth_rate()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.growth_rate) : The function behind this method. [`ArrayAnalysis.damping_rate()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.damping_rate) : The same fit to the envelope of an oscillating series. [`ArrayPlots.timeseries()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.timeseries) : The series with the fit drawn (`fit=`). Examples ```python >>> energy.plasma.analysis.growth_rate(window=(0.0, 5.0), amplitude=True).rate ``` ### `damping_rate` [Section titled “damping\_rate”](#damping_rate) ### `damping_rate`method[#](#plasma_plots.accessors.ArrayAnalysis.damping_rate) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3081-L3119 "src/plasma_plots/accessors.py:3081-3119") ``` def damping_rate(window: tuple[float | None, float | None] = (None, None), amplitude: bool = False) ``` Fit exponential decay to the envelope of this oscillating time series. Parameters | Name | Type | Default | Description | | ----------- | -------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------- | | `window` | `(float or None, float or None)` | `(None, None)` | The time interval `(t0, t1)` of the peaks that are used; `None` for an open end. Default: every sample. | | `amplitude` | `bool` | `False` | The series is quadratic in an amplitude (e.g. an energy): return the amplitude’s rate. Default: `False`. | Returns * `FitResult or None` The fit to the peaks; the rate is negative for damping. `None` with fewer than two valid peaks. See Also [`plasma_plots.analysis.damping_rate()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.damping_rate) : The function behind this method. [`ArrayAnalysis.growth_rate()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.growth_rate) : The same fit to the series itself. [`ArrayAnalysis.envelope()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.envelope) : The peaks that are fitted. Examples ```python >>> energy.plasma.analysis.damping_rate(amplitude=True).rate ``` ### `oscillation_frequency` [Section titled “oscillation\_frequency”](#oscillation_frequency) ### `oscillation_frequency`method[#](#plasma_plots.accessors.ArrayAnalysis.oscillation_frequency) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3121-L3149 "src/plasma_plots/accessors.py:3121-3149") ``` def oscillation_frequency(window: tuple[float | None, float | None] = (None, None), method: str = 'zero_crossings', detrend: bool = True) ``` Measure the frequency of this oscillating time series from its zero crossings or peaks. Parameters | Name | Type | Default | Description | | --------- | -------------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `window` | `(float or None, float or None)` | `(None, None)` | The time interval `(t0, t1)` used; `None` for an open end. Default: every sample. | | `method` | `('zero_crossings', 'peaks')` | `"zero_crossings"` | Count the crossings of the mean (half a period apart), or the maxima (a period apart; for a signal that does not cross its mean, e.g. an energy, whose peaks are half the field’s period apart). Default: `"zero_crossings"`. | | `detrend` | `bool` | `True` | Subtract the mean over the window first, so that crossings are of the mean. Default: `True`. | Returns * `OscillationFit or None` `omega`, `period` and the `times` of the crossings or peaks used; `None` with fewer than two. See Also [`plasma_plots.analysis.oscillation_frequency()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.oscillation_frequency) : The function behind this method. [`ArrayAnalysis.damping_rate()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.damping_rate) : The decay of the same oscillation. Examples ```python >>> probe.plasma.analysis.oscillation_frequency(window=(5.0, 40.0)).omega ``` ### `map_coordinate` [Section titled “map\_coordinate”](#map_coordinate) ### `map_coordinate`method[#](#plasma_plots.accessors.ArrayAnalysis.map_coordinate) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3151-L3182 "src/plasma_plots/accessors.py:3151-3182") ``` def map_coordinate(dim: str, mapping, *, name: str | None = None, units: str | None = None, label: str | None = None) -> xr.DataArray ``` Replace a coordinate by a function of it, e.g. `eta1` by the minor radius in meters. Parameters | Name | Type | Default | Description | | --------- | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- | | `dim` | `str` | required | The dimension whose coordinate is mapped, e.g. `"eta1"`. | | `mapping` | `callable or float` | required | A function of the coordinate’s values (`lambda eta1: 0.1 + 0.9 * eta1`), or a factor (a length, for `length * eta1`). | | `name` | `str` | `None` | The name of the new dimension, e.g. `"r"`. Default: keep `dim`. | | `units` | `str` | `None` | The new coordinate’s units, e.g. `"m"`. Default: none. | | `label` | `str` | `None` | The new coordinate’s axis label (its `long_name`), mathtext allowed. Default: `name`. | Returns * `xarray.DataArray` The array over the new coordinate, which every plot then draws and labels. See Also [`plasma_plots.arrays.map_coordinate()`](/plasma-plots/api/plasma_plots/arrays/#plasma_plots.arrays.map_coordinate) : The function behind this method. Examples ```python >>> r_T = T.plasma.analysis.map_coordinate( ... "eta1", lambda eta1: 0.1 + 0.9 * eta1, name="r", units="m" ... ) >>> r_T.plasma.plot.profiles(x="r", eta2=0, eta3=0) ``` ### `envelope` [Section titled “envelope”](#envelope) ### `envelope`method[#](#plasma_plots.accessors.ArrayAnalysis.envelope) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3184-L3198 "src/plasma_plots/accessors.py:3184-3198") ``` def envelope() -> xr.DataArray ``` Return the local maxima of this time series. Returns * `xarray.DataArray` The peaks, over their times `t`. See Also [`plasma_plots.analysis.envelope()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.envelope) : The function behind this method. ### `norm` [Section titled “norm”](#norm) ### `norm`method[#](#plasma_plots.accessors.ArrayAnalysis.norm) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3200-L3218 "src/plasma_plots/accessors.py:3200-3218") ``` def norm(dims=None, squared: bool = False) -> xr.DataArray ``` Return the L2 norm over `dims` (default: every dimension except `t`). Parameters | Name | Type | Default | Description | | --------- | ------------------------ | ------- | ---------------------------------------------------------------- | | `dims` | `str or sequence of str` | `None` | The dimensions summed over. Default: every dimension except `t`. | | `squared` | `bool` | `False` | Return the squared norm `Σ f²` instead. Default: `False`. | Returns * `xarray.DataArray` The norm over the remaining dimensions, e.g. `t`. See Also [`plasma_plots.analysis.norm()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.norm) : The function behind this method. Examples ```python >>> div_B.plasma.analysis.norm() ``` ### `drift` [Section titled “drift”](#drift) ### `drift`method[#](#plasma_plots.accessors.ArrayAnalysis.drift) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3220-L3239 "src/plasma_plots/accessors.py:3220-3239") ``` def drift(ref=None) -> xr.DataArray ``` Return the signed deviation of this time series from `ref` or from its first sample. Parameters | Name | Type | Default | Description | | ----- | ----------------------------------------- | ------- | ---------------------------------------------------------------------------------- | | `ref` | `float or array_like or xarray.DataArray` | `None` | The reference, broadcast against `data`. Default: `data` at the first time sample. | Returns * `xarray.DataArray` The deviation over `t`. See Also [`plasma_plots.analysis.drift()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.drift) : The function behind this method. [`ArrayAnalysis.relative_error()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.relative_error) : The absolute relative deviation. Examples ```python >>> energy.plasma.analysis.drift().plasma.plot.timeseries() ``` ### `relative_error` [Section titled “relative\_error”](#relative_error) ### `relative_error`method[#](#plasma_plots.accessors.ArrayAnalysis.relative_error) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3241-L3260 "src/plasma_plots/accessors.py:3241-3260") ``` def relative_error(ref=None, skip_first: bool = True) -> xr.DataArray ``` Return the absolute relative deviation from `ref` or from this series’ first sample. Parameters | Name | Type | Default | Description | | ------------ | ----------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------- | | `ref` | `float or array_like or xarray.DataArray` | `None` | The reference, broadcast against `data`; must be non-zero everywhere. Default: `data` at the first time sample. | | `skip_first` | `bool` | `True` | Leave out the first time sample (zero against the default reference). Default: `True`. | Returns * `xarray.DataArray` The relative deviation over `t`. See Also [`plasma_plots.analysis.relative_error()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.relative_error) : The function behind this method. [`ArrayAnalysis.drift()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.drift) : The signed deviation. Examples ```python >>> energy.plasma.analysis.relative_error(ref=exact_solution) ``` ### `spatial_average` [Section titled “spatial\_average”](#spatial_average) ### `spatial_average`method[#](#plasma_plots.accessors.ArrayAnalysis.spatial_average) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3262-L3282 "src/plasma_plots/accessors.py:3262-3282") ``` def spatial_average(dims=None) -> xr.DataArray ``` Return the mean over the logical space dimensions `eta1`, `eta2`, `eta3` (or `dims`). For a binned `e1_v1` distribution this is f(v1, t) averaged over space. Parameters | Name | Type | Default | Description | | ------ | ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `dims` | `str or sequence of str` | `None` | The dimensions averaged over. Default: every logical dimension (`eta1`, `eta2`, `eta3`, or GVEC’s `rho`, `theta`, `zeta`) that `data` has. | Returns * `xarray.DataArray` The mean over the remaining dimensions. See Also [`plasma_plots.analysis.spatial_average()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.spatial_average) : The function behind this method. Examples ```python >>> distribution.plasma.analysis.spatial_average() ``` ### `velocity_moments` [Section titled “velocity\_moments”](#velocity_moments) ### `velocity_moments`method[#](#plasma_plots.accessors.ArrayAnalysis.velocity_moments) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3284-L3304 "src/plasma_plots/accessors.py:3284-3304") ``` def velocity_moments(dims=None) -> xr.Dataset ``` Return density, mean velocity and variance of a binned distribution over its velocity dimensions. See [`plasma_plots.analysis.velocity_moments()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.velocity_moments) for the definitions. Parameters | Name | Type | Default | Description | | ------ | ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `dims` | `str or sequence of str` | `None` | The velocity dimensions integrated over, each with a coordinate of at least two bins. Default: every one of `v1`, `v2`, `v3` that `f` has. | Returns * `xarray.Dataset` The moments, over the remaining dimensions. See Also [`plasma_plots.analysis.velocity_moments()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.velocity_moments) : The function behind this method. Examples ```python >>> distribution.plasma.analysis.velocity_moments() ``` ### `dispersion` [Section titled “dispersion”](#dispersion) ### `dispersion`method[#](#plasma_plots.accessors.ArrayAnalysis.dispersion) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3306-L3334 "src/plasma_plots/accessors.py:3306-3334") ``` def dispersion(dim: str | None = None, detrend: bool = True) -> xr.DataArray ``` Return the space-time power spectrum of this `(t, dim)` field. A plain FFT, as a function of angular frequency and wavenumber: the data behind a dispersion-relation plot ([`ArrayPlots.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.dispersion)). `dim` defaults to the sole dimension other than `t`; select every other dimension away first. `omega` comes out in the angular-frequency units implied by `t`’s spacing (e.g. rad/s for physical seconds, or a normalized angular frequency for normalized time). Parameters | Name | Type | Default | Description | | --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `dim` | `str` | `None` | The spatial dimension. Default: the sole dimension other than `t`. | | `detrend` | `bool` | `True` | Remove the time-mean at each point of `dim` first, which otherwise dominates the spectrum as a spurious zero-frequency line. Default: `True`. | Returns * `xarray.DataArray` The power over `omega` and the wavenumber. See Also [`plasma_plots.analysis.power_spectrum()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.power_spectrum) : The function behind this method, and the definition. [`ArrayPlots.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.dispersion) : The plot of this spectrum. [`ArrayAnalysis.fit_branches()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.fit_branches) : Straight branches fitted to it. Examples ```python >>> spectrum = E.isel(eta2=0, eta3=0).plasma.analysis.dispersion() ``` ### `fit_branches` [Section titled “fit\_branches”](#fit_branches) ### `fit_branches`method[#](#plasma_plots.accessors.ArrayAnalysis.fit_branches) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3336-L3371 "src/plasma_plots/accessors.py:3336-3371") ``` def fit_branches(n_branches: int, k_range: tuple[float, float] | None = None, noise_level: float = 0.5, order: int = 10) ``` Fit straight dispersion branches (`omega = v * k`) to this `(omega, k)` power spectrum. Parameters | Name | Type | Default | Description | | ------------- | ---------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n_branches` | `int` | required | The number of branches, at least 1. | | `k_range` | `(float, float)` | `None` | The interval of non-negative k’s that are scanned. Default: `(k.max() / 8, k.max() / 2)`, which in practice skips both the low-k region where branches have not yet separated, and the folded Nyquist edge. | | `noise_level` | `float` | `0.5` | Maxima count only above this fraction of the column’s peak power. Default: 0.5. | | `order` | `int` | `10` | A local maximum must exceed every one of its `order` neighbors on both sides along omega (out-of-range neighbors are clipped to the edge sample, as in `scipy.signal.argrelextrema`). Default: 10. | Returns * `list of BranchFit` One fit per branch. See Also [`plasma_plots.analysis.fit_dispersion_branches()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.fit_dispersion_branches) : The function behind this method. [`ArrayAnalysis.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.dispersion) : The spectrum to fit. [`ArrayAnalysis.trace_branch()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.trace_branch) : The measured frequency along a curved branch. Examples ```python >>> field.plasma.analysis.dispersion().plasma.analysis.fit_branches( ... n_branches=2 ... ) ``` ### `fft` [Section titled “fft”](#fft) ### `fft`method[#](#plasma_plots.accessors.ArrayAnalysis.fft) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3375-L3396 "src/plasma_plots/accessors.py:3375-3396") ``` def fft(dim: str, detrend: bool = False, window: str | None = None) -> xr.DataArray ``` Return the two-sided Fourier coefficients along `dim`. Parameters | Name | Type | Default | Description | | --------- | ---------------- | -------- | ------------------------------------------------------------------------------------------ | | `dim` | `str` | required | The dimension to transform. | | `detrend` | `bool` | `False` | Subtract the mean along `dim` first. Default: False. | | `window` | `(None, 'hann')` | `None` | Multiply by a periodic Hann window (see \[`hann()`]\[hann]) first. Default: None (boxcar). | Returns * `xarray.DataArray` The complex coefficients. See Also [`plasma_plots.spectral.fft()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.fft) : The function behind this method. [`ArrayAnalysis.time_fft()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.time_fft) : The one-sided transform in time. Examples ```python >>> phi.plasma.analysis.fft(dim="eta1") ``` ### `time_fft` [Section titled “time\_fft”](#time_fft) ### `time_fft`method[#](#plasma_plots.accessors.ArrayAnalysis.time_fft) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3398-L3419 "src/plasma_plots/accessors.py:3398-3419") ``` def time_fft(detrend: bool = False, window: str | None = None) -> xr.Dataset ``` Return the one-sided temporal coefficients and the power per bin. Parameters | Name | Type | Default | Description | | --------- | ---------------- | ------- | ------------------------------------------------------------------------------------------ | | `detrend` | `bool` | `False` | Subtract the temporal mean first. Default: False. | | `window` | `(None, 'hann')` | `None` | Multiply by a periodic Hann window (see \[`hann()`]\[hann]) first. Default: None (boxcar). | Returns * `xarray.Dataset` `coefficients` and `power` over `omega` and the other dimensions. See Also [`plasma_plots.spectral.time_fft()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.time_fft) : The function behind this method. [`ArrayPlots.power_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.power_spectrum) : The plot of the power. Examples ```python >>> phi.plasma.analysis.time_fft(detrend=True) ``` ### `filter_time` [Section titled “filter\_time”](#filter_time) ### `filter_time`method[#](#plasma_plots.accessors.ArrayAnalysis.filter_time) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3421-L3442 "src/plasma_plots/accessors.py:3421-3442") ``` def filter_time(dims=None, omega_min: float = 1e-08, pad_bins: int = 0) ``` Return the dominant frequency band, reconstructed. Parameters | Name | Type | Default | Description | | ----------- | ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `dims` | `str or sequence of str` | `None` | Non-time dimensions to sum the power over before choosing the band. Default: all dimensions except `t` and `component`. Pass `dims=()` for independent filtering at each point. | | `omega_min` | `float` | `1e-08` | Finite, positive lowest frequency considered, which excludes DC. Default: 1e-8. | | `pad_bins` | `int` | `0` | Nonnegative number of extra bins on each side of the band. Default: 0. | Returns * `TimeFilterResult` The band and the reconstructed signal. See Also [`plasma_plots.spectral.filter_time()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.filter_time) : The function behind this method. [`ArrayPlots.filtered()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.filtered) : A probe of the signal against the reconstruction. Examples ```python >>> band = phi.plasma.analysis.filter_time(dims=("eta1", "eta2", "eta3")) ``` ### `band_filter` [Section titled “band\_filter”](#band_filter) ### `band_filter`method[#](#plasma_plots.accessors.ArrayAnalysis.band_filter) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3444-L3465 "src/plasma_plots/accessors.py:3444-3465") ``` def band_filter(omega_lo: float, omega_hi: float, *, detrend: bool = False) -> xr.DataArray ``` Return only the frequencies in `[omega_lo, omega_hi]`. Parameters | Name | Type | Default | Description | | ---------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------- | | `omega_lo` | `float` | required | The lowest angular frequency kept. | | `omega_hi` | `float` | required | The highest angular frequency kept, at least `omega_lo`. | | `detrend` | `bool` | `False` | Subtract the temporal mean first; the result then has zero mean even if the band includes DC. Default: False. | Returns * `xarray.DataArray` The filtered signal, on this array’s grid. See Also [`plasma_plots.spectral.band_filter()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.band_filter) : The function behind this method. [`ArrayAnalysis.filter_time()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.filter_time) : The dominant band, found automatically. Examples ```python >>> phi.plasma.analysis.band_filter(0.08, 0.11) ``` ### `spectral_peaks` [Section titled “spectral\_peaks”](#spectral_peaks) ### `spectral_peaks`method[#](#plasma_plots.accessors.ArrayAnalysis.spectral_peaks) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3467-L3501 "src/plasma_plots/accessors.py:3467-3501") ``` def spectral_peaks(n_peaks: int = 3, dims=None, omega_min: float = 1e-08, detrend=True, window=None) -> xr.Dataset ``` Return the strongest spectral peaks, with sub-bin frequencies. Parameters | Name | Type | Default | Description | | ----------- | ------------------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n_peaks` | `int` | `3` | The number of peaks to return at most. Default: 3. | | `dims` | `str or sequence of str` | `None` | Dimensions to sum the power over. Default: every dimension but `omega`. Only `omega` may remain. | | `omega_min` | `float` | `1e-08` | The lowest frequency a peak may have, which excludes DC. Default: 1e-8. | | `detrend` | `bool or int` | `True` | For a time series: `True` subtracts the mean, `False` nothing, and an integer is the degree of a least-squares polynomial in `t` removed at every point first. An energy such as LinearMHD’s `en_U` oscillates at twice the wave frequency around a slow trend, so its peaks with `detrend=2` sit at `2 * omega`. Ignored for spectra. Default: True. | | `window` | `(None, 'hann')` | `None` | Window applied before transforming a time series. Default: None. | Returns * `xarray.Dataset` The peaks, strongest first. See Also [`plasma_plots.spectral.spectral_peaks()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.spectral_peaks) : The function behind this method. [`ArrayPlots.power_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.power_spectrum) : The spectrum with the peaks labeled (`peaks=`). Examples ```python >>> phi.plasma.analysis.spectral_peaks(n_peaks=2) ``` ### `spectrogram` [Section titled “spectrogram”](#spectrogram) ### `spectrogram`method[#](#plasma_plots.accessors.ArrayAnalysis.spectrogram) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3503-L3526 "src/plasma_plots/accessors.py:3503-3526") ``` def spectrogram(length, step=None, detrend: bool = True, window: str | None = 'hann') -> xr.DataArray ``` Return power spectra in sliding time windows. Parameters | Name | Type | Default | Description | | --------- | ---------------- | -------- | ----------------------------------------------------------------------------------------------------------- | | `length` | `int or float` | required | The window length: a sample count (integer, 4 to the number of samples) or a time span (float). | | `step` | `int or float` | `None` | The shift between windows: a sample count (integer) or a time span (float). Default: a quarter of `length`. | | `detrend` | `bool` | `True` | Subtract each window’s mean. Default: True. | | `window` | `('hann', None)` | `"hann"` | The taper of each window, not compensated for. Default: `"hann"`. | Returns * `xarray.DataArray` The power over `(t, omega, ...)`, `t` being each window’s center. See Also [`plasma_plots.spectral.spectrogram()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.spectrogram) : The function behind this method. [`ArrayPlots.spectrogram()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.spectrogram) : The plot of these spectra. Examples ```python >>> signal.plasma.analysis.spectrogram(length=200.0, step=10.0) ``` ### `mode_spectrum` [Section titled “mode\_spectrum”](#mode_spectrum) ### `mode_spectrum`method[#](#plasma_plots.accessors.ArrayAnalysis.mode_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3528-L3551 "src/plasma_plots/accessors.py:3528-3551") ``` def mode_spectrum(dims=None, names=('m', 'n'), periods=None, scale=None) -> xr.DataArray ``` Return the complex amplitudes over poloidal/toroidal mode numbers. Parameters | Name | Type | Default | Description | | --------- | ---------------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `dims` | `str or sequence of str` | `None` | The periodic dimensions to transform. Default: the two angles of the logical dimensions (see [`plasma_plots.arrays.logical_dims()`](/plasma-plots/api/plasma_plots/arrays/#plasma_plots.arrays.logical_dims)), `("eta2", "eta3")` for Struphy. | | `names` | `str or sequence of str` | `('m', 'n')` | The name of the mode number of each dimension, one per dimension. Default: `("m", "n")`. | | `periods` | `float or sequence of float` | `None` | Each direction’s period in its coordinate: one number for all, or one per dimension. Default: the coordinate’s `period` attribute (see [`plasma_plots.arrays.angle_period()`](/plasma-plots/api/plasma_plots/arrays/#plasma_plots.arrays.angle_period)), else 1.0. | | `scale` | `int or sequence of int` | `None` | Multiplies the mode numbers (one number, or one per dimension; cast to integers), e.g. `scale=(1, 6)` labels a sixth of a torus (Struphy’s `tor_period=6`) with full-torus toroidal mode numbers. Default: 2π over the `period` attribute of an angle (nfp for GVEC’s toroidal angle), else 1. | Returns * `xarray.DataArray` The amplitudes over the mode numbers `names` and every remaining dimension. See Also [`plasma_plots.spectral.mode_spectrum()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.mode_spectrum) : The function behind this method. [`ArrayAnalysis.mode_amplitudes()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.mode_amplitudes) : Real amplitudes of this spectrum. Examples ```python >>> modes = phi.plasma.analysis.mode_spectrum() ``` ### `mode_amplitudes` [Section titled “mode\_amplitudes”](#mode_amplitudes) ### `mode_amplitudes`method[#](#plasma_plots.accessors.ArrayAnalysis.mode_amplitudes) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3553-L3574 "src/plasma_plots/accessors.py:3553-3574") ``` def mode_amplitudes(top: int | None = None, real: bool = True, relative: bool = False) -> xr.DataArray ``` Return the real amplitudes of this mode spectrum along one `mode` dimension. Parameters | Name | Type | Default | Description | | ---------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `top` | `int` | `None` | Keep only the `top` modes with the largest peak amplitude over every other dimension, strongest first. Default: all modes. | | `real` | `bool` | `True` | The field is real: each `(m, n)` is combined with its conjugate `(-m, -n)`. Only the half with the first nonzero mode number positive is kept, and its amplitude doubled, so a field `A cos(...)` gives `A`. A mode without a twin on the grid (the mean, or the Nyquist mode of an even grid) is kept as it is. Default: True. | | `relative` | `bool` | `False` | Divide by the amplitude of the mean (the mode with all numbers zero), which is then left out: e.g. density perturbations relative to the background density, as growth plots of an instability often show. NaN where the mean vanishes. Default: False. | Returns * `xarray.DataArray` The amplitudes over `mode` and every remaining dimension. See Also [`plasma_plots.spectral.mode_amplitudes()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.mode_amplitudes) : The function behind this method. [`ArrayAnalysis.mode_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.mode_spectrum) : The spectrum this is applied to. Examples ```python >>> phi.plasma.analysis.mode_spectrum().plasma.analysis.mode_amplitudes(top=4) ``` ### `mode_structure` [Section titled “mode\_structure”](#mode_structure) ### `mode_structure`method[#](#plasma_plots.accessors.ArrayAnalysis.mode_structure) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3576-L3597 "src/plasma_plots/accessors.py:3576-3597") ``` def mode_structure(omega: float, *, window: str | None = 'hann', detrend: bool = True) -> xr.DataArray ``` Return the complex amplitude at the exact frequency `omega` at every point. Parameters | Name | Type | Default | Description | | --------- | ---------------- | -------- | --------------------------------------------------------------------------------------------- | | `omega` | `float` | required | The angular frequency ω. | | `window` | `('hann', None)` | `"hann"` | The weights `w(t)`: a periodic Hann window, or `None` for uniform weights. Default: `"hann"`. | | `detrend` | `bool` | `True` | Subtract the temporal mean at every point first. Default: True. | Returns * `xarray.DataArray` The complex amplitude over every dimension but `t`. See Also [`plasma_plots.spectral.mode_structure()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.mode_structure) : The function behind this method. [`ArrayPlots.mode_profiles()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.mode_profiles) : The harmonics of this eigenfunction (`omega=`). Examples ```python >>> phi.plasma.analysis.mode_structure(omega) ``` ### `cross_spectrum` [Section titled “cross\_spectrum”](#cross_spectrum) ### `cross_spectrum`method[#](#plasma_plots.accessors.ArrayAnalysis.cross_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3599-L3627 "src/plasma_plots/accessors.py:3599-3627") ``` def cross_spectrum(other: xr.DataArray, *, dims=None, detrend: bool = True, window=None) -> xr.Dataset ``` Return the cross-spectrum, phase (of `other` relative to this) and coherence. Parameters | Name | Type | Default | Description | | --------- | ------------------------ | -------- | ------------------------------------------------------------------------------------------ | | `other` | `xarray.DataArray` | required | The second signal, on the same time grid; its phase is relative to this one. | | `dims` | `str or sequence of str` | `None` | Dimensions to sum the cross-spectrum over, as an ensemble. Default: none (no `coherence`). | | `detrend` | `bool` | `True` | Subtract each signal’s temporal mean first. Default: True. | | `window` | `(None, 'hann')` | `None` | Window applied to both signals before transforming. Default: None. | Returns * `xarray.Dataset` The cross-spectrum, phase and (with `dims`) coherence over `omega`. See Also [`plasma_plots.spectral.cross_spectrum()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.cross_spectrum) : The function behind this method. [`ArrayPlots.cross_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.cross_spectrum) : The plot of this spectrum. Examples ```python >>> u.plasma.analysis.cross_spectrum(b, dims="eta3") ``` ### `matrix_pencil` [Section titled “matrix\_pencil”](#matrix_pencil) ### `matrix_pencil`method[#](#plasma_plots.accessors.ArrayAnalysis.matrix_pencil) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3629-L3652 "src/plasma_plots/accessors.py:3629-3652") ``` def matrix_pencil(n_modes: int = 1, pencil: int | None = None, detrend: bool = False) -> xr.Dataset ``` Return frequencies and growth rates beyond the FFT resolution. Parameters | Name | Type | Default | Description | | --------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `n_modes` | `int` | `1` | The number of modes to fit and return: real oscillations for a real signal, complex exponentials for a complex one. The fit needs well over `2 * n_modes` samples. Default: 1. | | `pencil` | `int` | `None` | The pencil parameter (Hankel matrix width minus one), which trades noise robustness against resolution. Default: `N // 2`. | | `detrend` | `bool` | `False` | Subtract the mean first. Default: False. | Returns * `xarray.Dataset` `omega`, `gamma`, `amplitude` and `phase` along `mode`, strongest first. See Also [`plasma_plots.spectral.matrix_pencil()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.matrix_pencil) : The function behind this method. [`ArrayPlots.pencil_fit()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.pencil_fit) : The plot of this fit. Examples ```python >>> probe.plasma.analysis.matrix_pencil(n_modes=1) ``` ### `gradient` [Section titled “gradient”](#gradient) ### `gradient`method[#](#plasma_plots.accessors.ArrayAnalysis.gradient) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3654-L3672 "src/plasma_plots/accessors.py:3654-3672") ``` def gradient(domain=None) -> xr.DataArray ``` Return the Cartesian gradient of this scalar field on a mapped domain. Parameters | Name | Type | Default | Description | | -------- | ---------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | `domain` | `struphy domain` | `None` | The mapping (`out.domain`), for the exact Jacobian. Default: differentiate the `X`, `Y`, `Z` coordinates numerically. | Returns * `xarray.DataArray` The gradient, with a `component` dimension `(x, y, z)`. See Also [`plasma_plots.analysis.gradient()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.gradient) : The function behind this method. Examples ```python >>> phi.plasma.analysis.gradient() ``` ### `surface_average` [Section titled “surface\_average”](#surface_average) ### `surface_average`method[#](#plasma_plots.accessors.ArrayAnalysis.surface_average) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3674-L3697 "src/plasma_plots/accessors.py:3674-3697") ``` def surface_average(jacobian=None, domain=None, quadrature=None) -> xr.DataArray ``` Return the flux-surface average of this field over its two angles. Parameters | Name | Type | Default | Description | | ------------ | ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `jacobian` | `xarray.DataArray` | `None` | `√g` on the same grid, e.g. GVEC’s `Jac` (its absolute value is used). Default: from `domain`, else the numerical Jacobian of the `X`, `Y`, `Z` coordinates, which needs at least two radial points. | | `domain` | `struphy domain` | `None` | The mapping, for the exact `√g` of a Struphy run. | | `quadrature` | `dict` | `None` | Explicit weights for the angles, as for \[`volume_integral()`]\[volume\_integral]. | Returns * `xarray.DataArray` `⟨f⟩` over the radius and every non-spatial dimension. See Also [`plasma_plots.analysis.surface_average()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.surface_average) : The function behind this method. [`DatasetAnalysis.surface_average()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.surface_average) : The same, with the Dataset’s `Jac`. Examples ```python >>> ev.mod_B.plasma.analysis.surface_average(jacobian=ev.Jac) ``` ### `rational_surfaces` [Section titled “rational\_surfaces”](#rational_surfaces) ### `rational_surfaces`method[#](#plasma_plots.accessors.ArrayAnalysis.rational_surfaces) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3699-L3722 "src/plasma_plots/accessors.py:3699-3722") ``` def rational_surfaces(count: int = 4, nfp: int | None = None, max_denominator: int = 12) -> xr.DataArray ``` Return where this rotational transform (or safety factor) profile is a low-order rational. Parameters | Name | Type | Default | Description | | ----------------- | ----- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `count` | `int` | `4` | The number of rational values. Default: 4. | | `nfp` | `int` | `None` | The numerators are multiples of it. Default: the profile’s `nfp` attribute (GVEC’s, see [`plasma_plots.gvec.from_gvec()`](/plasma-plots/api/plasma_plots/gvec/#plasma_plots.gvec.from_gvec)), else 1. | | `max_denominator` | `int` | `12` | The largest `m`. Default: 12. | Returns * `xarray.DataArray` The positions over `surface`, with the coordinates `n`, `m` and `value`. See Also [`plasma_plots.analysis.rational_surfaces()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.rational_surfaces) : The function behind this method. [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout) : `rationals=` marks them on the profile. Examples ```python >>> ev.iota.plasma.analysis.rational_surfaces(count=3) ``` ### `error` [Section titled “error”](#error) ### `error`method[#](#plasma_plots.accessors.ArrayAnalysis.error) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3724-L3762 "src/plasma_plots/accessors.py:3724-3762") ``` def error(exact, *, norm: str = 'rms', relative: bool = False, dims=None, weighted: bool = False, domain=None, args=None) -> xr.DataArray ``` Return the error against an exact solution (an array or a function of the coordinates). Parameters | Name | Type | Default | Description | | ---------- | ---------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `exact` | `(callable, array_like, number or xarray.DataArray)` | required | The exact solution: an array (aligned with `data`, or broadcast to it) or a function of its coordinates, evaluated with \[`evaluate_on()`]\[evaluate\_on], e.g. `lambda x, y, z, t: ...`. | | `norm` | `('rms', 'max', 'l1', 'l2', 'pointwise')` | `"rms"` | `"pointwise"` is the difference `data − exact` itself; `"max"` the largest absolute difference; `"l1"` the mean (or, weighted, the integral) of `\|data − exact\|`; `"l2"` the square root of the mean (or integral) of `\|data − exact\|²`; `"rms"` (default) as `"l2"`, divided by the volume when weighted. | | `relative` | `bool` | `False` | Divide by the same norm of the exact solution; for `"pointwise"`, by the largest `\|exact\|` over the whole array. Default: `False`. | | `dims` | `str or sequence of str` | `None` | The dimensions the norm is taken over. Default: every dimension but `t`. Weighted norms need exactly `eta1`, `eta2`, `eta3`. | | `weighted` | `bool` | `False` | Integrate over the physical volume instead of averaging over the grid points (no effect on `"max"` and `"pointwise"`). Default: `False`. | | `domain` | `struphy domain` | `None` | The mapping (`out.domain`), for the exact `\|√g\|` of weighted norms. Default: from the `X`, `Y`, `Z` coordinates. | | `args` | `sequence of str` | `None` | The coordinates passed to a callable `exact`, as in \[`evaluate_on()`]\[evaluate\_on]. Default: `X`, `Y`, `Z` (or the logical dimensions), then `t`. | Returns * `xarray.DataArray` The error, over the dimensions not reduced by `norm`. See Also [`plasma_plots.analysis.error()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.error) : The function behind this method. Examples ```python >>> T.plasma.analysis.error(exact, relative=True) >>> T.plasma.analysis.error(exact, norm="max") ``` ### `project_mode` [Section titled “project\_mode”](#project_mode) ### `project_mode`method[#](#plasma_plots.accessors.ArrayAnalysis.project_mode) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3764-L3797 "src/plasma_plots/accessors.py:3764-3797") ``` def project_mode(dim: str, number: float, kind: str = 'sin', period: float = 1.0, bin_correction: bool = False) -> xr.DataArray ``` Return the amplitude of one Fourier mode along `dim`. Parameters | Name | Type | Default | Description | | ---------------- | --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `dim` | `str` | required | The periodic dimension, e.g. `"eta1"`. | | `number` | `float` | required | The mode number, not a wavenumber: `k = 2π number / L`. | | `kind` | `('sin', 'cos', 'complex')` | `"sin"` | `"sin"` (default) gives `a` of `a sin(2π number x / period)`: `2 ⟨f sin(…)⟩`; `"cos"` the cosine amplitude, and `"complex"` the complex amplitude `2 ⟨f exp(−i…)⟩` (`abs()` the amplitude, `np.angle()` the phase). | | `period` | `float` | `1.0` | The period of `dim`. Default: 1, the logical unit interval. | | `bin_correction` | `bool` | `False` | Undo the damping of binned particle data, whose bins average the mode over their width `h`: divide by `sinc(number h / period)`. Default: `False`. | Returns * `xarray.DataArray` The amplitude over the other dimensions. See Also [`plasma_plots.analysis.project_mode()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.project_mode) : The function behind this method. Examples ```python >>> rho.plasma.analysis.project_mode(dim="eta2", number=3, kind="complex") ``` ### `divergence` [Section titled “divergence”](#divergence) ### `divergence`method[#](#plasma_plots.accessors.ArrayAnalysis.divergence) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3799-L3817 "src/plasma_plots/accessors.py:3799-3817") ``` def divergence(components: str = 'cartesian', domain=None) -> xr.DataArray ``` Return the divergence of this vector field. Parameters | Name | Type | Default | Description | | ------------ | -------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | `components` | `('cartesian', 'contravariant')` | `"cartesian"` | What the components are, as for the 3-D views: `"cartesian"` (default) `(x, y, z)`, or `"contravariant"` components, which are pushed forward first. | | `domain` | `struphy domain` | `None` | The mapping (`out.domain`), for the exact Jacobian. Default: from the `X`, `Y`, `Z` coordinates. | Returns * `xarray.DataArray` The divergence, without the `component` dimension. See Also [`plasma_plots.analysis.divergence()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.divergence) : The function behind this method. Examples ```python >>> B.plasma.analysis.divergence() ``` ### `curl` [Section titled “curl”](#curl) ### `curl`method[#](#plasma_plots.accessors.ArrayAnalysis.curl) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3819-L3837 "src/plasma_plots/accessors.py:3819-3837") ``` def curl(components: str = 'cartesian', domain=None) -> xr.DataArray ``` Return the curl of this vector field, in Cartesian components. Parameters | Name | Type | Default | Description | | ------------ | -------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------ | | `components` | `('cartesian', 'contravariant')` | `"cartesian"` | What the components are: `"cartesian"` (default) `(x, y, z)`, or `"contravariant"` components, which are pushed forward first. | | `domain` | `struphy domain` | `None` | The mapping (`out.domain`), for the exact Jacobian. Default: from the `X`, `Y`, `Z` coordinates. | Returns * `xarray.DataArray` The curl, with a `component` dimension. See Also [`plasma_plots.analysis.curl()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.curl) : The function behind this method. Examples ```python >>> B.plasma.analysis.curl() ``` ### `flux_function` [Section titled “flux\_function”](#flux_function) ### `flux_function`method[#](#plasma_plots.accessors.ArrayAnalysis.flux_function) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3839-L3857 "src/plasma_plots/accessors.py:3839-3857") ``` def flux_function() -> xr.DataArray ``` Return the flux (or stream) function of this 2-D in-plane field. Returns * `xarray.DataArray` The flux function, without the `component` dimension. See Also [`plasma_plots.analysis.flux_function()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.flux_function) : The function behind this method. Examples ```python >>> B.plasma.analysis.flux_function() ``` ### `cylindrical_components` [Section titled “cylindrical\_components”](#cylindrical_components) ### `cylindrical_components`method[#](#plasma_plots.accessors.ArrayAnalysis.cylindrical_components) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3859-L3878 "src/plasma_plots/accessors.py:3859-3878") ``` def cylindrical_components() -> xr.DataArray ``` Return the Cartesian components rotated to `(R, phi, Z)`. Returns * `xarray.DataArray` The vector field in cylindrical components. See Also [`plasma_plots.analysis.cylindrical_components()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.cylindrical_components) : The function behind this method. [`ArrayAnalysis.toroidal_components()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.toroidal_components) : Components about a magnetic axis. Examples ```python >>> E.plasma.analysis.cylindrical_components() ``` ### `toroidal_components` [Section titled “toroidal\_components”](#toroidal_components) ### `toroidal_components`method[#](#plasma_plots.accessors.ArrayAnalysis.toroidal_components) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3880-L3899 "src/plasma_plots/accessors.py:3880-3899") ``` def toroidal_components(R0: float, Z0: float = 0.0) -> xr.DataArray ``` Return the Cartesian components rotated to `(radial, poloidal, toroidal)` about an axis at `R0`. Parameters | Name | Type | Default | Description | | ---- | ------- | -------- | -------------------------------------------- | | `R0` | `float` | required | The major radius of the magnetic axis. | | `Z0` | `float` | `0.0` | The height of the magnetic axis. Default: 0. | Returns * `xarray.DataArray` The vector field in toroidal components. See Also [`plasma_plots.analysis.toroidal_components()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.toroidal_components) : The function behind this method. [`ArrayAnalysis.cylindrical_components()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.cylindrical_components) : Components about the `Z` axis. Examples ```python >>> u.plasma.analysis.toroidal_components(R0=3.0) ``` ### `polar_coordinates` [Section titled “polar\_coordinates”](#polar_coordinates) ### `polar_coordinates`method[#](#plasma_plots.accessors.ArrayAnalysis.polar_coordinates) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3901-L3919 "src/plasma_plots/accessors.py:3901-3919") ``` def polar_coordinates(center=(0.0, 0.0)) -> xr.DataArray ``` Return this array with coordinates `r` and `theta` in the `X`-`Y` plane. Parameters | Name | Type | Default | Description | | -------- | ---------------- | ------------ | -------------------------------------------------------------------- | | `center` | `(float, float)` | `(0.0, 0.0)` | The origin `(X, Y)` of the polar coordinates. Default: `(0.0, 0.0)`. | Returns * `xarray.DataArray` This array with the added coordinates. See Also [`plasma_plots.analysis.polar_coordinates()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.polar_coordinates) : The function behind this method. Examples ```python >>> n.plasma.analysis.polar_coordinates(center=(0.0, 0.0)) ``` ### `trace_branch` [Section titled “trace\_branch”](#trace_branch) ### `trace_branch`method[#](#plasma_plots.accessors.ArrayAnalysis.trace_branch) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3921-L3946 "src/plasma_plots/accessors.py:3921-3946") ``` def trace_branch(theory, *, window: float = 0.2, k_range=None, threshold: float = 0.001) -> xr.Dataset ``` Return the measured frequency of a dispersion branch near `theory(k)` in this `(omega, k)` spectrum. Parameters | Name | Type | Default | Description | | ----------- | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `theory` | `callable` | required | The expected branch `omega(k)`, applied to an array of `k`; of a complex frequency (as [`plasma_plots.theory`](/plasma-plots/api/plasma_plots/theory/) returns), the real part is used. | | `window` | `float` | `0.2` | The relative half-width of the search window about the theory. Default: 0.2. | | `k_range` | `(float, float)` | `None` | The `k` interval to trace (negative `k` are never traced). Default: every `k >= 0`. | | `threshold` | `float` | `0.001` | Maxima weaker than this times the strongest one found count as no wave. Default: 1e-3. | Returns * `xarray.Dataset` The measured branch over `k`. See Also [`plasma_plots.spectral.trace_branch()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.trace_branch) : The function behind this method. [`ArrayPlots.against_theory()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.against_theory) : The measured frequencies against the theory. Examples ```python >>> spectrum.plasma.analysis.trace_branch( ... bohm_gross, window=0.2, k_range=(1.5, 5.5) ... ) ``` ### `drop_periodic_endpoint` [Section titled “drop\_periodic\_endpoint”](#drop_periodic_endpoint) ### `drop_periodic_endpoint`method[#](#plasma_plots.accessors.ArrayAnalysis.drop_periodic_endpoint) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3948-L3962 "src/plasma_plots/accessors.py:3948-3962") ``` def drop_periodic_endpoint(dim: str, *, period: float = 1.0) -> xr.DataArray ``` Return this array without a duplicated periodic endpoint along `dim`. Parameters | Name | Type | Default | Description | | -------- | ------- | -------- | ---------------------------------------------------- | | `dim` | `str` | required | The periodic dimension. | | `period` | `float` | `1.0` | The period in the coordinate of `dim`. Default: 1.0. | Returns * `xarray.DataArray` This array, one point shorter along `dim` if its last point repeats the first. See Also [`plasma_plots.spectral.drop_periodic_endpoint()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.drop_periodic_endpoint) : The function behind this method. ### `field_lines` [Section titled “field\_lines”](#field_lines) ### `field_lines`method[#](#plasma_plots.accessors.ArrayAnalysis.field_lines) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L3964-L4022 "src/plasma_plots/accessors.py:3964-4022") ``` def field_lines(seeds=8, turns: float | None = None, length: float | None = None, step: float | None = None, direction: str = 'forward', section: float | None = None, stride: int | None = None, components: str = 'cartesian', **selection) -> xr.Dataset ``` Trace field lines of this vector field through its mapped grid. Parameters | Name | Type | Default | Description | | ------------- | ------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `seeds` | `(int, dict, array_like or xarray.Dataset)` | `8` | Where the lines start, in logical coordinates: a number of seeds spread along the radial coordinate at the first poloidal and toroidal grid values (the outboard midplane of a torus whose angles start at 0); a dict of logical coordinates to values or 1-D arrays, which are combined into a grid of seeds (e.g. `{"rho": 0.95, "theta": thetas, "zeta": zetas}` for a connection-length map; a missing coordinate takes its first grid value); an `(n, 3)` array of points in the order of the logical dimensions; or a Dataset with one variable per logical coordinate. Default: 8. | | `turns` | `float` | `None` | Stop a line after this many toroidal transits (turns of the torus: nfp periods of the toroidal logical coordinate, i.e. 2π of GVEC’s toroidal angle, one period of Struphy’s `eta3`). Default: 20 when the toroidal direction wraps around, else none. | | `length` | `float` | `None` | Stop a line after this arc length, in the units of `X`, `Y`, `Z`. Default: with `turns`, 1.5 times the length `turns` circles through the seeds’ mean major radius would take (a safety net); without, four times the grid’s extent. | | `step` | `float` | `None` | The step of arc length of the integrator. Default: the median spacing of the grid points (trilinear interpolation limits the accuracy before the step does). | | `direction` | `('forward', 'backward', 'both')` | `"forward"` | Along the field, against it, or each seed in both directions (two lines per seed, with the coordinates `seed` and `direction` telling them apart; the connection length is then the sum of both). Default: `"forward"`. | | `section` | `float` | `None` | The toroidal logical coordinate of the poloidal plane whose punctures are recorded. Default: the first toroidal grid value (e.g. `zeta = 0`). | | `stride` | `int` | `None` | Save every `stride`-th step of each line. Default: as many as keep each line at about 20 000 samples at most; the punctures, transits and lengths count every step regardless. | | `components` | `('cartesian', 'contravariant')` | `"cartesian"` | What the components are: `"cartesian"` (default) `(x, y, z)`, or contravariant logical components, as for [`plasma_plots.analysis.divergence()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.divergence). | | `**selection` | | `{}` | The other dimensions, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `xarray.Dataset` The lines over `(s, line)` with their punctures, rotational transforms and connection lengths; it has `.plasma.plot.poincare()`, `.footprint()` and the other field-line plots. See Also [`plasma_plots.fieldlines.trace_field_lines()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.trace_field_lines) : The function behind this method. [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) : The Poincaré plot of the lines. [`ArrayAnalysis.sample_along()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.sample_along) : A field along them. Examples ```python >>> lines = B.plasma.analysis.field_lines(seeds=12, turns=100, t=-1) >>> lines.plasma.plot.poincare(color_by="iota") >>> edge = B.plasma.analysis.field_lines( ... seeds={"eta1": 0.98, "eta2": np.linspace(0, 1, 32)}, ... direction="both", ... t=-1, ... ) ``` ### `sample_along` [Section titled “sample\_along”](#sample_along) ### `sample_along`method[#](#plasma_plots.accessors.ArrayAnalysis.sample_along) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4024-L4045 "src/plasma_plots/accessors.py:4024-4045") ``` def sample_along(lines: xr.Dataset) -> xr.DataArray ``` Return this scalar field interpolated along traced field lines. Parameters | Name | Type | Description | | ------- | ---------------- | ------------------------------------------------------------ | | `lines` | `xarray.Dataset` | The lines of \[`trace_field_lines()`]\[trace\_field\_lines]. | Returns * `xarray.DataArray` The field over `(s, line)` after its other dimensions. See Also [`plasma_plots.fieldlines.sample_along()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.sample_along) : The function behind this method. [`ArrayAnalysis.parallel_wavenumber()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.parallel_wavenumber) : The dominant wavenumber along each line. [`ArrayPlots.along_field_lines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.along_field_lines) : The plot. Examples ```python >>> along = phi.plasma.analysis.sample_along(lines) >>> along.isel(line=0).plasma.plot.slice(x="s", y="t") ``` ### `parallel_wavenumber` [Section titled “parallel\_wavenumber”](#parallel_wavenumber) ### `parallel_wavenumber`method[#](#plasma_plots.accessors.ArrayAnalysis.parallel_wavenumber) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4047-L4079 "src/plasma_plots/accessors.py:4047-4079") ``` def parallel_wavenumber(lines: xr.Dataset | None = None, method: str = 'fft', detrend: bool = True) -> xr.DataArray ``` Return the dominant parallel wavenumber of this field along field lines. Parameters | Name | Type | Default | Description | | --------- | ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `lines` | `xarray.Dataset` | `None` | Traced lines to sample this field along first. Default: this array already is the samples of [`sample_along()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.sample_along), over `(s, line)`. | | `method` | `('fft', 'crossings')` | `"fft"` | How to estimate it. Default: `"fft"`. | | `detrend` | `bool` | `True` | Remove the mean along each line first. Default: True. | Returns * `xarray.DataArray` `k_parallel` over `line` and the other dimensions. See Also [`plasma_plots.fieldlines.parallel_wavenumber()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.parallel_wavenumber) : The function behind this method. [`plasma_plots.theory.waves.parallel_wavenumber()`](/plasma-plots/api/plasma_plots/theory/waves/#plasma_plots.theory.waves.parallel_wavenumber) : The expected `(n + m/q)/R₀`. Examples ```python >>> phi.plasma.analysis.parallel_wavenumber(lines=lines) ``` ### `boozer_spectrum` [Section titled “boozer\_spectrum”](#boozer_spectrum) ### `boozer_spectrum`method[#](#plasma_plots.accessors.ArrayAnalysis.boozer_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4081-L4103 "src/plasma_plots/accessors.py:4081-4103") ``` def boozer_spectrum(top: int | None = None, angles: str = 'boozer') -> xr.DataArray ``` Return the Boozer harmonics `B_mn` of this quantity over the radius. Parameters | Name | Type | Default | Description | | -------- | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `top` | `int` | `None` | Keep only the `top` harmonics with the largest peak amplitude over the radius, strongest first. Default: all. | | `angles` | `('boozer', 'any')` | `"boozer"` | Require the Boozer angles `theta_B`, `zeta_B` (default), or take the harmonics in whatever angles the field has (not a Boozer spectrum then; e.g. for a comparison). | Returns * `xarray.DataArray` The real amplitudes over `mode` (with `m`, `n`) and the radius. See Also [`plasma_plots.analysis.boozer_spectrum()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.boozer_spectrum) : The function behind this method. [`ArrayAnalysis.quasisymmetry_error()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.quasisymmetry_error) : The symmetry-breaking part. [`ArrayPlots.boozer_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.boozer_spectrum) : The plot. Examples ```python >>> boozer.mod_B.plasma.analysis.boozer_spectrum(top=8) ``` ### `quasisymmetry_error` [Section titled “quasisymmetry\_error”](#quasisymmetry_error) ### `quasisymmetry_error`method[#](#plasma_plots.accessors.ArrayAnalysis.quasisymmetry_error) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4105-L4126 "src/plasma_plots/accessors.py:4105-4126") ``` def quasisymmetry_error(helicity='QA', angles: str = 'boozer') -> xr.DataArray ``` Return the quasi-symmetry error of this `|B|` on each flux surface. Parameters | Name | Type | Default | Description | | ---------- | -------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `helicity` | `('QA', 'QP', 'QH')` | `"QA"` | The symmetry: a name, or `(M, N)` with `N` a full-torus toroidal mode number (its sign picks the handedness). Default: `"QA"`. | | `angles` | `('boozer', 'any')` | `"boozer"` | As for [`boozer_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.boozer_spectrum). | Returns * `xarray.DataArray` `f_QS` over the radius. See Also [`plasma_plots.analysis.quasisymmetry_error()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.quasisymmetry_error) : The function behind this method. [`ArrayAnalysis.boozer_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.boozer_spectrum) : The harmonics it is computed from. Examples ```python >>> boozer.mod_B.plasma.analysis.quasisymmetry_error(helicity="QH") ``` ### `critical_points` [Section titled “critical\_points”](#critical_points) ### `critical_points`method[#](#plasma_plots.accessors.ArrayAnalysis.critical_points) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4128-L4148 "src/plasma_plots/accessors.py:4128-4148") ``` def critical_points(refine: bool = True) -> xr.Dataset ``` Return the O-points and X-points of this flux function (at every time). Parameters | Name | Type | Default | Description | | -------- | ------ | ------- | ------------------------------------------------------------------------------------------------ | | `refine` | `bool` | `True` | Locate the zero within the cell by Newton’s method (the cell’s centre otherwise). Default: True. | Returns * `xarray.Dataset` The points over `point` (and `t`): positions, values and kinds. See Also [`plasma_plots.analysis.critical_points()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.critical_points) : The function behind this method. [`ArrayAnalysis.reconnected_flux()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.reconnected_flux) : The flux between them over time. [`ArrayPlots.critical_points()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.critical_points) : The plot. Examples ```python >>> B.plasma.analysis.flux_function().plasma.analysis.critical_points() ``` ### `reconnected_flux` [Section titled “reconnected\_flux”](#reconnected_flux) ### `reconnected_flux`method[#](#plasma_plots.accessors.ArrayAnalysis.reconnected_flux) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4150-L4176 "src/plasma_plots/accessors.py:4150-4176") ``` def reconnected_flux(relative: bool = True, o_point=None, x_point=None) -> xr.DataArray ``` Return the reconnected flux over time: this flux function between an O- and an X-point. Parameters | Name | Type | Default | Description | | ---------- | ---------------- | ------- | ------------------------------------------------------------------------------------------- | | `relative` | `bool` | `True` | Subtract the value at the first time. Default: True. | | `o_point` | `(float, float)` | `None` | The logical coordinates near which to look for the O-point. Default: the dominant island’s. | | `x_point` | `(float, float)` | `None` | The same for the X-point. | Returns * `xarray.DataArray` `ΔΨ(t)`. See Also [`plasma_plots.analysis.reconnected_flux()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.reconnected_flux) : The function behind this method. [`ArrayAnalysis.growth_rate()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.growth_rate) : Its growth rate. Examples ```python >>> A = B.plasma.analysis.flux_function() >>> A.plasma.analysis.reconnected_flux().plasma.plot.timeseries( ... fit=(10.0, 30.0) ... ) ``` # array.plasma.data > The selected data behind every plot, without drawing it. Every plot on `array.plasma.plot` has a twin here, as `array.plasma.data.(...)`, that does the same selection and returns the labeled `xarray` object instead of a figure. See the [Selecting data](/plasma-plots/guides/data/) guide. Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## array.plasma.data [Section titled “array.plasma.data”](#arrayplasmadata) The data behind each plot in :class:`ArrayPlots`, without rendering it. ### `lineout` [Section titled “lineout”](#lineout) ### `lineout`method[#](#plasma_plots.accessors.ArrayData.lineout) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2582-L2616 "src/plasma_plots/accessors.py:2582-2616") ``` def lineout(x: str | None = None, **selection) -> xr.DataArray ``` Return the 1-D profile [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout) would plot. Parameters | Name | Type | Default | Description | | ------------- | ----- | ------- | ------------------------------------------------------------------------------------------------------- | | `x` | `str` | `None` | The dimension to keep: checked to be the only one left after `selection`. Default: whichever it is. | | `**selection` | | `{}` | The other dimensions: an integer is a position (`t=-1` the last), a float the nearest coordinate value. | Returns * `xarray.DataArray` The selected profile, over `x` only. Raises * `ValueError` If more or fewer than one dimension remains, or `x` is not the remaining one. See Also [`plasma_plots.plotting.prepare_lineout()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_lineout) : The check behind this method. [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout) : The plot of this profile. Examples ```python >>> n.plasma.data.lineout(x="eta1", t=-1, eta2=0.3, eta3=0) ``` ### `vector` [Section titled “vector”](#vector) ### `vector`method[#](#plasma_plots.accessors.ArrayData.vector) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2618-L2645 "src/plasma_plots/accessors.py:2618-2645") ``` def vector(x: str, y: str, components: tuple[int, int] = (0, 1), stride: int = 1, coordinates: Coordinates = 'logical', **selection) -> xr.DataArray ``` Return the selected, strided vector field [`ArrayPlots.vector()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.vector) would plot. Parameters | Name | Type | Default | Description | | ------------- | ------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `x` | `str` | required | The dimension along the horizontal axis. | | `y` | `str` | required | The dimension along the vertical axis. | | `components` | `(int, int)` | `(0, 1)` | The positions along `component_dim` of the two components drawn. Default: `(0, 1)`. | | `stride` | `int` | `1` | Draw every `stride`-th arrow along `x` and `y`. Default: `1`. | | `coordinates` | `('logical', 'physical')` | `"logical"` | Place the arrows at the logical coordinates, or at the attached physical `X`, `Y`, `Z` (then `x` and `y` must be two of `eta1`, `eta2`, `eta3`, and the axes have equal scales). Default: `"logical"`. | | `**selection` | | `{}` | Every dimension but `x`, `y` and the component dimension, e.g. `t=-1, eta3=0`: an integer is a position, a float the nearest coordinate value. | Returns * `xarray.DataArray` The two selected components over `x` and `y`, every `stride`-th point. See Also [`ArrayPlots.vector()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.vector) : The plot of these components. [`plasma_plots.plotting.prepare_vector()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_vector) : The function that prepares them. ### `volume_slices` [Section titled “volume\_slices”](#volume_slices) ### `volume_slices`method[#](#plasma_plots.accessors.ArrayData.volume_slices) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2647-L2665 "src/plasma_plots/accessors.py:2647-2665") ``` def volume_slices(indices: dict[str, int] | None = None, **selection) -> dict[str, xr.DataArray] ``` Return the three orthogonal planes [`ArrayPlots.volume_slices()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.volume_slices) would plot. Parameters | Name | Type | Default | Description | | ------------- | -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | | `indices` | `dict of str to int` | `None` | The index at which each dimension is held fixed, e.g. `{"eta3": 0}`. Default: the middle index of every dimension. | | `**selection` | | `{}` | Every dimension but the three of the volume, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `dict of str to xarray.DataArray` The three planes. See Also [`ArrayPlots.volume_slices()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.volume_slices) : The plot of these planes. [`plasma_plots.plotting.prepare_volume_slices()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_volume_slices) : The function that prepares them. ### `grid` [Section titled “grid”](#grid) ### `grid`method[#](#plasma_plots.accessors.ArrayData.grid) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2667-L2697 "src/plasma_plots/accessors.py:2667-2697") ``` def grid(name: str | None = None, **selection) ``` Return this field as a `pyvista.StructuredGrid` on its physical points. Every dimension but `eta1`, `eta2`, `eta3` (and `component`) is selected first. This is the data behind every 3-D view, ready for any PyVista filter. Parameters | Name | Type | Default | Description | | ------------- | ----- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `str` | `None` | The name of the point data. Default: the field’s label. | | `**selection` | | `{}` | Every dimension but `eta1`, `eta2`, `eta3` and `component`, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `pyvista.StructuredGrid` The grid, with the field as its point data. See Also [`plasma_plots.pyvista_plots.structured_grid()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.structured_grid) : The function behind this method. [`ArrayData.to_vtk()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.to_vtk) : Write the grid to files instead. Examples ```python >>> grid = phi.plasma.data.grid(t=-1) ``` ### `to_vtk` [Section titled “to\_vtk”](#to_vtk) ### `to_vtk`method[#](#plasma_plots.accessors.ArrayData.to_vtk) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2699-L2730 "src/plasma_plots/accessors.py:2699-2730") ``` def to_vtk(path, *, name: str | None = None, **selection) -> list[str] ``` Write this field to VTK structured-grid files for ParaView. One `.vts` per time and a `.pvd` collection, or a single `.vts` without `t`. Select other dimensions first. Parameters | Name | Type | Default | Description | | ------------- | --------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `path` | `str or pathlib.Path` | required | The `.vts` file (the suffix is set to `.vts`), or with a `t` dimension the directory to write into (created if needed). | | `name` | `str` | `None` | The name of the point data, also the file stem in a time series. Default: the field’s label. | | `**selection` | | `{}` | Every dimension but `t`, `eta1`, `eta2`, `eta3` and `component`: an integer is a position, a float the nearest coordinate value. `t` is kept unless selected too. | Returns * `list of str` The paths of the written files. See Also [`plasma_plots.pyvista_plots.save_vtk()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.save_vtk) : The function behind this method. [`ArrayData.grid()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.grid) : One time as a PyVista grid, in memory. Examples ```python >>> field.plasma.data.to_vtk("frames") ``` ### `slices_3d` [Section titled “slices\_3d”](#slices_3d) ### `slices_3d`method[#](#plasma_plots.accessors.ArrayData.slices_3d) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2732-L2749 "src/plasma_plots/accessors.py:2732-2749") ``` def slices_3d(cuts: dict | None = None, **selection) -> list[xr.DataArray] ``` Return the logical cuts [`ArrayPlots.slices_3d()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.slices_3d) would draw. Parameters | Name | Type | Default | Description | | ------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `cuts` | `dict` | `None` | `{dim: position or list of positions}` along `eta1`, `eta2`, `eta3`: a float is the nearest logical coordinate, an integer a grid index (`-1` the last). Default: the middle of every dimension, or the whole plane of a 2-D field. | | `**selection` | | `{}` | Every dimension but `eta1`, `eta2`, `eta3`, e.g. `t=0`: an integer is a position, a float the nearest coordinate value. | Returns * `list of xarray.DataArray` One array per cut. See Also [`ArrayPlots.slices_3d()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.slices_3d) : The drawing of these cuts. [`plasma_plots.pyvista_plots.prepare_slices_3d()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.prepare_slices_3d) : The function that prepares them. ### `compare` [Section titled “compare”](#compare) ### `compare`method[#](#plasma_plots.accessors.ArrayData.compare) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2751-L2775 "src/plasma_plots/accessors.py:2751-2775") ``` def compare(other: xr.DataArray, *, mode: Literal['difference', 'ratio'] = 'difference') -> xr.DataArray ``` Return the aligned difference or ratio [`ArrayPlots.compare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.compare) would plot. Parameters | Name | Type | Default | Description | | ------- | ------------------------- | -------------- | -------------------------------------------------------------------------------------------- | | `other` | `xarray.DataArray` | required | The array to compare with, e.g. a reference run; aligned with this one first. | | `mode` | `('difference', 'ratio')` | `"difference"` | `first - second`, or `first / second` (NaN where `second` is zero). Default: `"difference"`. | Returns * `xarray.DataArray` This array minus `other`, or divided by it, after alignment. See Also [`ArrayPlots.compare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.compare) : The plot of this difference or ratio. [`plasma_plots.plotting.prepare_compare()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_compare) : The function that computes it. Examples ```python >>> field.plasma.data.compare(reference_field, mode="ratio") ``` ### `view` [Section titled “view”](#view) ### `view`method[#](#plasma_plots.accessors.ArrayData.view) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2777-L2816 "src/plasma_plots/accessors.py:2777-2816") ``` def view(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', **selection) -> xr.DataArray ``` Return every remaining dimension of this array, sweep included. This data is shared by [`ArrayPlots.panels()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.panels), `.viewer()`, `.animation()` and `.frames()`, which each render one frame of exactly this data at a time. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `None` | The dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions. | | `y` | `str` | `None` | The dimension along the vertical axis. Default: the second remaining dimension. | | `sweep` | `str` | `'t'` | The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: `"t"`. | | `coords` | `('logical', 'physical')` | `"logical"` | Draw over the logical coordinates, or over the mapped physical coordinates (`X`, `Y`, `Z`). Default: `"logical"`. | | `plane` | `('XY', 'XZ', 'YZ', 'RZ', 'X1X2')` | `"XY"` | The physical plane, with `coords="physical"`: `"RZ"` uses `R = √(X² + Y²)`, `"X1X2"` GVEC’s reference coordinates. Default: `"XY"`. | | `**selection` | | `{}` | Every dimension but `x`, `y` and `sweep`: an integer is a position (`-1` the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises `TypeError`. | Returns * `xarray.DataArray` The selection ordered `(sweep, x, y)`. With `coords="physical"` the periodic seam of a cell-centered grid is closed, as in every drawn frame (one more point along a periodic angle). Raises * `ValueError` If other dimensions than `sweep`, `x` and `y` remain, or the physical coordinates are missing. See Also [`ArrayPlots.view()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.view) : The configured view of this data, and its options. Examples ```python >>> n.plasma.data.view(coords="physical", plane="XY", eta3=0) ``` ### `slice` [Section titled “slice”](#slice) ### `slice`method[#](#plasma_plots.accessors.ArrayData.slice) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2818-L2848 "src/plasma_plots/accessors.py:2818-2848") ``` def slice(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', **selection) -> xr.DataArray ``` Return the single 2-D slice [`ArrayPlots.slice()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.slice) would plot. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `None` | The dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions. | | `y` | `str` | `None` | The dimension along the vertical axis. Default: the second remaining dimension. | | `sweep` | `str` | `'t'` | The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: `"t"`. | | `coords` | `('logical', 'physical')` | `"logical"` | Draw over the logical coordinates, or over the mapped physical coordinates (`X`, `Y`, `Z`). Default: `"logical"`. | | `plane` | `('XY', 'XZ', 'YZ', 'RZ', 'X1X2')` | `"XY"` | The physical plane, with `coords="physical"`: `"RZ"` uses `R = √(X² + Y²)`, `"X1X2"` GVEC’s reference coordinates. Default: `"XY"`. | | `**selection` | | `{}` | Every dimension but `x`, `y` and `sweep`: an integer is a position (`-1` the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises `TypeError`. | Returns * `xarray.DataArray` The selected slice. See Also [`ArrayPlots.slice()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.slice) : The plot of this slice. Examples ```python >>> phi.plasma.data.slice(x="eta1", y="eta2", t=-1) >>> n.plasma.data.slice(coords="physical", plane="XY", t=-1, eta3=0) ``` ### `dispersion` [Section titled “dispersion”](#dispersion) ### `dispersion`method[#](#plasma_plots.accessors.ArrayData.dispersion) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2850-L2875 "src/plasma_plots/accessors.py:2850-2875") ``` def dispersion(dim: str | None = None, detrend: bool = True) -> xr.DataArray ``` Return the space-time power spectrum [`ArrayPlots.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.dispersion) would plot. The same as [`ArrayAnalysis.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.dispersion); included here too for parity with every other plot. Parameters | Name | Type | Default | Description | | --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `dim` | `str` | `None` | The spatial dimension. Default: the sole dimension other than `t`. | | `detrend` | `bool` | `True` | Remove the time-mean at each point of `dim` first, which otherwise dominates the spectrum as a spurious zero-frequency line. Default: `True`. | Returns * `xarray.DataArray` The power over angular frequency `omega` and wavenumber. See Also [`plasma_plots.analysis.power_spectrum()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.power_spectrum) : The function behind this method. [`ArrayPlots.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.dispersion) : The plot of this spectrum. [`ArrayAnalysis.dispersion()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.dispersion) : The same spectrum. Examples ```python >>> field.plasma.data.dispersion(dim="eta1") ``` ### `overlay_orbits` [Section titled “overlay\_orbits”](#overlay_orbits) ### `overlay_orbits`method[#](#plasma_plots.accessors.ArrayData.overlay_orbits) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2877-L2905 "src/plasma_plots/accessors.py:2877-2905") ``` def overlay_orbits(orbits: xr.Dataset, *, x: str, y: str, max_markers: int = 200, **selection) -> tuple[xr.DataArray, xr.Dataset] ``` Return the field slice and marker subset [`ArrayPlots.overlay_orbits()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.overlay_orbits) would plot. Parameters | Name | Type | Default | Description | | ------------- | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `orbits` | `xarray.Dataset` | required | An orbits product with position variables named after `view.x` and `view.y` (e.g. its logical coordinates, to overlay directly on a logical-coordinates slice). | | `x` | `str` | required | The horizontal dimension of the slice. `orbits` must have a position variable of the same name (e.g. logical `eta1`, to overlay directly on a logical-coordinates slice of this field). | | `y` | `str` | required | The vertical dimension of the slice; `orbits` needs a variable of this name too. | | `max_markers` | `int` | `200` | Draw only the first `max_markers` markers. Default: `200`. | | `**selection` | | `{}` | Every other dimension of this field, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `tuple of (xarray.DataArray, xarray.Dataset)` The field slice, and the orbits of the first `max_markers` markers. Raises * `ValueError` If `orbits` has no variables named `x` and `y`, or no `marker` dimension. See Also [`ArrayPlots.overlay_orbits()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.overlay_orbits) : The plot of this slice and these orbits. Examples ```python >>> field, paths = field.plasma.data.overlay_orbits( ... orbits, x="eta1", y="eta2", t=-1 ... ) ``` ### `trajectories` [Section titled “trajectories”](#trajectories) ### `trajectories`method[#](#plasma_plots.accessors.ArrayData.trajectories) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2907-L2928 "src/plasma_plots/accessors.py:2907-2928") ``` def trajectories(max_markers: int = 200) -> xr.Dataset ``` Return the marker-position subset [`ArrayPlots.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.trajectories) would plot. Parameters | Name | Type | Default | Description | | ------------- | ----- | ------- | ---------------------------------------------------------- | | `max_markers` | `int` | `200` | Draw only the first `max_markers` markers. Default: `200`. | Returns * `xarray.Dataset` The orbits of the first `max_markers` markers. Raises * `ValueError` If the orbits lack `x`, `y` or `z`, or a `marker` dimension. See Also [`ArrayPlots.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.trajectories) : The plot of these markers. ### `timeseries` [Section titled “timeseries”](#timeseries) ### `timeseries`method[#](#plasma_plots.accessors.ArrayData.timeseries) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2930-L2956 "src/plasma_plots/accessors.py:2930-2956") ``` def timeseries(*others) -> list[xr.DataArray] ``` Return this time series and any `others`, validated, as [`ArrayPlots.timeseries()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.timeseries) plots them. Parameters | Name | Default | Description | | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------- | | `*others` | `()` | Further arrays with the single dimension `t`; they may come from other runs and need not share this array’s time grid. | Returns * `list of xarray.DataArray` This series first, then `others`. Raises * `ValueError` If a series does not have the dimension `t`. See Also [`ArrayPlots.timeseries()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.timeseries) : The plot of these series. Examples ```python >>> energy.plasma.data.timeseries(other_run_energy) ``` ### `poincare` [Section titled “poincare”](#poincare) ### `poincare`method[#](#plasma_plots.accessors.ArrayData.poincare) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2958-L2997 "src/plasma_plots/accessors.py:2958-2997") ``` def poincare(seeds=8, turns: float | None = None, section: float | None = None, **selection) -> xr.Dataset ``` Return the Poincaré section [`ArrayPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.poincare) would plot. Parameters | Name | Type | Default | Description | | ------------- | ------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `seeds` | `(int, dict, array_like or xarray.Dataset)` | `8` | Where the lines start; see [`plasma_plots.fieldlines.trace_field_lines()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.trace_field_lines). Default: 8 along the radius. | | `turns` | `float` | `None` | How many toroidal transits to trace. Default: 20. | | `section` | `float` | `None` | The toroidal logical coordinate of the plane. Default: the first grid value. | | `**selection` | | `{}` | The other dimensions, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `xarray.Dataset` The punctures over `(puncture, line)`; see [`plasma_plots.fieldlines.poincare_section()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.poincare_section). See Also [`ArrayPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.poincare) : The plot of these punctures. [`ArrayAnalysis.field_lines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.field_lines) : The traced lines themselves. Examples ```python >>> B.plasma.data.poincare(seeds=12, turns=100, t=-1) ``` ### `critical_points` [Section titled “critical\_points”](#critical_points) ### `critical_points`method[#](#plasma_plots.accessors.ArrayData.critical_points) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L2999-L3026 "src/plasma_plots/accessors.py:2999-3026") ``` def critical_points(refine: bool = True, **selection) -> xr.Dataset ``` Return the O- and X-points [`ArrayPlots.critical_points()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.critical_points) would mark. Parameters | Name | Type | Default | Description | | ------------- | ------ | ------- | -------------------------------------------------------------------------------------------------- | | `refine` | `bool` | `True` | Locate the zero within the cell by Newton’s method (the cell’s centre otherwise). Default: True. | | `**selection` | | `{}` | The other dimensions, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `xarray.Dataset` The points over `point` (and the dimensions left, e.g. `t`). See Also [`plasma_plots.analysis.critical_points()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.critical_points) : The function behind this method. [`ArrayPlots.critical_points()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.critical_points) : The plot of these points. Examples ```python >>> A.plasma.data.critical_points(t=-1) ``` # dataset.plasma > Plots, diagnostics and data of marker Datasets such as orbits. Plots, diagnostics and data of an `xarray.Dataset` with per-marker variables, such as an orbits product. Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## dataset.plasma.plot [Section titled “dataset.plasma.plot”](#datasetplasmaplot) Plots of one dataset, as `dataset.plasma.plot.(...)`. ### `power_spectrum` [Section titled “power\_spectrum”](#power_spectrum) ### `power_spectrum`method[#](#plasma_plots.accessors.DatasetPlots.power_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4586-L4620 "src/plasma_plots/accessors.py:4586-4620") ``` def power_spectrum(backend: Backend | None = None, **options) ``` Plot the power of a `time_fft` Dataset. Parameters | Name | Type | Default | Description | | ----------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `**options` | | `{}` | The keyword options of [`plasma_plots.spectral_plots.plot_power_spectrum()`](/plasma-plots/api/plasma_plots/spectral_plots/#plasma_plots.spectral_plots.plot_power_spectrum), e.g. `peaks=2`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn artists; `data` holds the averaged `"power"` and the found `"peaks"`. See Also [`plasma_plots.spectral_plots.plot_power_spectrum()`](/plasma-plots/api/plasma_plots/spectral_plots/#plasma_plots.spectral_plots.plot_power_spectrum) : The function behind this method. [`ArrayAnalysis.time_fft()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.time_fft) : The Dataset to plot. Examples ```python >>> phi.plasma.analysis.time_fft(detrend=True).plasma.plot.power_spectrum( ... peaks=2 ... ) ``` ### `cross_spectrum` [Section titled “cross\_spectrum”](#cross_spectrum) ### `cross_spectrum`method[#](#plasma_plots.accessors.DatasetPlots.cross_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4622-L4655 "src/plasma_plots/accessors.py:4622-4655") ``` def cross_spectrum(omega_max: float | None = None, backend: Backend | None = None) ``` Plot the magnitude, coherence and phase of a `cross_spectrum` Dataset. Parameters | Name | Type | Default | Description | | ----------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `omega_max` | `float` | `None` | The highest frequency shown. Default: all. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn artists; `data` holds `"peak_omega"` and `"peak_phase_deg"`. See Also [`plasma_plots.spectral_plots.plot_cross_spectrum()`](/plasma-plots/api/plasma_plots/spectral_plots/#plasma_plots.spectral_plots.plot_cross_spectrum) : The function behind this method. [`ArrayAnalysis.cross_spectrum()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.cross_spectrum) : The Dataset to plot. Examples ```python >>> u.plasma.analysis.cross_spectrum( ... b, dims="eta3" ... ).plasma.plot.cross_spectrum(omega_max=1.5) ``` ### `trajectories` [Section titled “trajectories”](#trajectories) ### `trajectories`method[#](#plasma_plots.accessors.DatasetPlots.trajectories) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4657-L4695 "src/plasma_plots/accessors.py:4657-4695") ``` def trajectories(max_markers: int = 200, show_paths: bool | None = None, ax=None, backend: Backend | None = None) ``` Plot the three-dimensional paths of saved markers, for an `orbits` product. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `max_markers` | `int` | `200` | Draw only the first `max_markers` markers. Default: `200`. | | `show_paths` | `bool` | `None` | Draw each marker’s path, not only its last position. Default: `True` for up to 200 markers. | | `ax` | `mpl_toolkits.mplot3d.Axes3D` | `None` | A 3-D axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the 3-D axes and the drawn artists. See Also [`plasma_plots.plotting.plot_marker_trajectories()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_marker_trajectories) : The function behind this method. [`DatasetData.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.trajectories) : The plotted markers, without plotting them. [`DatasetPlots.orbits_3d()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbits_3d) : Interactive PyVista orbit lines. Examples ```python >>> orbits.plasma.plot.trajectories(max_markers=200) ``` ### `scatter` [Section titled “scatter”](#scatter) ### `scatter`method[#](#plasma_plots.accessors.DatasetPlots.scatter) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4697-L4760 "src/plasma_plots/accessors.py:4697-4760") ``` def scatter(x: str, y: str, color: str | None = None, ax=None, cmap=None, s: int = 8, color_at=None, background: xr.DataArray | None = None, background_options: dict | None = None, equal_aspect: bool | None = None, backend: Backend | None = None, **selection) ``` Scatter two marker variables, optionally colored by a third (e.g. density or a tracer). Remaining dimensions such as `t` are selected by keyword, exactly like [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout): an integer is a position (`-1` the last), and a float is the nearest coordinate value. `color_at` colors by the values at another time (e.g. `0`, the initial positions); `background` draws a field behind the markers. Parameters | Name | Type | Default | Description | | -------------------- | ----------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | required | The data variable along the horizontal axis, e.g. the position `"x"`. | | `y` | `str` | required | The data variable along the vertical axis, e.g. the position `"y"`. | | `color` | `str` | `None` | A data variable to color the markers by, e.g. a Lagrangian tracer, weight or density, with a color bar. Default: one color. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `cmap` | `str or matplotlib.colors.Colormap` | `None` | The colormap for `color`. Default: `"viridis"`. | | `s` | `int` | `8` | The marker size, in points². Default: `8`. | | `color_at` | `int or float` | `None` | Take the colors at another time (an integer position such as `0`, or a float value), e.g. each marker’s initial position, to follow where fluid parcels go. Default: the selected time. | | `background` | `xarray.DataArray` | `None` | A field drawn behind the markers at the same time (select its other dimensions first): on its own `x`/`y` dimensions if it has them (a Cartesian field), in logical coordinates if `x`/`y` are `eta1`/`eta2`/`eta3`, else in the physical plane of `x`/`y` (`x`, `y`, `z`; the field then needs its `X`, `Y`, `Z` coordinates). | | `background_options` | `dict` | `None` | Passed to \[`plot_slice()`]\[plot\_slice] for the background (e.g. `cmap`, `levels`, `fill=False`). | | `equal_aspect` | `bool` | `None` | Draw both axes to the same scale. Default: when `x` and `y` have the same `units` attribute (e.g. two positions), not for a phase space such as `x` against `vx`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | The remaining dimensions, such as `t`, exactly like [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout): an integer is a position (`t=-1` the last), a float the nearest coordinate value. | Returns * `PlotResult` The figure, the axes and the drawn artists. See Also [`plasma_plots.plotting.plot_marker_scatter()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_marker_scatter) : The function behind this method. [`DatasetData.scatter()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.scatter) : The selected markers, without plotting them. [`DatasetPlots.animation()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.animation) : The markers moving over time. Examples ```python >>> markers.plasma.plot.scatter(x="x", y="y", color="density", t=-1) >>> markers.plasma.plot.scatter(x="x", y="y", color="tracer", color_at=0, t=-1) ``` ### `orbit_classification` [Section titled “orbit\_classification”](#orbit_classification) ### `orbit_classification`method[#](#plasma_plots.accessors.DatasetPlots.orbit_classification) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4762-L4807 "src/plasma_plots/accessors.py:4762-4807") ``` def orbit_classification(x: str = 'v_par', y: str | None = None, v_par: str = 'v_par', t=0, ax=None, s: int = 8, backend: Backend | None = None) ``` Plot markers in a phase-space plane, colored as passing, trapped or lost. By default initial `v_par` against `mu`; for a guiding-center orbits product. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `'v_par'` | The quantity along the horizontal axis. Default: `"v_par"`. | | `y` | `str` | `None` | The quantity along the vertical axis. Default: the magnetic moment `mu` (Particles5D), or `v_perp` if there is no `mu` (Particles5Dvperp). | | `v_par` | `str` | `'v_par'` | The parallel velocity the classification uses. Default: `"v_par"`. | | `t` | `int or float` | `0` | The time of the plotted values: an integer position (default `0`, the initial phase-space position, before any marker is lost; `-1` the last), or a float nearest value. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `s` | `int` | `8` | The marker size, in points². Default: `8`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn artists; `data["counts"]` holds the number of markers per class. See Also [`plasma_plots.plotting.plot_orbit_classification()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_orbit_classification) : The function behind this method. [`DatasetData.orbit_classification()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.orbit_classification) : The plotted values, without plotting them. [`DatasetAnalysis.classify_orbits()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.classify_orbits) : The classification alone. Examples ```python >>> orbits.plasma.plot.orbit_classification() >>> orbits.plasma.plot.orbit_classification(x="p_phi") ``` ### `animation` [Section titled “animation”](#animation) ### `animation`method[#](#plasma_plots.accessors.DatasetPlots.animation) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4809-L4881 "src/plasma_plots/accessors.py:4809-4881") ``` def animation(x: str, y: str, color: str | None = None, color_at=None, background: xr.DataArray | None = None, background_options: dict | None = None, step: int = 1, max_frames: int | None = None, interval: int = 100, s: int = 8, cmap=None, trail: int | None = None, paths: bool = False, backend: Backend | None = None) ``` Animate the markers moving over time, optionally over a field animated in sync. E.g. over an SPH density. Keep a reference to the returned animation. Parameters | Name | Type | Default | Description | | -------------------- | ----------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | required | The data variable along the horizontal axis, e.g. the position `"x"`; `"R"` is `√(x² + y²)` when the data has no `R` of its own (with `y="z"` the poloidal plane). | | `y` | `str` | required | The data variable along the vertical axis, e.g. the position `"y"`. | | `color` | `str` | `None` | A variable to color by: per frame, or fixed at the time `color_at`; or `"classification"`, the orbit class of each marker (passing, trapped, lost; needs `v_par`, see [`classify_orbits()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.classify_orbits)), with a legend. Default: one color. | | `color_at` | `int or float` | `None` | Fix the colors at this time (an integer position, e.g. `0` for the initial position, to follow fluid parcels, or a float value). Default: the colors of each frame. | | `background` | `xarray.DataArray` | `None` | A field drawn behind the markers: with a `t` dimension (other dimensions selected) at the nearest time of each frame, with shared color limits; without one, fixed (drawn once). On its own `x`/`y` dimensions if it has them (a Cartesian field), in logical coordinates if `x`/`y` are `eta1`/`eta2`/`eta3`, else in the physical plane of `x`/`y` (the field then needs its `X`, `Y`, `Z` coordinates). | | `background_options` | `dict` | `None` | Rendering options for the background, as for \[`plot_slice()`]\[plot\_slice] (`cmap`, `symmetric`, `levels`, …). | | `step` | `int` | `1` | Use every `step`-th time. Default: `1`. | | `max_frames` | `int` | `None` | Keep at most this many frames, evenly spaced over those `step` leaves (the first and last included), e.g. to keep a Plotly animation small. Default: all. | | `interval` | `int` | `100` | The delay between frames, in milliseconds. Default: `100`. | | `s` | `int` | `8` | The marker size, in points². Default: `8`. | | `cmap` | `str or matplotlib.colors.Colormap` | `None` | The colormap for `color`. Default: `"viridis"`. | | `trail` | `int` | `None` | Draw each marker’s last `trail` samples as a faint line behind it. Default: none. | | `paths` | `bool` | `False` | Draw each marker’s whole path, fixed and faint, under the animation. Default: `False`. | | `backend` | `('matplotlib', 'plotly')` | `"matplotlib"` | Draw with Matplotlib, or as an interactive Plotly figure with a slider (in `result.fig`; needs plotly, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `matplotlib.animation.FuncAnimation or PlotResult` The animation; with `backend="plotly"` a result whose Plotly figure has a slider and Play/Pause buttons. See Also [`plasma_plots.plotting.animate_markers()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.animate_markers) : The function behind this method. [`DatasetPlots.scatter()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.scatter) : One frame, as a static plot. Examples ```python >>> markers.plasma.plot.animation( ... x="x", y="y", color="density", background=n, step=2 ... ) >>> orbits.plasma.plot.animation( ... x="R", ... y="z", ... color="classification", ... trail=300, ... paths=True, ... background=psi, ... ) ``` ### `paths` [Section titled “paths”](#paths) ### `paths`method[#](#plasma_plots.accessors.DatasetPlots.paths) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4883-L4935 "src/plasma_plots/accessors.py:4883-4935") ``` def paths(x: str = 'x', y: str = 'y', markers=6, near=None, background: xr.DataArray | None = None, background_options: dict | None = None, t=0, ax=None, backend: Backend | None = None) ``` Plot the paths of a few markers in a plane, with start and end markers. Optionally over a field (e.g. stream-function contour lines). Parameters | Name | Type | Default | Description | | -------------------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `'x'` | The quantity along the horizontal axis. Default: `"x"`. | | `y` | `str` | `'y'` | The quantity along the vertical axis. Default: `"y"`. | | `markers` | `int or sequence of int` | `6` | A number of markers (spread evenly over the saved markers) or a list of marker indices. Default: `6`. | | `near` | `sequence of (float, float)` | `None` | Picks instead the marker starting closest to each of a list of `(x, y)` points, e.g. a row across the domain. | | `background` | `xarray.DataArray` | `None` | A field drawn behind the paths at the time `t`: on its own `x`/`y` dimensions if it has them (a Cartesian field), in logical coordinates if `x`/`y` are `eta1`/`eta2`/`eta3`, else in the physical plane of `x`/`y` (the field then needs its `X`, `Y`, `Z` coordinates). | | `background_options` | `dict` | `None` | Passed to \[`plot_slice()`]\[plot\_slice] for the background, e.g. `dict(levels=12, fill=False)` for the contour lines of a stream function. | | `t` | `int or float` | `0` | The time of the background: an integer position or a float value. Default: `0`, the first. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn artists; `data["markers"]` holds the chosen markers. See Also [`plasma_plots.plotting.plot_marker_paths()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_marker_paths) : The function behind this method. Examples ```python >>> orbits.plasma.plot.paths(markers=4, background=psi.isel(t=0)) ``` ### `poloidal` [Section titled “poloidal”](#poloidal) ### `poloidal`method[#](#plasma_plots.accessors.DatasetPlots.poloidal) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4937-L4981 "src/plasma_plots/accessors.py:4937-4981") ``` def poloidal(color_by: str | None = 'classification', max_markers: int = 200, boundary: xr.DataArray | None = None, ax=None, backend: Backend | None = None) ``` Plot orbits projected onto the poloidal plane (`R` against `z`). By default colored as passing, trapped or lost. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `color_by` | `str or None` | `'classification'` | `"classification"` colors by orbit class (needs `v_par`, see [`classify_orbits()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.classify_orbits)); `"t"` or the name of a `(t, marker)` variable (e.g. `"v_par"`) colors each orbit along its path, with a color bar; `None` gives one color per marker. Default: `"classification"`. | | `max_markers` | `int` | `200` | Draw only the first `max_markers` markers. Default: `200`. | | `boundary` | `xarray.DataArray` | `None` | Any field with physical coordinates, whose outer (last `eta1`) surface is drawn at its first `eta3` as the domain boundary. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn lines. See Also [`plasma_plots.plotting.plot_orbit_poloidal()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_orbit_poloidal) : The function behind this method. [`DatasetPlots.orbit_grid()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbit_grid) : One panel per marker. Examples ```python >>> orbits.plasma.plot.poloidal(boundary=field) ``` ### `orbit_grid` [Section titled “orbit\_grid”](#orbit_grid) ### `orbit_grid`method[#](#plasma_plots.accessors.DatasetPlots.orbit_grid) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4983-L5022 "src/plasma_plots/accessors.py:4983-5022") ``` def orbit_grid(markers=8, ncols: int = 4, boundary: xr.DataArray | None = None, backend: Backend | None = None) ``` Plot one small poloidal panel per marker, colored by orbit class. Parameters | Name | Type | Default | Description | | ---------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `markers` | `int or sequence of int` | `8` | A number of markers (spread over the classes when `v_par` is saved) or a list of marker indices. Default: `8`. | | `ncols` | `int` | `4` | The number of panels per row. Default: `4`. | | `boundary` | `xarray.DataArray` | `None` | A field with physical coordinates whose outer (last `eta1`) surface is drawn in every panel, at its first `eta3`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn lines; `data["markers"]` holds the plotted markers. See Also [`plasma_plots.plotting.plot_orbit_grid()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_orbit_grid) : The function behind this method. [`DatasetPlots.poloidal()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poloidal) : All orbits in one panel. Examples ```python >>> orbits.plasma.plot.orbit_grid(markers=8, ncols=4, boundary=field) >>> orbits.plasma.plot.orbit_grid(markers=[3, 17, 42]) ``` ### `quantities` [Section titled “quantities”](#quantities) ### `quantities`method[#](#plasma_plots.accessors.DatasetPlots.quantities) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5024-L5062 "src/plasma_plots/accessors.py:5024-5062") ``` def quantities(quantities=('v_par', 'mu'), markers=6, drift_of=('mu'), backend: Backend | None = None) ``` Plot saved orbit quantities over time for a few markers. E.g. `v_par` bouncing, or the drift of the invariant `mu`. Parameters | Name | Type | Default | Description | | ------------ | ---------------------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `quantities` | `sequence of str` | `('v_par', 'mu')` | The quantities, one panel each. Default: `("v_par", "mu")`. | | `markers` | `int or sequence of int` | `6` | A number of markers (spread over the classes if `v_par` is saved, so passing and trapped ones both show) or a list of marker indices. Default: `6`. | | `drift_of` | `bool or sequence of str` | `('mu')` | The quantities shown as their change since `t = 0` (default `("mu",)`, an invariant of guiding-center motion, so its drift measures the pusher’s accuracy); `True` for all, `False` for none. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, one axes per quantity and the drawn lines. See Also [`plasma_plots.plotting.plot_orbit_quantities()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_orbit_quantities) : The function behind this method. Examples ```python >>> orbits.plasma.plot.quantities(markers=4) ``` ### `orbits_3d` [Section titled “orbits\_3d”](#orbits_3d) ### `orbits_3d`method[#](#plasma_plots.accessors.DatasetPlots.orbits_3d) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5064-L5106 "src/plasma_plots/accessors.py:5064-5106") ``` def orbits_3d(color_by: str = 't', max_markers: int = 200, tube_radius: float | None = None, cmap=None, domain: xr.DataArray | None = None, title: str | None = None, plotter=None) ``` Draw PyVista 3-D orbit lines, colored by `"t"`, `"classification"` or any variable. `domain` is a field whose boundary is drawn for context. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `color_by` | `str` | `'t'` | `"t"`, `"classification"` (passing, trapped, lost, with a legend) or the name of any `(t, marker)` variable, e.g. `"v_par"`. Default: `"t"`. | | `max_markers` | `int` | `200` | At most this many markers are drawn. Default: 200. | | `tube_radius` | `float` | `None` | Draw the orbits as tubes of this radius. Default: plain lines. | | `cmap` | `str or matplotlib colormap` | `None` | The colormap (not used for `"classification"`). Default: `"viridis"`. | | `domain` | `xarray.DataArray` | `None` | A field with physical coordinates whose outer surface is drawn translucently; other than `eta1`, `eta2`, `eta3`, its dimensions are taken at their first position. | | `title` | `str` | `None` | Text in the scene’s corner. Default: `"Marker orbits"`; `""` for none. | | `plotter` | `pyvista.Plotter` | `None` | Draw into this scene instead of a new one, to combine several views. | Returns * `pyvista.Plotter` The plotter with the orbits, not yet shown. See Also [`plasma_plots.pyvista_plots.pyvista_orbits()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.pyvista_orbits) : The function behind this method. [`DatasetPlots.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.trajectories) : A static Matplotlib overview. Examples ```python >>> orbits.plasma.plot.orbits_3d( ... color_by="classification", domain=phi.isel(t=0) ... ).show() ``` ### `poincare` [Section titled “poincare”](#poincare) ### `poincare`method[#](#plasma_plots.accessors.DatasetPlots.poincare) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5108-L5167 "src/plasma_plots/accessors.py:5108-5167") ``` def poincare(coords: str = 'physical', color_by: str | None = 'line', s: float = 3.0, cmap=None, islands: bool = False, boundary: xr.DataArray | None = None, max_lines: int | None = None, ax=None, title: str | None = None, backend: Backend | None = None, **classification) ``` Plot the Poincaré section of these traced field lines. Parameters | Name | Type | Default | Description | | ------------------ | --------------------------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `coords` | `('physical', 'logical')` | `"physical"` | Draw `R` against `z` (physical), or the poloidal angle against the radial logical coordinate (logical). Default: `"physical"`. | | `color_by` | `('line', 'iota', 'classification', 'connection_length', None)` | `"line"` | One color per line (cycling), a color bar over each line’s rotational transform or connection length, or the classes of [`classify_field_lines()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.classify_field_lines) (surface, island, chaotic) with a legend; `None` for one color. Default: `"line"`. | | `s` | `float` | `3.0` | The marker size, in points². Default: 3. | | `cmap` | `str or matplotlib colormap` | `None` | The colormap of `"iota"` and `"connection_length"`. Default: `"viridis"`. | | `islands` | `bool` | `False` | Label the island chains with their `n/m` and widths. Default: False. | | `boundary` | `xarray.DataArray` | `None` | A field with physical coordinates whose outermost surface is drawn at the section (physical coordinates only). | | `max_lines` | `int` | `None` | Draw only the first `max_lines` lines. Default: all. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: the section’s label and angle. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**classification` | | `{}` | Options of [`classify_field_lines()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.classify_field_lines) (`max_denominator`, `tolerance`, `threshold`, `min_spread`), for `color_by="classification"` and `islands_`. | Returns * `PlotResult` The figure, the axes and the scatters; `data` holds the section and, with `islands`, the chains and the classification. See Also [`plasma_plots.fieldline_plots.plot_poincare()`](/plasma-plots/api/plasma_plots/fieldline_plots/#plasma_plots.fieldline_plots.plot_poincare) : The function behind this method. [`DatasetData.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.poincare) : The punctures, without plotting them. [`DatasetAnalysis.islands()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.islands) : The island chains alone. Examples ```python >>> lines.plasma.plot.poincare(color_by="iota") >>> lines.plasma.plot.poincare(color_by="classification", islands=True) ``` ### `field_lines` [Section titled “field\_lines”](#field_lines) ### `field_lines`method[#](#plasma_plots.accessors.DatasetPlots.field_lines) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5169-L5218 "src/plasma_plots/accessors.py:5169-5218") ``` def field_lines(plane: str = 'RZ', color_by: str | None = 'line', max_lines: int = 200, cmap=None, boundary: xr.DataArray | None = None, ax=None, title: str | None = None, backend: Backend | None = None) ``` Plot these traced field lines projected onto a plane, or in 3-D. Parameters | Name | Type | Default | Description | | ----------- | ------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `plane` | `('RZ', 'XY', 'XZ', 'YZ', '3d')` | `"RZ"` | The projection: the poloidal plane `R`-`z` (default), a Cartesian plane, or a 3-D axes. | | `color_by` | `('line', 'iota', 'absB', 's', None)` | `"line"` | One color per line (cycling), each line colored by its rotational transform, or each line colored along its path by `\|B\|` or the arc length `s` (with a color bar; 2-D planes only); `None` for one color. Default: `"line"`. | | `max_lines` | `int` | `200` | Draw only the first `max_lines` lines. Default: 200. | | `cmap` | `str or matplotlib colormap` | `None` | The colormap. Default: `"viridis"`. | | `boundary` | `xarray.DataArray` | `None` | A field with physical coordinates whose outermost surface is drawn in the `RZ` plane. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into (a 3-D axes for `plane="3d"`). Default: a new figure. | | `title` | `str` | `None` | The title. Default: the lines’ label. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the lines. See Also [`plasma_plots.fieldline_plots.plot_field_lines()`](/plasma-plots/api/plasma_plots/fieldline_plots/#plasma_plots.fieldline_plots.plot_field_lines) : The function behind this method. [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) : Their punctures of a poloidal plane. Examples ```python >>> lines.plasma.plot.field_lines(plane="RZ", color_by="iota") >>> lines.plasma.plot.field_lines(plane="3d", max_lines=20) ``` ### `footprint` [Section titled “footprint”](#footprint) ### `footprint`method[#](#plasma_plots.accessors.DatasetPlots.footprint) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5220-L5260 "src/plasma_plots/accessors.py:5220-5260") ``` def footprint(log: bool = True, s: float = 14.0, cmap=None, ax=None, title: str | None = None, backend: Backend | None = None) ``` Plot where these open field lines leave the grid, colored by connection length. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `log` | `bool` | `True` | Color by the decimal logarithm of the connection length. Default: True. | | `s` | `float` | `14.0` | The marker size, in points². Default: 14. | | `cmap` | `str or matplotlib colormap` | `None` | The colormap. Default: `"viridis"`. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: how many lines left the grid. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the scatter; `data["footprint"]` holds the exit points. See Also [`plasma_plots.fieldline_plots.plot_footprint()`](/plasma-plots/api/plasma_plots/fieldline_plots/#plasma_plots.fieldline_plots.plot_footprint) : The function behind this method. [`DatasetData.footprint()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.footprint) : The exit points, without plotting them. [`DatasetPlots.connection_length()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.connection_length) : The connection lengths over the seeds. Examples ```python >>> edge.plasma.plot.footprint() ``` ### `connection_length` [Section titled “connection\_length”](#connection_length) ### `connection_length`method[#](#plasma_plots.accessors.DatasetPlots.connection_length) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5262-L5301 "src/plasma_plots/accessors.py:5262-5301") ``` def connection_length(log: bool = True, cmap=None, s: float = 14.0, ax=None, title: str | None = None, backend: Backend | None = None) ``` Plot the connection length of each field line over its seed. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `log` | `bool` | `True` | Show the decimal logarithm of the connection length. Default: True. | | `cmap` | `str or matplotlib colormap` | `None` | The colormap. Default: `"viridis"`. | | `s` | `float` | `14.0` | The marker size of a scatter, in points². Default: 14. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: `"connection length"`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the mesh or scatter; `data["connection_length"]`. See Also [`plasma_plots.fieldline_plots.plot_connection_length()`](/plasma-plots/api/plasma_plots/fieldline_plots/#plasma_plots.fieldline_plots.plot_connection_length) : The function behind this method. [`DatasetAnalysis.seed_grid()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.seed_grid) : The values over the seed grid. Examples ```python >>> edge.plasma.plot.connection_length() ``` ### `weight_histogram` [Section titled “weight\_histogram”](#weight_histogram) ### `weight_histogram`method[#](#plasma_plots.accessors.DatasetPlots.weight_histogram) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5303-L5351 "src/plasma_plots/accessors.py:5303-5351") ``` def weight_histogram(weight: str = 'weight', t=-1, bins: int = 50, log: bool = True, density: bool = True, ax=None, title: str | None = None, backend: Backend | None = None) ``` Plot the distribution of the marker weights at one or several times. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `weight` | `str` | `'weight'` | The weight variable. Default: `"weight"`. | | `t` | `(int, float or sequence)` | `-1` | The time(s): integer positions (`-1` the last) or float nearest values, one or several. Default: `-1`. | | `bins` | `int` | `50` | The number of bins, shared by all times. Default: 50. | | `log` | `bool` | `True` | A logarithmic count axis. Default: True. | | `density` | `bool` | `True` | Normalize each histogram to unit area. Default: True. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: the noise estimate at the last time shown. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and one outline per time; `data["statistics"]`. See Also [`plasma_plots.plotting.plot_weight_histogram()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_weight_histogram) : The function behind this method. [`DatasetAnalysis.weight_statistics()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.weight_statistics) : The numbers. Examples ```python >>> orbits.plasma.plot.weight_histogram(t=[0, 0.5, -1]) ``` ### `marker_density` [Section titled “marker\_density”](#marker_density) ### `marker_density`method[#](#plasma_plots.accessors.DatasetPlots.marker_density) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5353-L5405 "src/plasma_plots/accessors.py:5353-5405") ``` def marker_density(x: str = 'eta1', weight: str | None = 'weight', against: xr.DataArray | None = None, bins: int = 32, normalize: bool = True, ax=None, title: str | None = None, backend: Backend | None = None, **selection) ``` Plot where the markers are against what they represent, along one coordinate. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `'eta1'` | The position variable to bin over, e.g. `"eta1"` or `"x"`. Default: `"eta1"`. | | `weight` | `str` | `'weight'` | The weight variable, for the weighted density; `None` leaves it out. Default: `"weight"` (skipped when the Dataset has no such variable). | | `against` | `xarray.DataArray` | `None` | A reference profile over the same coordinate (every other dimension selected, or with `t` matching `markers`), drawn dashed. Default: none. | | `bins` | `int` | `32` | The number of bins. Default: 32. | | `normalize` | `bool` | `True` | Divide each profile by the mean of its magnitude, so that the shapes compare (a δf perturbation sums to nearly nothing, so its plain mean would not do). Default: True. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: `"marker density"`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | The time: `t=-1` (default, the last) or a float nearest value. | Returns * `PlotResult` The figure, the axes and the lines; `data` holds the densities. See Also [`plasma_plots.plotting.plot_marker_density()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_marker_density) : The function behind this method. [`DatasetAnalysis.marker_density()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.marker_density) : The binned densities. Examples ```python >>> orbits.plasma.plot.marker_density( ... x="eta1", against=n.isel(eta2=0, eta3=0), t=-1 ... ) ``` ### `lost_fraction` [Section titled “lost\_fraction”](#lost_fraction) ### `lost_fraction`method[#](#plasma_plots.accessors.DatasetPlots.lost_fraction) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5407-L5445 "src/plasma_plots/accessors.py:5407-5445") ``` def lost_fraction(weight: str | None = None, percent: bool = True, ax=None, title: str | None = None, backend: Backend | None = None) ``` Plot the fraction of markers lost from the domain, against time. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `weight` | `str` | `None` | Weigh each marker by its initial value of this variable, i.e. count particles rather than markers. Default: count markers. | | `percent` | `bool` | `True` | Show percentages. Default: True. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The title. Default: the final fraction. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the line; `data["lost_fraction"]`. See Also [`plasma_plots.plotting.plot_lost_fraction()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_lost_fraction) : The function behind this method. [`DatasetAnalysis.lost_fraction()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.lost_fraction) : The fraction alone. Examples ```python >>> orbits.plasma.plot.lost_fraction(weight="weight") ``` ### `loss_map` [Section titled “loss\_map”](#loss_map) ### `loss_map`method[#](#plasma_plots.accessors.DatasetPlots.loss_map) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5447-L5490 "src/plasma_plots/accessors.py:5447-5490") ``` def loss_map(x: str = 'v_par', y: str | None = None, t=0, absB=None, ax=None, s: int = 10, cmap=None, title: str | None = None, backend: Backend | None = None) ``` Plot which markers are lost, over their initial phase-space position, colored by when. Parameters | Name | Type | Default | Description | | --------- | ----------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `'v_par'` | The quantity along the horizontal axis: a variable, or `"energy"`, `"pitch"` or `"speed"` (see [`loss_map()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.loss_map)). Default: `"v_par"`. | | `y` | `str` | `None` | The vertical one. Default: `"mu"`, or `"v_perp"` without `mu`. | | `t` | `int or float` | `0` | The time of the plotted positions: an integer position (default `0`) or a float nearest value. | | `absB` | `callable` | `None` | `\|B\|(x, y, z)`, for `"energy"` and `"pitch"`. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `s` | `int` | `10` | The marker size, in points². Default: 10. | | `cmap` | `str or matplotlib.colors.Colormap` | `None` | The colormap of the loss time. Default: `"plasma"`. | | `title` | `str` | `None` | The title. Default: how many markers are lost. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the scatters; `data["losses"]`. See Also [`plasma_plots.plotting.plot_loss_map()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_loss_map) : The function behind this method. [`DatasetData.loss_map()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetData.loss_map) : The values, without plotting them. [`DatasetPlots.orbit_classification()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbit_classification) : Passing, trapped and lost markers. Examples ```python >>> orbits.plasma.plot.loss_map(x="energy", y="pitch", absB=absB) ``` ## dataset.plasma.analysis [Section titled “dataset.plasma.analysis”](#datasetplasmaanalysis) Quantitative diagnostics of one dataset, as `dataset.plasma.analysis.(...)`. ### `classify_orbits` [Section titled “classify\_orbits”](#classify_orbits) ### `classify_orbits`method[#](#plasma_plots.accessors.DatasetAnalysis.classify_orbits) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4227-L4248 "src/plasma_plots/accessors.py:4227-4248") ``` def classify_orbits(v_par: str = 'v_par') -> xr.DataArray ``` Classify each marker of this guiding-center orbits product: passing (0), trapped (1) or lost (-1). See [`plasma_plots.analysis.classify_orbits()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.classify_orbits) for the criteria. Parameters | Name | Type | Default | Description | | ------- | ----- | --------- | --------------------------------------------------------------- | | `v_par` | `str` | `'v_par'` | The name of the parallel-velocity variable. Default: `"v_par"`. | Returns * `xarray.DataArray` The class of each marker, over `marker`. See Also [`plasma_plots.analysis.classify_orbits()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.classify_orbits) : The function behind this method. [`DatasetPlots.orbit_classification()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbit_classification) : The markers in a phase-space plane, colored by class. Examples ```python >>> orbits.plasma.analysis.classify_orbits() ``` ### `orbit_invariants` [Section titled “orbit\_invariants”](#orbit_invariants) ### `orbit_invariants`method[#](#plasma_plots.accessors.DatasetAnalysis.orbit_invariants) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4250-L4268 "src/plasma_plots/accessors.py:4250-4268") ``` def orbit_invariants(absB=None) -> xr.Dataset ``` Return the speed, guiding-centre energy and pitch of the saved orbits. Parameters | Name | Type | Default | Description | | ------ | ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `absB` | `callable` | `None` | `\|B\|(x, y, z)` as a function of the physical positions (numpy arrays), e.g. `lambda x, y, z: out.equil.absB0(*out.domain.inverse_map(x, y, z))`. Needed for the energy and the pitch. | Returns * `xarray.Dataset` The invariants per marker and time. See Also [`plasma_plots.analysis.orbit_invariants()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.orbit_invariants) : The function behind this method. Examples ```python >>> orbits.plasma.analysis.orbit_invariants(absB=absB_xyz) ``` ### `bounce_period` [Section titled “bounce\_period”](#bounce_period) ### `bounce_period`method[#](#plasma_plots.accessors.DatasetAnalysis.bounce_period) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4270-L4289 "src/plasma_plots/accessors.py:4270-4289") ``` def bounce_period(v_par: str = 'v_par') -> xr.DataArray ``` Return the bounce period of each trapped marker. Parameters | Name | Type | Default | Description | | ------- | ----- | --------- | --------------------------------------------------------------- | | `v_par` | `str` | `'v_par'` | The name of the parallel-velocity variable. Default: `"v_par"`. | Returns * `xarray.DataArray` The bounce period over `marker`. See Also [`plasma_plots.analysis.bounce_period()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.bounce_period) : The function behind this method. [`DatasetAnalysis.classify_orbits()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.classify_orbits) : Which markers are trapped. Examples ```python >>> orbits.plasma.analysis.bounce_period() ``` ### `surface_average` [Section titled “surface\_average”](#surface_average) ### `surface_average`method[#](#plasma_plots.accessors.DatasetAnalysis.surface_average) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4291-L4327 "src/plasma_plots/accessors.py:4291-4327") ``` def surface_average(name: str, *, jacobian: str | None = 'Jac', domain=None, quadrature=None) -> xr.DataArray ``` Return the flux-surface average of one variable, with this Dataset’s Jacobian. Parameters | Name | Type | Default | Description | | ------------ | ---------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `str` | required | The variable, e.g. `"mod_B"`. | | `jacobian` | `str or None` | `'Jac'` | The variable holding `√g`, used if the Dataset has it. `None` (or a missing variable) takes `domain`, else the numerical Jacobian of `X`, `Y`, `Z`. Default: `"Jac"`, GVEC’s. | | `domain` | `struphy domain` | `None` | The mapping, for the exact `√g` of a Struphy run. | | `quadrature` | `dict` | `None` | Explicit weights for the angles, as for \[`volume_integral()`]\[volume\_integral]. | Returns * `xarray.DataArray` `⟨name⟩` over the radius and every non-spatial dimension. See Also [`plasma_plots.analysis.surface_average()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.surface_average) : The function behind this method. Examples ```python >>> ev.plasma.analysis.surface_average("mod_B") ``` ### `poincare_section` [Section titled “poincare\_section”](#poincare_section) ### `poincare_section`method[#](#plasma_plots.accessors.DatasetAnalysis.poincare_section) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4329-L4348 "src/plasma_plots/accessors.py:4329-4348") ``` def poincare_section(angle: float | None = None) -> xr.Dataset ``` Return the punctures of a poloidal plane by these traced field lines. Parameters | Name | Type | Default | Description | | ------- | ------- | ------- | -------------------------------------------------------------------------- | | `angle` | `float` | `None` | The toroidal logical coordinate of the plane. Default: the traced section. | Returns * `xarray.Dataset` The punctures over `(puncture, line)`. See Also [`plasma_plots.fieldlines.poincare_section()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.poincare_section) : The function behind this method. [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) : The plot. Examples ```python >>> lines.plasma.analysis.poincare_section(angle=np.pi / 5) ``` ### `rotational_transform` [Section titled “rotational\_transform”](#rotational_transform) ### `rotational_transform`method[#](#plasma_plots.accessors.DatasetAnalysis.rotational_transform) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4350-L4368 "src/plasma_plots/accessors.py:4350-4368") ``` def rotational_transform() -> xr.DataArray ``` Return the rotational transform of each traced field line. Returns * `xarray.DataArray` `iota` over `line`. See Also [`plasma_plots.fieldlines.rotational_transform()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.rotational_transform) : The function behind this method. Examples ```python >>> lines.plasma.analysis.rotational_transform() ``` ### `classify_field_lines` [Section titled “classify\_field\_lines”](#classify_field_lines) ### `classify_field_lines`method[#](#plasma_plots.accessors.DatasetAnalysis.classify_field_lines) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4370-L4402 "src/plasma_plots/accessors.py:4370-4402") ``` def classify_field_lines(max_denominator: int = 12, tolerance: float | None = None, threshold: float = 0.1, min_spread: float | None = None) -> xr.DataArray ``` Classify each traced field line: on a flux surface (0), in an island (1) or chaotic (2). Parameters | Name | Type | Default | Description | | ----------------- | ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `max_denominator` | `int` | `12` | The largest `m` of the rationals considered. Default: 12. | | `tolerance` | `float` | `None` | How close ι must be to `n/m`. Default: two over the number of toroidal transits of the line (the resolution of ι from the trace), at least 1e-3. | | `threshold` | `float` | `0.1` | The median radial jump between punctures that are neighbours in the poloidal angle, relative to the line’s radial spread, above which a non-librating line is chaotic (a smooth curve through 100 punctures gives a few hundredths). Default: 0.1. | | `min_spread` | `float` | `None` | The radial spread of the punctures (in the radial logical coordinate) below which a line is on a surface. Default: half the radial grid spacing of the traced field. | Returns * `xarray.DataArray` The class of each line over `line`. See Also [`plasma_plots.fieldlines.classify_field_lines()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.classify_field_lines) : The function behind this method. [`DatasetAnalysis.islands()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.islands) : The island chains and their widths. Examples ```python >>> lines.plasma.analysis.classify_field_lines() ``` ### `islands` [Section titled “islands”](#islands) ### `islands`method[#](#plasma_plots.accessors.DatasetAnalysis.islands) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4404-L4436 "src/plasma_plots/accessors.py:4404-4436") ``` def islands(max_denominator: int = 12, tolerance: float | None = None, threshold: float = 0.1, min_spread: float | None = None) -> xr.Dataset ``` Return the island chains these traced field lines show, with their widths. Parameters | Name | Type | Default | Description | | ----------------- | ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `max_denominator` | `int` | `12` | The largest `m` of the rationals considered. Default: 12. | | `tolerance` | `float` | `None` | How close ι must be to `n/m`; see [`classify_field_lines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.classify_field_lines). | | `threshold` | `float` | `0.1` | The chaos criterion of [`classify_field_lines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.classify_field_lines). Default: 0.1. | | `min_spread` | `float` | `None` | The surface criterion of [`classify_field_lines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.classify_field_lines). Default: half the radial grid spacing. | Returns * `xarray.Dataset` Over `chain`: `n`, `m`, `width`, `center`, … See Also [`plasma_plots.fieldlines.islands()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.islands) : The function behind this method. [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) : `islands=True` labels them. Examples ```python >>> lines.plasma.analysis.islands().to_dataframe() ``` ### `footprint` [Section titled “footprint”](#footprint-1) ### `footprint`method[#](#plasma_plots.accessors.DatasetAnalysis.footprint) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4438-L4457 "src/plasma_plots/accessors.py:4438-4457") ``` def footprint() -> xr.Dataset ``` Return where these traced field lines left the grid, with their connection lengths. Returns * `xarray.Dataset` The exit points over `line`. See Also [`plasma_plots.fieldlines.footprint()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.footprint) : The function behind this method. [`DatasetPlots.footprint()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.footprint) : The plot. Examples ```python >>> edge.plasma.analysis.footprint() ``` ### `seed_grid` [Section titled “seed\_grid”](#seed_grid) ### `seed_grid`method[#](#plasma_plots.accessors.DatasetAnalysis.seed_grid) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4459-L4478 "src/plasma_plots/accessors.py:4459-4478") ``` def seed_grid(name: str = 'connection_length') -> xr.DataArray ``` Return a per-line quantity of these field lines over their grid of seeds. Parameters | Name | Type | Default | Description | | ------ | ----- | --------------------- | ------------------------------------------------------ | | `name` | `str` | `'connection_length'` | The per-line variable. Default: `"connection_length"`. | Returns * `xarray.DataArray` `name` over the two varying seed coordinates. See Also [`plasma_plots.fieldlines.seed_grid()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.seed_grid) : The function behind this method. [`DatasetPlots.connection_length()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.connection_length) : The plot of the connection lengths. Examples ```python >>> edge.plasma.analysis.seed_grid("connection_length").plasma.plot.slice() ``` ### `weight_statistics` [Section titled “weight\_statistics”](#weight_statistics) ### `weight_statistics`method[#](#plasma_plots.accessors.DatasetAnalysis.weight_statistics) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4480-L4499 "src/plasma_plots/accessors.py:4480-4499") ``` def weight_statistics(weight: str = 'weight') -> xr.Dataset ``` Return the statistics of the marker weights over time, with the noise estimate. Parameters | Name | Type | Default | Description | | -------- | ----- | ---------- | ---------------------------------------------------- | | `weight` | `str` | `'weight'` | The weight variable. Default: `"weight"`, Struphy’s. | Returns * `xarray.Dataset` `mean`, `std`, `total`, `noise`, `effective_markers`, … over `t`. See Also [`plasma_plots.analysis.weight_statistics()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.weight_statistics) : The function behind this method. [`DatasetPlots.weight_histogram()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.weight_histogram) : The distribution of the weights. Examples ```python >>> orbits.plasma.analysis.weight_statistics().noise.plasma.plot.timeseries() ``` ### `marker_density` [Section titled “marker\_density”](#marker_density-1) ### `marker_density`method[#](#plasma_plots.accessors.DatasetAnalysis.marker_density) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4501-L4524 "src/plasma_plots/accessors.py:4501-4524") ``` def marker_density(dims=('eta1'), bins=32, weight: str | None = None, ranges=None) -> xr.DataArray ``` Return the markers binned over position variables, per unit volume. Parameters | Name | Type | Default | Description | | -------- | ------------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------- | | `dims` | `str or sequence of str` | `('eta1')` | The position variables to bin over, e.g. `("eta1",)` or `("x", "y")`. Default: `("eta1",)`. | | `bins` | `int or sequence of int` | `32` | The number of bins, for all or for each. Default: 32. | | `weight` | `str` | `None` | Weigh each marker by this variable, e.g. `"weight"`. Default: count the markers. | | `ranges` | `dict` | `None` | `{variable: (low, high)}` bin ranges. Default: `(0, 1)` for the logical `eta` coordinates, the markers’ extent otherwise. | Returns * `xarray.DataArray` The density over `t` and the binned variables. See Also [`plasma_plots.analysis.marker_density()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.marker_density) : The function behind this method. [`DatasetPlots.marker_density()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.marker_density) : Sampling against physical density. Examples ```python >>> orbits.plasma.analysis.marker_density(dims="eta1", weight="weight") ``` ### `lost_fraction` [Section titled “lost\_fraction”](#lost_fraction-1) ### `lost_fraction`method[#](#plasma_plots.accessors.DatasetAnalysis.lost_fraction) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4526-L4545 "src/plasma_plots/accessors.py:4526-4545") ``` def lost_fraction(weight: str | None = None) -> xr.DataArray ``` Return the fraction of markers lost from the domain, over time. Parameters | Name | Type | Default | Description | | -------- | ----- | ------- | ----------------------------------------------------------------------------------------------------- | | `weight` | `str` | `None` | Weigh each marker by its initial value of this variable, e.g. `"weight"`. Default: count the markers. | Returns * `xarray.DataArray` The fraction over `t`. See Also [`plasma_plots.analysis.lost_fraction()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.lost_fraction) : The function behind this method. [`DatasetPlots.lost_fraction()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.lost_fraction) : The plot. Examples ```python >>> orbits.plasma.analysis.lost_fraction(weight="weight") ``` ### `loss_map` [Section titled “loss\_map”](#loss_map-1) ### `loss_map`method[#](#plasma_plots.accessors.DatasetAnalysis.loss_map) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L4547-L4568 "src/plasma_plots/accessors.py:4547-4568") ``` def loss_map(x: str = 'v_par', y: str | None = None, t=0, absB=None) -> xr.Dataset ``` Return each marker’s initial phase-space position, whether it is lost, and when. Parameters | Name | Type | Default | Description | | ------ | -------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `'v_par'` | The first quantity. Default: `"v_par"`. | | `y` | `str` | `None` | The second quantity. Default: `"mu"`, or `"v_perp"` without `mu`. | | `t` | `int or float` | `0` | The time of the plotted values: an integer position (default `0`, the initial one) or a float nearest value. | | `absB` | `callable` | `None` | `\|B\|(x, y, z)`, for `"energy"` and `"pitch"` (see [`orbit_invariants()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetAnalysis.orbit_invariants)). | Returns * `xarray.Dataset` `x`, `y`, `lost` and `loss_time` over `marker`. See Also [`plasma_plots.analysis.loss_map()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.loss_map) : The function behind this method. [`DatasetPlots.loss_map()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.loss_map) : The plot. Examples ```python >>> orbits.plasma.analysis.loss_map(x="energy", y="pitch", absB=absB) ``` ## dataset.plasma.data [Section titled “dataset.plasma.data”](#datasetplasmadata) The data behind each plot in :class:`DatasetPlots`, without rendering it. ### `trajectories` [Section titled “trajectories”](#trajectories-1) ### `trajectories`method[#](#plasma_plots.accessors.DatasetData.trajectories) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5504-L5529 "src/plasma_plots/accessors.py:5504-5529") ``` def trajectories(max_markers: int = 200) -> xr.Dataset ``` Return the marker-position subset [`DatasetPlots.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.trajectories) would plot. Parameters | Name | Type | Default | Description | | ------------- | ----- | ------- | ---------------------------------------------------------- | | `max_markers` | `int` | `200` | Draw only the first `max_markers` markers. Default: `200`. | Returns * `xarray.Dataset` The orbits of the first `max_markers` markers. Raises * `ValueError` If the orbits lack `x`, `y` or `z`, or a `marker` dimension. See Also [`DatasetPlots.trajectories()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.trajectories) : The plot of these markers. Examples ```python >>> markers.plasma.data.trajectories(max_markers=50) ``` ### `scatter` [Section titled “scatter”](#scatter-1) ### `scatter`method[#](#plasma_plots.accessors.DatasetData.scatter) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5531-L5560 "src/plasma_plots/accessors.py:5531-5560") ``` def scatter(x: str, y: str, color: str | None = None, color_at=None, **selection) -> xr.Dataset ``` Return the per-marker positions and colors [`DatasetPlots.scatter()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.scatter) would plot. `.to_dataframe()` hands them straight to e.g. Plotly Express. Parameters | Name | Type | Default | Description | | ------------- | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | required | The variables for the horizontal and vertical axes. | | `y` | `str` | required | The variables for the horizontal and vertical axes. | | `color` | `str` | `None` | The variable to color by. Default: none. | | `color_at` | `int or float` | `None` | Take the colors at another time (an integer position such as `0`, or a float value). Default: at the selected time. | | `**selection` | | `{}` | The other dimensions, e.g. `t`: an integer is a position (`t=-1` the last), a float the nearest coordinate value. | Returns * `xarray.Dataset` `x`, `y` and `color` over `marker`. See Also [`plasma_plots.plotting.prepare_marker_scatter()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_marker_scatter) : The function behind this method. [`DatasetPlots.scatter()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.scatter) : The plot of these markers. Examples ```python >>> markers.plasma.data.scatter( ... x="x", y="y", color="density", t=-1 ... ).to_dataframe() >>> # colored by the start >>> markers.plasma.data.scatter(x="x", y="y", color="x", color_at=0, t=-1) ``` ### `orbit_classification` [Section titled “orbit\_classification”](#orbit_classification-1) ### `orbit_classification`method[#](#plasma_plots.accessors.DatasetData.orbit_classification) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5562-L5585 "src/plasma_plots/accessors.py:5562-5585") ``` def orbit_classification(x: str = 'v_par', y: str | None = None, v_par: str = 'v_par', t=0) -> xr.Dataset ``` Return the per-marker `x`, `y` and `classification` that orbit\_classification plots. The values [`DatasetPlots.orbit_classification()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbit_classification) would plot. Parameters | Name | Type | Default | Description | | ------- | -------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `x` | `str` | `'v_par'` | The quantity along the horizontal axis. Default: `"v_par"`. | | `y` | `str` | `None` | The quantity along the vertical axis. Default: the magnetic moment `mu` (Particles5D), or `v_perp` if there is no `mu` (Particles5Dvperp). | | `v_par` | `str` | `'v_par'` | The parallel velocity the classification uses. Default: `"v_par"`. | | `t` | `int or float` | `0` | The time of the plotted values: an integer position (default `0`, the initial phase-space position, before any marker is lost; `-1` the last), or a float nearest value. | Returns * `xarray.Dataset` `x`, `y` and `classification` over `marker`. See Also [`DatasetPlots.orbit_classification()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.orbit_classification) : The plot of these values. [`plasma_plots.plotting.prepare_orbit_classification()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.prepare_orbit_classification) : The function that prepares them. Examples ```python >>> orbits.plasma.data.orbit_classification(x="p_phi") ``` ### `poincare` [Section titled “poincare”](#poincare-1) ### `poincare`method[#](#plasma_plots.accessors.DatasetData.poincare) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5587-L5606 "src/plasma_plots/accessors.py:5587-5606") ``` def poincare(angle: float | None = None) -> xr.Dataset ``` Return the punctures [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) would plot. Parameters | Name | Type | Default | Description | | ------- | ------- | ------- | -------------------------------------------------------------------------- | | `angle` | `float` | `None` | The toroidal logical coordinate of the plane. Default: the traced section. | Returns * `xarray.Dataset` The punctures over `(puncture, line)`. See Also [`plasma_plots.fieldlines.poincare_section()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.poincare_section) : The function behind this method. [`DatasetPlots.poincare()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.poincare) : The plot of these punctures. Examples ```python >>> lines.plasma.data.poincare().to_dataframe() ``` ### `footprint` [Section titled “footprint”](#footprint-2) ### `footprint`method[#](#plasma_plots.accessors.DatasetData.footprint) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5608-L5627 "src/plasma_plots/accessors.py:5608-5627") ``` def footprint() -> xr.Dataset ``` Return the exit points [`DatasetPlots.footprint()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.footprint) would plot. Returns * `xarray.Dataset` The exit points over `line`, with the connection lengths. See Also [`plasma_plots.fieldlines.footprint()`](/plasma-plots/api/plasma_plots/fieldlines/#plasma_plots.fieldlines.footprint) : The function behind this method. [`DatasetPlots.footprint()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.footprint) : The plot of these points. Examples ```python >>> edge.plasma.data.footprint() ``` ### `loss_map` [Section titled “loss\_map”](#loss_map-2) ### `loss_map`method[#](#plasma_plots.accessors.DatasetData.loss_map) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L5629-L5650 "src/plasma_plots/accessors.py:5629-5650") ``` def loss_map(x: str = 'v_par', y: str | None = None, t=0, absB=None) -> xr.Dataset ``` Return the per-marker values [`DatasetPlots.loss_map()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.loss_map) would plot. Parameters | Name | Type | Default | Description | | ------ | -------------- | --------- | ------------------------------------------------------------------------------------------------------------ | | `x` | `str` | `'v_par'` | The first quantity. Default: `"v_par"`. | | `y` | `str` | `None` | The second quantity. Default: `"mu"`, or `"v_perp"` without `mu`. | | `t` | `int or float` | `0` | The time of the plotted values: an integer position (default `0`, the initial one) or a float nearest value. | | `absB` | `callable` | `None` | `\|B\|(x, y, z)`, for `"energy"` and `"pitch"` (see \[`orbit_invariants()`]\[orbit\_invariants]). | Returns * `xarray.Dataset` `x`, `y`, `lost` and `loss_time` over `marker`. See Also [`plasma_plots.analysis.loss_map()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.loss_map) : The function behind this method. [`DatasetPlots.loss_map()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.DatasetPlots.loss_map) : The plot of these values. Examples ```python >>> orbits.plasma.data.loss_map(x="energy", y="pitch", absB=absB) ``` # out.plot and out.analysis > Whole-run plots and diagnostics of a Struphy Output. Plots and diagnostics of a whole run, on a Struphy `Output` object. `out.plot()` on its own draws the scalar overview. Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## out.plot [Section titled “out.plot”](#outplot) Plots of a whole run, as `out.plot.(...)`, constructed as `OutputPlots(out)`. ### `scalars` [Section titled “scalars”](#scalars) ### `scalars`method[#](#plasma_plots.output_accessors.OutputPlots.scalars) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L181-L228 "src/plasma_plots/output_accessors.py:181-228") ``` def scalars(names=None, *, relative_to: str | None = None, logy: bool = False, backend: Backend | None = None) ``` Overview of the scalar time series in one axes. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `names` | `list of str` | `None` | Scalars to show; all by default. | | `relative_to` | `str` | `None` | Show every scalar divided by this one. | | `logy` | `bool` | `False` | Logarithmic value axis. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn lines, titled with the run’s label. See Also [`plasma_plots.plotting.plot_scalars()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_scalars) : The function behind this method. Examples ```python >>> out.plot.scalars() >>> out.plot.scalars(["en_U", "en_B"], logy=True) ``` ### `energies` [Section titled “energies”](#energies) ### `energies`method[#](#plasma_plots.output_accessors.OutputPlots.energies) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L230-L282 "src/plasma_plots/output_accessors.py:230-282") ``` def energies(parts=None, total: str | None = 'en_tot', groups: dict | None = None, logy: bool = False, backend: Backend | None = None) ``` Plot the run’s energy budget from its energy scalars (`en_*` or `*_energy`). Shows the energy scalars, the relative drift of `total`, and, with `groups` (e.g. `{"wave": ["en_U", "en_B", "en_p"], "energetic ions": ["en_fv", "en_fB"]}`), the energy exchanged between them. Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `parts` | `sequence of str` | `None` | The energies drawn in the first panel. Default: the scalars \[`energy_names()`]\[energy\_names] finds (`en_*` and `*_energy`), except `total`. | | `total` | `str or None` | `'en_tot'` | The total energy; the second panel is left out if it is `None` or not among the scalars. Default: `"en_tot"`, or `"total_energy"` for a run that names its energies that way. | | `groups` | `dict of str to list of str` | `None` | A label to the names it sums, e.g. `{"wave": ["en_U", "en_B", "en_p"], "energetic ions": ["en_fv", "en_fB"]}`. Default: no exchange panel. | | `logy` | `bool` | `False` | Use a logarithmic value axis in the first panel. Default: `False`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn lines, titled with the run’s label. See Also [`plasma_plots.plotting.plot_energy_budget()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_energy_budget) : The function behind this method. Examples ```python >>> out.plot.energies() >>> out.plot.energies( ... groups={ ... "wave": ["en_U", "en_B", "en_p"], ... "energetic ions": ["en_fv", "en_fB"], ... } ... ) ``` ### `equilibrium` [Section titled “equilibrium”](#equilibrium) ### `equilibrium`method[#](#plasma_plots.output_accessors.OutputPlots.equilibrium) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L284-L311 "src/plasma_plots/output_accessors.py:284-311") ``` def equilibrium(ax=None, *, backend: Backend | None = None) ``` Plot radial profiles of this run’s fluid equilibrium (`out.equil`, `out.domain`). Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and the drawn lines. See Also [`plasma_plots.plotting.plot_equilibrium_profile()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_equilibrium_profile) : The function behind this method. Examples ```python >>> out.plot.equilibrium() ``` ### `equilibrium_3d` [Section titled “equilibrium\_3d”](#equilibrium_3d) ### `equilibrium_3d`method[#](#plasma_plots.output_accessors.OutputPlots.equilibrium_3d) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L313-L333 "src/plasma_plots/output_accessors.py:313-333") ``` def equilibrium_3d(scalars: str = 'p0', cmap='viridis') ``` Create a PyVista view of this run’s fluid equilibrium; call `.show()` on the returned plotter. Parameters | Name | Type | Default | Description | | --------- | ----- | ----------- | ---------------------------------------------------------------------- | | `scalars` | `str` | `'p0'` | One of `equil`’s profile methods (`"p0"`, `"n0"`, …). Default: `"p0"`. | | `cmap` | `str` | `'viridis'` | The colormap. Default: `"viridis"`. | Returns * `pyvista.Plotter` The scene, not yet shown. See Also [`plasma_plots.plotting.show_equilibrium()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.show_equilibrium) : The function behind this method. Examples ```python >>> out.plot.equilibrium_3d(scalars="p0").show() ``` ### `domain_3d` [Section titled “domain\_3d”](#domain_3d) ### `domain_3d`method[#](#plasma_plots.output_accessors.OutputPlots.domain_3d) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L335-L356 "src/plasma_plots/output_accessors.py:335-356") ``` def domain_3d(n1: int = 8, n2: int = 32, n3: int = 32, surface: bool = True) ``` Draw a PyVista wireframe of this run’s mapping (`out.domain`); call `.show()` on it. Parameters | Name | Type | Default | Description | | --------- | ------ | ------- | ------------------------------------------------------- | | `n1` | `int` | `8` | Grid lines along `eta1`. Default: 8. | | `n2` | `int` | `32` | Grid lines along `eta2`. Default: 32. | | `n3` | `int` | `32` | Grid lines along `eta3`. Default: 32. | | `surface` | `bool` | `True` | Draw the translucent boundary surface. Default: `True`. | Returns * `pyvista.Plotter` The scene, not yet shown. See Also [`plasma_plots.pyvista_plots.pyvista_domain()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.pyvista_domain) : The function behind this method. Examples ```python >>> out.plot.domain_3d().show() >>> out.plot.domain_3d(n3=1).show() ``` ### `profile` [Section titled “profile”](#profile) ### `profile`property[#](#plasma_plots.output_accessors.OutputPlots.profile) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L359-L370 "src/plasma_plots/output_accessors.py:359-370") ``` profile: 'ProfilePlots' ``` Plots of this run’s timing regions, e.g. `out.plot.profile.gantt()`. Needs the optional `scope-profiler` extra (`pip install "plasma-plots[profiling]"`) and a run recorded with `sim.run(profiling_activated=True)`. Returns * `ProfilePlots` The profiling plots of this run. ## out.plot.profile [Section titled “out.plot.profile”](#outplotprofile) Plots of one run’s timing regions (`out.profile.results`), as `out.plot.profile.(...)`. ### `gantt` [Section titled “gantt”](#gantt) ### `gantt`method[#](#plasma_plots.output_accessors.ProfilePlots.gantt) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L55-L87 "src/plasma_plots/output_accessors.py:55-87") ``` def gantt(return_fig: bool = True, verbose: bool = False, **kwargs) ``` A timeline of every recorded region, one row per rank. Parameters | Name | Type | Default | Description | | ------------ | ------ | ------- | -------------------------------------------------------------------------------------------------------------------- | | `return_fig` | `bool` | `True` | Return the rendered figure (scope-profiler’s own default is to return `None`). Default: `True`. | | `verbose` | `bool` | `False` | Let scope-profiler print progress information. Default: `False`. | | `**kwargs` | | `{}` | Passed on to scope-profiler’s `plot_gantt` (`ranks`, `include`/`exclude`, `backend`, `filepath`, `min_duration`, …). | Returns * `tuple or plotly.graph_objects.Figure or None` Whatever scope-profiler returns: `(fig, axes)` for the default matplotlib backend, a Plotly figure with `backend="plotly"`, `None` with `return_fig=False`. Examples ```python >>> out.plot.profile.gantt() ``` ### `flame` [Section titled “flame”](#flame) ### `flame`method[#](#plasma_plots.output_accessors.ProfilePlots.flame) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L89-L121 "src/plasma_plots/output_accessors.py:89-121") ``` def flame(return_fig: bool = True, verbose: bool = False, **kwargs) ``` A flame chart reconstructing the call stack from region timings. Parameters | Name | Type | Default | Description | | ------------ | ------ | ------- | ---------------------------------------------------------------------------------------------------- | | `return_fig` | `bool` | `True` | Return the rendered figure (scope-profiler’s own default is to return `None`). Default: `True`. | | `verbose` | `bool` | `False` | Let scope-profiler print progress information. Default: `False`. | | `**kwargs` | | `{}` | Passed on to scope-profiler’s `plot_flame` (`ranks`, `include`/`exclude`, `backend`, `filepath`, …). | Returns * `tuple or plotly.graph_objects.Figure or None` Whatever scope-profiler returns: `(fig, axes)` for the default matplotlib backend, a Plotly figure with `backend="plotly"`, `None` with `return_fig=False`. Examples ```python >>> out.plot.profile.flame() ``` ### `callgraph` [Section titled “callgraph”](#callgraph) ### `callgraph`method[#](#plasma_plots.output_accessors.ProfilePlots.callgraph) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L123-L155 "src/plasma_plots/output_accessors.py:123-155") ``` def callgraph(return_fig: bool = True, verbose: bool = False, **kwargs) ``` The explicit call graph (which region calls which), without timings. Parameters | Name | Type | Default | Description | | ------------ | ------ | ------- | --------------------------------------------------------------------------------------------------------------- | | `return_fig` | `bool` | `True` | Return the rendered figure (scope-profiler’s own default is to return `None`). Default: `True`. | | `verbose` | `bool` | `False` | Let scope-profiler print progress information. Default: `False`. | | `**kwargs` | | `{}` | Passed on to scope-profiler’s `plot_callgraph` (`rank`, `include`/`exclude`, `backend`, `compact`, `fluid`, …). | Returns * `tuple or plotly.graph_objects.Figure or None` Whatever scope-profiler returns: `(fig, axes)` for the default matplotlib backend, a Plotly figure with `backend="plotly"`, `None` with `return_fig=False`. Examples ```python >>> out.plot.profile.callgraph() ``` ## out.analysis [Section titled “out.analysis”](#outanalysis) Spectral diagnostics of a run’s products, as `out.analysis.(product, ...)`. ### `fft` [Section titled “fft”](#fft) ### `fft`method[#](#plasma_plots.output_accessors.OutputAnalysis.fft) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L530-L556 "src/plasma_plots/output_accessors.py:530-556") ``` def fft(product, *, dim: str, detrend: bool = False, window: str | None = None) ``` Compute two-sided Fourier coefficients of a product along `dim`. Parameters | Name | Type | Default | Description | | --------- | ------------------------- | -------- | ---------------------------------------------------------------------------------------------------- | | `product` | `str or xarray.DataArray` | required | A product name (e.g. `"mhd/velocity"`), evaluated with `out.evaluate`, or an already selected array. | | `dim` | `str` | required | The dimension to transform. | | `detrend` | `bool` | `False` | Subtract the mean along `dim` first. Default: False. | | `window` | `(None, 'hann')` | `None` | Multiply by a periodic Hann window (see \[`hann()`]\[hann]) first. Default: None (boxcar). | Returns * `xarray.DataArray` Complex coefficients, with `dim` replaced by `omega` (time) or `k_`. See Also [`plasma_plots.spectral.fft()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.fft) : The function behind this method. Examples ```python >>> out.analysis.fft(phi.isel(t=-1, eta2=0, eta3=0), dim="eta1") ``` ### `time_fft` [Section titled “time\_fft”](#time_fft) ### `time_fft`method[#](#plasma_plots.output_accessors.OutputAnalysis.time_fft) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L558-L582 "src/plasma_plots/output_accessors.py:558-582") ``` def time_fft(product, *, detrend: bool = False, window: str | None = None) ``` Compute one-sided temporal Fourier coefficients and per-bin power of a product. Parameters | Name | Type | Default | Description | | --------- | ------------------------- | -------- | ---------------------------------------------------------------------------------------------------- | | `product` | `str or xarray.DataArray` | required | A product name (e.g. `"mhd/velocity"`), evaluated with `out.evaluate`, or an already selected array. | | `detrend` | `bool` | `False` | Subtract the temporal mean first. Default: False. | | `window` | `(None, 'hann')` | `None` | Multiply by a periodic Hann window (see \[`hann()`]\[hann]) first. Default: None (boxcar). | Returns * `xarray.Dataset` The complex coefficients and the power over `omega`. See Also [`plasma_plots.spectral.time_fft()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.time_fft) : The function behind this method. Examples ```python >>> out.analysis.time_fft(phi.isel(eta1=0.5, eta2=0, eta3=0), window="hann") ``` ### `filter_time` [Section titled “filter\_time”](#filter_time) ### `filter_time`method[#](#plasma_plots.output_accessors.OutputAnalysis.filter_time) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L584-L613 "src/plasma_plots/output_accessors.py:584-613") ``` def filter_time(product, *, dims=None, omega_min: float = 1e-08, pad_bins: int = 0) ``` Reconstruct the dominant temporal frequency band of a product. Parameters | Name | Type | Default | Description | | ----------- | ------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `product` | `str or xarray.DataArray` | required | A product name (e.g. `"mhd/velocity"`), evaluated with `out.evaluate`, or an already selected array. | | `dims` | `str or sequence of str` | `None` | Non-time dimensions to sum the power over before choosing the band. Default: all dimensions except `t` and `component`. Pass `dims=()` for independent filtering at each point. | | `omega_min` | `float` | `1e-08` | Finite, positive lowest frequency considered, which excludes DC. Default: 1e-8. | | `pad_bins` | `int` | `0` | Nonnegative number of extra bins on each side of the band. Default: 0. | Returns * `TimeFilterResult` The filtered field and the reduced spectrum with the selected band. See Also [`plasma_plots.spectral.filter_time()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.filter_time) : The function behind this method. Examples ```python >>> result = out.analysis.filter_time(phi) >>> result.filtered.plasma.plot.slice(t=-1, eta3=0) ``` ### `linear_mhd_energies` [Section titled “linear\_mhd\_energies”](#linear_mhd_energies) ### `linear_mhd_energies`method[#](#plasma_plots.output_accessors.OutputAnalysis.linear_mhd_energies) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L615-L680 "src/plasma_plots/output_accessors.py:615-680") ``` def linear_mhd_energies(velocity='mhd/velocity', b_field='em_fields/b_field', pressure='mhd/pressure', gamma: float = 5 / 3) ``` Compute LinearMHD’s energy scalars from fields, as a Dataset of time series. The scalars are `en_U`, `en_B`, `en_thermal`, `en_p` and `en_tot = en_U + en_B + en_thermal`. Same definitions as the scalars saved during the run (`en_U = 1/2 u^T M2n u`, …), with the run’s `domain` and equilibrium (`n0`, `p0`), but evaluated by quadrature on the post-processing grid, so they also work for fields that were never simulated: pass a filtered array (e.g. `filter_time(...).filtered`) to get the energy in one mode. Each argument is a raw field name (evaluated at the Gauss points of [`quadrature_grid()`](/plasma-plots/api/plasma_plots/output_accessors/#plasma_plots.output_accessors.OutputAnalysis.quadrature_grid), in its FEEC space’s own representation), an array in that representation (on the Gauss grid its weights are exact; elsewhere see [`quadrature_weights()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.quadrature_weights)), or `None` to skip it: 2-form components for `velocity` and `b_field` (`out.evaluate("mhd/velocity", representation="2")`), a 3-form for `pressure` (`representation="3"`). The default post-processing products are in other representations (`"norm"`, `"0"`) and would give wrong energies. Points where `p0` vanishes are left out of `en_thermal`. Parameters | Name | Type | Default | Description | | ---------- | --------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------ | | `velocity` | `(str, xarray.DataArray or None)` | `'mhd/velocity'` | The velocity as 2-form components (`en_U`, weighted by `n0`). Default: `"mhd/velocity"`. | | `b_field` | `(str, xarray.DataArray or None)` | `'em_fields/b_field'` | The magnetic field as 2-form components (`en_B`). Default: `"em_fields/b_field"`. | | `pressure` | `(str, xarray.DataArray or None)` | `'mhd/pressure'` | The pressure as a 3-form (`en_thermal`, weighted by `1/p0`, and `en_p`). Default: `"mhd/pressure"`. | | `gamma` | `float` | `5 / 3` | The adiabatic index: `en_thermal` is normalized by `1/gamma` and `en_p = ∫ p / (gamma - 1)`. Default: `5/3`. | Returns * `xarray.Dataset` One time series per computed scalar (only those whose fields were given), plus `en_tot`. Raises * `ValueError` If `velocity`, `b_field` and `pressure` are all `None`. See Also [`quadrature_grid()`](/plasma-plots/api/plasma_plots/output_accessors/#plasma_plots.output_accessors.OutputAnalysis.quadrature_grid) : The Gauss points the raw fields are evaluated at. [`plasma_plots.analysis.field_energy()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.field_energy) : The energy integral of one field. Examples ```python >>> energies = out.analysis.linear_mhd_energies() >>> filtered = out.analysis.filter_time( ... out.evaluate("mhd/velocity", representation="2") ... ).filtered >>> out.analysis.linear_mhd_energies( ... velocity=filtered, b_field=None, pressure=None ... ) ``` ### `quadrature_grid` [Section titled “quadrature\_grid”](#quadrature_grid) ### `quadrature_grid`method[#](#plasma_plots.output_accessors.OutputAnalysis.quadrature_grid) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L682-L709 "src/plasma_plots/output_accessors.py:682-709") ``` def quadrature_grid() ``` Return the run’s Gauss-Legendre quadrature points and weights in each logical direction. The points (spline degree + 1 per element) and their weights for each of `eta1`, `eta2`, `eta3` form the grid on which spline fields squared integrate exactly. Evaluate a field there (`out.evaluate(name, eta1=etas["eta1"], ..., representation="2")`), filter it, and `linear_mhd_energies` or `field_energy(..., quadrature=weights)` give its energy as the run’s own scalars would. Returns * `etas``dict of str to numpy.ndarray` The points in `[0, 1]` for `"eta1"`, `"eta2"`, `"eta3"`. * `weights``dict of str to numpy.ndarray` The matching quadrature weights, summing to 1 in each direction. Examples ```python >>> etas, weights = out.analysis.quadrature_grid() >>> b = out.evaluate( ... "em_fields/b_field", ... eta1=etas["eta1"], ... eta2=etas["eta2"], ... eta3=etas["eta3"], ... representation="2", ... ) ``` ### `mode_spectrum` [Section titled “mode\_spectrum”](#mode_spectrum) ### `mode_spectrum`method[#](#plasma_plots.output_accessors.OutputAnalysis.mode_spectrum) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/output_accessors.py#L711-L740 "src/plasma_plots/output_accessors.py:711-740") ``` def mode_spectrum(product, *, dims=('eta2', 'eta3'), names=('m', 'n'), periods=1.0) ``` Compute complex amplitudes of a product over poloidal/toroidal mode numbers. Parameters | Name | Type | Default | Description | | --------- | ---------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `product` | `str or xarray.DataArray` | required | A product name (e.g. `"mhd/velocity"`), evaluated with `out.evaluate`, or an already selected array. | | `dims` | `str or sequence of str` | `('eta2', 'eta3')` | The periodic dimensions to transform. Default: the two angles of the logical dimensions (see [`plasma_plots.arrays.logical_dims()`](/plasma-plots/api/plasma_plots/arrays/#plasma_plots.arrays.logical_dims)), `("eta2", "eta3")` for Struphy. | | `names` | `str or sequence of str` | `('m', 'n')` | The name of the mode number of each dimension, one per dimension. Default: `("m", "n")`. | | `periods` | `float or sequence of float` | `1.0` | Each direction’s period in its coordinate: one number for all, or one per dimension. Default: the coordinate’s `period` attribute (see [`plasma_plots.arrays.angle_period()`](/plasma-plots/api/plasma_plots/arrays/#plasma_plots.arrays.angle_period)), else 1.0. | Returns * `xarray.DataArray` Complex amplitudes over the mode numbers `names` and every remaining dimension. See Also [`plasma_plots.spectral.mode_spectrum()`](/plasma-plots/api/plasma_plots/spectral/#plasma_plots.spectral.mode_spectrum) : The function behind this method. Examples ```python >>> out.analysis.mode_spectrum("em_fields/phi_log") >>> out.analysis.mode_spectrum(phi.isel(t=-1), dims="eta3", names="n") ``` # array.plasma.plot > Plots of one labeled array: time series, slices, animations, spectra, 3-D views. Plots of one labeled `xarray.DataArray`, as `array.plasma.plot.(...)`. Each method selects the dimensions it doesn’t draw by keyword (an integer is a position, `t=-1` the last; a float the nearest value), draws, and returns a `PlotResult` (or an animation or a PyVista plotter). Where the accessors come from The examples use output of a Struphy `Output`, which loads plasma-plots and its `.plasma` accessors. For other xarray data, run `import plasma_plots` first (see [Getting started](/plasma-plots/guides/getting-started/#loading-plasma-plots)). ## array.plasma.plot [Section titled “array.plasma.plot”](#arrayplasmaplot) Plots of one array, as `array.plasma.plot.(...)`. ### `timeseries` [Section titled “timeseries”](#timeseries) ### `timeseries`method[#](#plasma_plots.accessors.ArrayPlots.timeseries) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L95-L162 "src/plasma_plots/accessors.py:95-162") ``` def timeseries(*others, logy: bool = True, fit=None, fit_amplitude: bool = False, title: str | None = None, ax=None, reference=None, backend: Backend | None = None) ``` Plot this time series, and any others given, in one axes. Parameters | Name | Type | Default | Description | | --------------- | ------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `*others` | | `()` | Further arrays with the single dimension `t`; they may come from other runs and need not share this array’s time grid. | | `logy` | `bool` | `True` | Use a logarithmic value axis. Default: `True`. | | `fit` | `(float or None, float or None) or bool` | `None` | Time window `(t0, t1)` of an exponential fit per series (`None` for an open end), or `True` for the whole series. Rates are in `result.fit_results`. Default: no fit. | | `fit_amplitude` | `bool` | `False` | The series is quadratic in an amplitude (e.g. an energy); fit the amplitude’s rate. Default: `False`. | | `title` | `str` | `None` | The axes title. Default: the first series’ label. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `reference` | `callable, array, (t, values) pair or dict` | `None` | Exact or expected curves, drawn dashed: a function of `t`, an array, a `(t, values)` pair, or a mapping of labels to these. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes, the drawn lines, and in `fit_results` one [`FitResult`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.FitResult) (or `None`) per series. See Also [`plasma_plots.plotting.plot_timeseries()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_timeseries) : The function behind this method. [`ArrayData.timeseries()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.timeseries) : The validated series, without plotting them. [`ArrayAnalysis.growth_rate()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.growth_rate) : The same fit, without plotting it. Examples ```python >>> energy.plasma.plot.timeseries( ... logy=True, fit=(0.0, 2.0), fit_amplitude=True ... ) >>> energy.plasma.plot.timeseries(other_run_energy) ``` ### `lineout` [Section titled “lineout”](#lineout) ### `lineout`method[#](#plasma_plots.accessors.ArrayPlots.lineout) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L164-L226 "src/plasma_plots/accessors.py:164-226") ``` def lineout(x: str | None = None, ax=None, title: str | None = None, reference=None, x_of=None, xlabel: str | None = None, rationals: int | None = None, nfp: int | None = None, backend: Backend | None = None, **selection) ``` Plot a one-dimensional profile after selecting every other dimension. Parameters | Name | Type | Default | Description | | ------------- | -------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `None` | The dimension to keep. Default: the only one left after `selection`. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `title` | `str` | `None` | The axes title. Default: the array’s label. | | `reference` | `callable, array, (x, y) pair or dict` | `None` | Exact or expected profiles, drawn dashed: a function of the plotted `x` (or of `x` and `t`, taking the profile’s time), a 1-D `xarray.DataArray` (drawn over its own coordinate), an `(x, y)` pair, or a dict of labels to these. | | `x_of` | `callable` | `None` | Maps the coordinate to the plotted axis, e.g. `lambda eta1: L * eta1`. | | `xlabel` | `str` | `None` | The horizontal axis label. Default: the coordinate’s label. | | `rationals` | `int` | `None` | Mark where a rotational transform (or safety factor) profile takes its `rationals` lowest-order rational values `n/m`: a dotted line at each value, labeled, and a point at each crossing (see [`plasma_plots.analysis.rational_surfaces()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.rational_surfaces)). Default: none. | | `nfp` | `int` | `None` | With `rationals`: the numerators `n` are multiples of it. Default: the profile’s `nfp` attribute, else 1. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | The other dimensions: an integer is a position (`t=-1` the last), a float the nearest coordinate value. | Returns * `PlotResult` The figure, the axes and the drawn lines. See Also [`plasma_plots.plotting.plot_lineout()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_lineout) : The function behind this method. [`ArrayData.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.lineout) : The selected profile, without plotting it. Examples ```python >>> phi.plasma.plot.lineout(x="eta1", t=-1, eta2=0.5, eta3=0) >>> T.plasma.plot.lineout( ... x="eta1", t=-1, reference=exact, x_of=lambda eta1: L * eta1 ... ) >>> # GVEC's ι(ρ) and its rational surfaces >>> ev.iota.plasma.plot.lineout(rationals=4) ``` ### `line_animation` [Section titled “line\_animation”](#line_animation) ### `line_animation`method[#](#plasma_plots.accessors.ArrayPlots.line_animation) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L228-L301 "src/plasma_plots/accessors.py:228-301") ``` def line_animation(x: str | None = None, sweep: str = 't', reference=None, x_of=None, xlabel: str | None = None, ylim=None, step: int = 1, max_frames: int | None = None, interval: int = 100, title: str | None = None, alongside=None, alongside_logy: bool = False, backend: Backend | None = None, **selection) ``` Animate a one-dimensional profile over `sweep`. Optionally with the exact profile of each frame (`reference=lambda x, t: ...`). Keep a reference to the returned animation, or it stops. Parameters | Name | Type | Default | Description | | ---------------- | ------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | `None` | The dimension along the horizontal axis. Default: the one besides `sweep`. | | `sweep` | `str` | `'t'` | The dimension to animate over. Default: `"t"`. | | `reference` | `callable, (x, y) pair or dict` | `None` | The exact profile of each frame, drawn dashed in black: a function of the plotted `x` and of the sweep value (`lambda x, t: ...`; a function of `x` alone is fixed), an `(x, y)` pair, a 1-D `xarray.DataArray` (drawn over its own coordinate), or a dict of labels to these. | | `x_of` | `callable` | `None` | Maps the `x` coordinate to the plotted axis, e.g. `lambda eta1: L * eta1`. | | `xlabel` | `str` | `None` | The horizontal axis label. Default: the coordinate’s label, or `"x"` with `x_of`. | | `ylim` | `(float, float)` | `None` | The fixed value axis limits. Default: the range of the data and references, padded by 5 %. | | `step` | `int` | `1` | Use every `step`-th value of the sweep. Default: `1`. | | `max_frames` | `int` | `None` | Keep at most this many frames, evenly spaced over those `step` leaves (the first and last included), e.g. to keep a Plotly animation small. Default: all. | | `interval` | `int` | `100` | The delay between frames, in milliseconds. Default: `100`. | | `title` | `str` | `None` | The title, followed in each frame by the sweep value. Default: the array’s label. | | `alongside` | `sequence` | `None` | One panel below the profile per item, in sync with it: an array over `sweep` and one other dimension (another profile, animated, e.g. the density next to the velocity), or an array over `sweep` alone, or a list of those (time series such as energies, drawn whole with a marker at each frame’s value of the sweep, nearest where the times differ). Default: none. | | `alongside_logy` | `bool` | `False` | Logarithmic value axes for the time-series panels. Default: `False`. | | `backend` | `('matplotlib', 'plotly')` | `"matplotlib"` | Draw with Matplotlib, or as an interactive Plotly figure with a slider (in `result.fig`; needs plotly, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | Every dimension but `x` and `sweep`: an integer is a position (`eta2=0`), a float the nearest coordinate value. | Returns * `matplotlib.animation.FuncAnimation or PlotResult` The animation, one frame per step along `sweep`; with `backend="plotly"` a result whose Plotly figure has a slider and Play/Pause buttons. See Also [`plasma_plots.plotting.animate_lines()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.animate_lines) : The function behind this method. [`ArrayPlots.lineout()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.lineout) : One frame, as a static plot. Examples ```python >>> T.plasma.plot.line_animation(reference={"exact": exact}, step=2) >>> u.plasma.plot.line_animation( ... x="eta1", ... alongside=[n, [en_U, en_B]], ... alongside_logy=True, ... eta2=0, ... eta3=0, ... ) ``` ### `against_theory` [Section titled “against\_theory”](#against_theory) ### `against_theory`method[#](#plasma_plots.accessors.ArrayPlots.against_theory) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L303-L357 "src/plasma_plots/accessors.py:303-357") ``` def against_theory(theory=None, *, show_error: bool = True, xlabel=None, ylabel=None, title=None, logx: bool = False, logy: bool = False, backend: Backend | None = None) ``` Plot these measured values as points against a `theory` function. The array is 1-D, over a parameter (e.g. the wavenumber); the relative error is shown too. Parameters | Name | Type | Default | Description | | ------------ | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `theory` | `callable, (x, y) pair or dict` | `None` | A function of the parameter, an `(x, y)` pair, or a dict of labels to these, drawn as lines over the measured range. Complex values (e.g. from [`plasma_plots.theory`](/plasma-plots/api/plasma_plots/theory/)) are compared by their real part; for growth or damping rates pass `lambda k: f(k).imag`. | | `show_error` | `bool` | `True` | Add a second panel with `(measured - theory) / theory` against the first theory, for every measured series. A theory given as points is interpolated linearly between them (NaN outside them). Default: `True`. | | `xlabel` | `str` | `None` | The horizontal axis label. Default: the coordinate label of the first measured array. | | `ylabel` | `str` | `None` | The value axis label. Default: the value label of the first measured array. | | `title` | `str` | `None` | The title. Default: `"Measured against theory"`. | | `logx` | `bool` | `False` | Use a logarithmic parameter axis. Default: `False`. | | `logy` | `bool` | `False` | Use a logarithmic value axis. Default: `False`. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes (with `show_error`, the upper one) and the drawn artists. See Also [`plasma_plots.plotting.plot_measured_vs_theory()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_measured_vs_theory) : The function behind this method. [`ArrayAnalysis.trace_branch()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayAnalysis.trace_branch) : Measured frequencies of a dispersion branch, to plot here. Examples ```python >>> traced = spectrum.plasma.analysis.trace_branch( ... bohm_gross, k_range=(1.5, 5.5) ... ) >>> traced.omega.plasma.plot.against_theory(bohm_gross) ``` ### `convergence` [Section titled “convergence”](#convergence) ### `convergence`method[#](#plasma_plots.accessors.ArrayPlots.convergence) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L359-L431 "src/plasma_plots/accessors.py:359-431") ``` def convergence(*others, order: float | None = None, xlabel: str | None = None, title: str = 'Convergence', ax=None, backend: Backend | None = None) ``` Plot these errors against their resolution (or step size) on log-log axes, with the order. The array is 1-D over the resolution, e.g. an error norm per number of cells; each series gets its fitted convergence order (or, with `order`, a reference slope). Parameters | Name | Type | Default | Description | | --------- | ---------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `*others` | | `()` | Further 1-D error arrays, e.g. of other methods or norms, drawn in the same axes. | | `order` | `float` | `None` | With `None` (default), fits and draws the observed order via [`plasma_plots.analysis.convergence_order()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.convergence_order). Pass an explicit `order` (e.g. `2` for second-order) to draw a reference slope through the first point instead of fitting one. | | `xlabel` | `str` | `None` | The horizontal axis label. Default: the coordinate’s label. | | `title` | `str` | `'Convergence'` | The axes title. Default: `"Convergence"`. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | Returns * `PlotResult` The figure, the axes and, per series, the error line and its fitted or reference line. Raises * `ValueError` If an array is not one-dimensional. See Also [`plasma_plots.plotting.plot_convergence()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_convergence) : The function behind this method. [`plasma_plots.analysis.convergence_order()`](/plasma-plots/api/plasma_plots/analysis/#plasma_plots.analysis.convergence_order) : The fitted order, without plotting it. Examples ```python >>> errors = xr.DataArray( ... l2_errors, dims="n", coords={"n": [16, 32, 64, 128]}, name="L2 error" ... ) >>> errors.plasma.plot.convergence(max_errors, backend="plotly") ``` ### `vector` [Section titled “vector”](#vector) ### `vector`method[#](#plasma_plots.accessors.ArrayPlots.vector) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L433-L484 "src/plasma_plots/accessors.py:433-484") ``` def vector(x: str, y: str, components: tuple[int, int] = (0, 1), stride: int = 1, coordinates: Coordinates = 'logical', ax=None, backend: Backend | None = None, **selection) ``` Plot two vector components after selecting time and remaining dimensions. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `x` | `str` | required | The dimension along the horizontal axis. | | `y` | `str` | required | The dimension along the vertical axis. | | `components` | `(int, int)` | `(0, 1)` | The positions along `component_dim` of the two components drawn. Default: `(0, 1)`. | | `stride` | `int` | `1` | Draw every `stride`-th arrow along `x` and `y`. Default: `1`. | | `coordinates` | `('logical', 'physical')` | `"logical"` | Place the arrows at the logical coordinates, or at the attached physical `X`, `Y`, `Z` (then `x` and `y` must be two of `eta1`, `eta2`, `eta3`, and the axes have equal scales). Default: `"logical"`. | | `ax` | `matplotlib.axes.Axes` | `None` | The axes to draw into. Default: a new figure. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | Every dimension but `x`, `y` and the component dimension, e.g. `t=-1, eta3=0`: an integer is a position, a float the nearest coordinate value. | Returns * `PlotResult` The figure, the axes and the quiver. See Also [`plasma_plots.plotting.plot_vector()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_vector) : The function behind this method. [`ArrayData.vector()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.vector) : The selected, strided components, without plotting them. Examples ```python >>> E.plasma.plot.vector(x="eta1", y="eta2", t=-1, eta3=0) ``` ### `volume_slices` [Section titled “volume\_slices”](#volume_slices) ### `volume_slices`method[#](#plasma_plots.accessors.ArrayPlots.volume_slices) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L486-L527 "src/plasma_plots/accessors.py:486-527") ``` def volume_slices(indices: dict[str, int] | None = None, cmap=None, backend: Backend | None = None, **selection) ``` Render three orthogonal slices of a selected scalar volume. Parameters | Name | Type | Default | Description | | ------------- | ----------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `indices` | `dict of str to int` | `None` | The index at which each dimension is held fixed, e.g. `{"eta3": 0}`. Default: the middle index of every dimension. | | `cmap` | `str or matplotlib.colors.Colormap` | `None` | The colormap. Default: Matplotlib’s default. | | `backend` | `('matplotlib', 'plotly', 'tikz')` | `"matplotlib"` | Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in `result.fig`; needs plotly or maxplotlib, see [`plasma_plots.plotly_backend`](/plasma-plots/api/plasma_plots/plotly_backend/) and [`plasma_plots.tikz_backend`](/plasma-plots/api/plasma_plots/tikz_backend/)). Default: the one set with [`plasma_plots.set_backend()`](/plasma-plots/api/plasma_plots/plotly_backend/#plasma_plots.plotly_backend.set_backend), `"matplotlib"` unless changed. | | `**selection` | | `{}` | Every dimension but the three of the volume, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `PlotResult` The figure, the three axes and the drawn meshes. See Also [`plasma_plots.plotting.plot_volume_slices()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.plot_volume_slices) : The function behind this method. [`ArrayData.volume_slices()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.volume_slices) : The three planes, without plotting them. Examples ```python >>> density.plasma.plot.volume_slices(t=-1) ``` ### `volume` [Section titled “volume”](#volume) ### `volume`method[#](#plasma_plots.accessors.ArrayPlots.volume) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L529-L559 "src/plasma_plots/accessors.py:529-559") ``` def volume(name: str | None = None, cmap='viridis', opacity='linear', **selection) ``` Create a PyVista volume plotter for a selected scalar field. Parameters | Name | Type | Default | Description | | ------------- | -------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ | | `name` | `str` | `None` | The name of the scalars in the PyVista grid. Default: the array’s label, else `"value"`. | | `cmap` | `str` | `'viridis'` | The colormap. Default: `"viridis"`. | | `opacity` | `str or sequence of float` | `'linear'` | PyVista’s opacity transfer function. Default: `"linear"`. | | `**selection` | | `{}` | Every dimension but `eta1`, `eta2`, `eta3`, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `pyvista.Plotter` The plotter, not yet shown; call `plotter.show()`. See Also [`plasma_plots.plotting.pyvista_volume()`](/plasma-plots/api/plasma_plots/plotting/#plasma_plots.plotting.pyvista_volume) : The function behind this method. [`ArrayPlots.isosurface()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.isosurface) : Contour surfaces instead of a volume rendering. Examples ```python >>> density.plasma.plot.volume(cmap="viridis", opacity="linear", t=-1).show() ``` ### `isosurface` [Section titled “isosurface”](#isosurface) ### `isosurface`method[#](#plasma_plots.accessors.ArrayPlots.isosurface) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L568-L619 "src/plasma_plots/accessors.py:568-619") ``` def isosurface(values=5, cmap='viridis', opacity: float = 1.0, clim=None, show_domain: bool = True, title: str | None = None, symmetric: bool = False, robust: bool = False, plotter=None, **selection) ``` Draw PyVista contour surfaces of this scalar field in physical space. For a 2-D field, contour lines over the colored plane instead. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `values` | `int or list of float` | `5` | The number of evenly spaced levels strictly between the color limits, or explicit levels. Default: 5. | | `cmap` | `str or matplotlib colormap` | `'viridis'` | The colormap. Default: `"viridis"`. | | `opacity` | `float` | `1.0` | Opacity of the surfaces (of the plane for a 2-D field). Default: 1. | | `clim` | `(float, float)` | `None` | Color limits; default from the field’s values, see `symmetric` and `robust`. | | `show_domain` | `bool` | `True` | Draw the domain’s outer surface translucently for context (3-D fields only). Default: `True`. | | `title` | `str` | `None` | Text in the scene’s corner. Default: the field’s label; `""` for none. | | `symmetric` | `bool` | `False` | Color limits symmetric about zero. Default: `False`. | | `robust` | `bool` | `False` | Color limits from percentiles instead of the extremes, so outliers don’t wash out the colors. Default: `False`. | | `plotter` | `pyvista.Plotter` | `None` | Draw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter. | | `**selection` | | `{}` | Every dimension but `eta1`, `eta2`, `eta3`, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `pyvista.Plotter` The plotter with the surfaces, not yet shown. See Also [`plasma_plots.pyvista_plots.pyvista_isosurface()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.pyvista_isosurface) : The function behind this method. [`ArrayPlots.slices_3d()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.slices_3d) : Surfaces of constant logical coordinate instead. Examples ```python >>> phi.plasma.plot.isosurface(values=[-0.5, 0.5], cmap="RdBu_r", t=0).show() ``` ### `slices_3d` [Section titled “slices\_3d”](#slices_3d) ### `slices_3d`method[#](#plasma_plots.accessors.ArrayPlots.slices_3d) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L621-L673 "src/plasma_plots/accessors.py:621-673") ``` def slices_3d(cuts: dict | None = None, cmap='viridis', clim=None, show_domain: bool = True, title: str | None = None, symmetric: bool = False, robust: bool = False, plotter=None, **selection) ``` Draw PyVista surfaces of constant logical coordinate in physical space. E.g. `cuts={"eta3": [0, 0.25]}` for poloidal cross-sections, `cuts={"eta1": 0.8}` for one flux surface. A 2-D field is shown as its whole plane by default. Parameters | Name | Type | Default | Description | | ------------- | ---------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `cuts` | `dict` | `None` | `{dim: position or list of positions}` along `eta1`, `eta2`, `eta3`: a float is the nearest logical coordinate, an integer a grid index (`-1` the last). Default: the middle of every dimension, or the whole plane of a 2-D field. | | `cmap` | `str or matplotlib colormap` | `'viridis'` | The colormap. Default: `"viridis"`. | | `clim` | `(float, float)` | `None` | Color limits, shared by every cut; default from the whole field’s values, see `symmetric` and `robust`. | | `show_domain` | `bool` | `True` | Draw the domain’s outer surface translucently for context. Not drawn when the whole plane of a 2-D field is shown. Default: `True`. | | `title` | `str` | `None` | Text in the scene’s corner. Default: the field’s label; `""` for none. | | `symmetric` | `bool` | `False` | Color limits symmetric about zero. Default: `False`. | | `robust` | `bool` | `False` | Color limits from percentiles instead of the extremes, so outliers don’t wash out the colors. Default: `False`. | | `plotter` | `pyvista.Plotter` | `None` | Draw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter. | | `**selection` | | `{}` | Every dimension but `eta1`, `eta2`, `eta3`, e.g. `t=0`: an integer is a position, a float the nearest coordinate value. | Returns * `pyvista.Plotter` The plotter with the cuts, not yet shown. See Also [`plasma_plots.pyvista_plots.pyvista_slices()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.pyvista_slices) : The function behind this method. [`ArrayData.slices_3d()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayData.slices_3d) : The cuts, without drawing them. Examples ```python >>> phi.plasma.plot.slices_3d( ... cuts={"eta3": [0, 0.25, 0.5, 0.75]}, cmap="RdBu_r", t=0 ... ).show() ``` ### `glyphs` [Section titled “glyphs”](#glyphs) ### `glyphs`method[#](#plasma_plots.accessors.ArrayPlots.glyphs) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L675-L722 "src/plasma_plots/accessors.py:675-722") ``` def glyphs(components: Literal['cartesian', 'contravariant'] = 'cartesian', stride: int = 2, scale: float | None = None, cmap='viridis', show_domain: bool = True, title: str | None = None, plotter=None, **selection) ``` Draw PyVista arrows of this `(component, eta1, eta2, eta3)` vector field. The arrows are colored by magnitude. Parameters | Name | Type | Default | Description | | ------------- | -------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `components` | `('cartesian', 'contravariant')` | `"cartesian"` | How to read the components: Cartesian x/y/z, or contravariant logical components, pushed forward. Default: `"cartesian"`. | | `stride` | `int` | `2` | Draw an arrow at every `stride`-th point in every direction. Default: 2. | | `scale` | `float` | `None` | Arrow length of the largest vector, in physical units. Default: a tenth of the domain size. | | `cmap` | `str or matplotlib colormap` | `'viridis'` | The colormap of the magnitude. Default: `"viridis"`. | | `show_domain` | `bool` | `True` | Draw the domain’s outer surface translucently for context. Default: `True`. | | `title` | `str` | `None` | Text in the scene’s corner. Default: the field’s label; `""` for none. | | `plotter` | `pyvista.Plotter` | `None` | Draw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter. | | `**selection` | | `{}` | Every dimension but `component`, `eta1`, `eta2`, `eta3`, e.g. `t=-1`: an integer is a position, a float the nearest coordinate value. | Returns * `pyvista.Plotter` The plotter with the arrows, not yet shown. See Also [`plasma_plots.pyvista_plots.pyvista_glyphs()`](/plasma-plots/api/plasma_plots/pyvista_plots/#plasma_plots.pyvista_plots.pyvista_glyphs) : The function behind this method. [`ArrayPlots.streamlines()`](/plasma-plots/api/plasma_plots/accessors/#plasma_plots.accessors.ArrayPlots.streamlines) : Field lines of the same field. Examples ```python >>> B.plasma.plot.glyphs(stride=3, t=-1).show() ``` ### `streamlines` [Section titled “streamlines”](#streamlines) ### `streamlines`method[#](#plasma_plots.accessors.ArrayPlots.streamlines) [View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/accessors.py#L724-L777 "src/plasma_plots/accessors.py:724-777") ``` def streamlines(components: Literal['cartesian', 'contravariant'] = 'cartesian', n_points: int = 100, source_radius: float | None = None, source_center=None, max_length: float | None = None, tube_radius: float | None = None, cmap='viridis', show_domain: bool = True, title: str | None = None, plotter=None, **selection) ``` Draw PyVista field lines of this vector field, e.g. magnetic field lines. Parameters | Name | Type | Default | Description | | --------------- | -------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `components` | `('cartesian', 'contravariant')` | `"cartesian"` | How to read the components: Cartesian x/y/z, or contravariant logical components, pushed forward by \[`push_forward()`]\[push\_forward]. Default: `"cartesian"`. | | `n_points` | `int` | `100` | The number of seed points (at most the number of grid points when seeding on the grid). Default: 100. | | `source_radius` | `float` | `None` | Seed in a sphere of this radius instead of at grid points. Default (when `source_center` is given): a quarter of the domain size. | | `source_center` | `(float, float, float)` | `None` | Seed in a sphere around this physical point instead of at grid points. Default (when `source_radius` is given): the bounding-box center. | | `max_length` | `float` | `None` | Maximum length of each line. Default: four times the domain size. | | `tube_radius` | `float` | `None` | Draw the lines as tubes of this radius. Default: plain lines. | | `cmap` | `str or matplotlib colormap` | `'viridis'` | The colormap of the magnitude. Default: `"viridis"`. | | `show_domain` | `bool` | `True` | Draw the domain’s outer surface translucently for context. Default: `True`. | | `title` | `str` | `None` | Text in the scene’s corner. Default: `"