Skip to content

dataset.plasma

Plots, diagnostics and data of an xarray.Dataset with per-marker variables, such as an orbits product.

Plots of one dataset, as dataset.plasma.plot.<kind>(...).

power_spectrummethod#

def power_spectrum(backend: Backend | None = None, **options)

Plot the power of a time_fft Dataset.

Parameters

NameTypeDefaultDescription
**options{}The keyword options of 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists; data holds the averaged "power" and the found "peaks".

Examples

>>> phi.plasma.analysis.time_fft(detrend=True).plasma.plot.power_spectrum(
... peaks=2
... )

cross_spectrummethod#

def cross_spectrum(omega_max: float | None = None, backend: Backend | None = None)

Plot the magnitude, coherence and phase of a cross_spectrum Dataset.

Parameters

NameTypeDefaultDescription
omega_maxfloatNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists; data holds "peak_omega" and "peak_phase_deg".

Examples

>>> u.plasma.analysis.cross_spectrum(
... b, dims="eta3"
... ).plasma.plot.cross_spectrum(omega_max=1.5)

trajectoriesmethod#

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

NameTypeDefaultDescription
max_markersint200Draw only the first max_markers markers. Default: 200.
show_pathsboolNoneDraw each marker’s path, not only its last position. Default: True for up to 200 markers.
axmpl_toolkits.mplot3d.Axes3DNoneA 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the 3-D axes and the drawn artists.

Examples

>>> orbits.plasma.plot.trajectories(max_markers=200)

scattermethod#

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(): 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

NameTypeDefaultDescription
xstrrequiredThe data variable along the horizontal axis, e.g. the position "x".
ystrrequiredThe data variable along the vertical axis, e.g. the position "y".
colorstrNoneA data variable to color the markers by, e.g. a Lagrangian tracer, weight or density, with a color bar. Default: one color.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
cmapstr or matplotlib.colors.ColormapNoneThe colormap for color. Default: "viridis".
sint8The marker size, in points². Default: 8.
color_atint or floatNoneTake 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.
backgroundxarray.DataArrayNoneA 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_optionsdictNonePassed to [plot_slice()][plot_slice] for the background (e.g. cmap, levels, fill=False).
equal_aspectboolNoneDraw 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The remaining dimensions, such as t, exactly like 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.

Examples

>>> 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_classificationmethod#

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

NameTypeDefaultDescription
xstr'v_par'The quantity along the horizontal axis. Default: "v_par".
ystrNoneThe quantity along the vertical axis. Default: the magnetic moment mu (Particles5D), or v_perp if there is no mu (Particles5Dvperp).
v_parstr'v_par'The parallel velocity the classification uses. Default: "v_par".
tint or float0The 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.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
sint8The 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists; data["counts"] holds the number of markers per class.

Examples

>>> orbits.plasma.plot.orbit_classification()
>>> orbits.plasma.plot.orbit_classification(x="p_phi")

animationmethod#

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

NameTypeDefaultDescription
xstrrequiredThe 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).
ystrrequiredThe data variable along the vertical axis, e.g. the position "y".
colorstrNoneA 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()), with a legend. Default: one color.
color_atint or floatNoneFix 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.
backgroundxarray.DataArrayNoneA 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_optionsdictNoneRendering options for the background, as for [plot_slice()][plot_slice] (cmap, symmetric, levels, …).
stepint1Use every step-th time. Default: 1.
max_framesintNoneKeep 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.
intervalint100The delay between frames, in milliseconds. Default: 100.
sint8The marker size, in points². Default: 8.
cmapstr or matplotlib.colors.ColormapNoneThe colormap for color. Default: "viridis".
trailintNoneDraw each marker’s last trail samples as a faint line behind it. Default: none.
pathsboolFalseDraw 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). Default: the one set with plasma_plots.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.

Examples

>>> 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,
... )

pathsmethod#

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

NameTypeDefaultDescription
xstr'x'The quantity along the horizontal axis. Default: "x".
ystr'y'The quantity along the vertical axis. Default: "y".
markersint or sequence of int6A number of markers (spread evenly over the saved markers) or a list of marker indices. Default: 6.
nearsequence of (float, float)NonePicks instead the marker starting closest to each of a list of (x, y) points, e.g. a row across the domain.
backgroundxarray.DataArrayNoneA 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_optionsdictNonePassed to [plot_slice()][plot_slice] for the background, e.g. dict(levels=12, fill=False) for the contour lines of a stream function.
tint or float0The time of the background: an integer position or a float value. Default: 0, the first.
axmatplotlib.axes.AxesNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists; data["markers"] holds the chosen markers.

Examples

>>> orbits.plasma.plot.paths(markers=4, background=psi.isel(t=0))

poloidalmethod#

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

NameTypeDefaultDescription
color_bystr or None'classification'"classification" colors by orbit class (needs v_par, see 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_markersint200Draw only the first max_markers markers. Default: 200.
boundaryxarray.DataArrayNoneAny field with physical coordinates, whose outer (last eta1) surface is drawn at its first eta3 as the domain boundary.
axmatplotlib.axes.AxesNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn lines.

Examples

>>> orbits.plasma.plot.poloidal(boundary=field)

orbit_gridmethod#

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

NameTypeDefaultDescription
markersint or sequence of int8A number of markers (spread over the classes when v_par is saved) or a list of marker indices. Default: 8.
ncolsint4The number of panels per row. Default: 4.
boundaryxarray.DataArrayNoneA 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn lines; data["markers"] holds the plotted markers.

Examples

>>> orbits.plasma.plot.orbit_grid(markers=8, ncols=4, boundary=field)
>>> orbits.plasma.plot.orbit_grid(markers=[3, 17, 42])

quantitiesmethod#

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

NameTypeDefaultDescription
quantitiessequence of str('v_par', 'mu')The quantities, one panel each. Default: ("v_par", "mu").
markersint or sequence of int6A 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_ofbool 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, one axes per quantity and the drawn lines.

Examples

>>> orbits.plasma.plot.quantities(markers=4)

orbits_3dmethod#

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

NameTypeDefaultDescription
color_bystr't'"t", "classification" (passing, trapped, lost, with a legend) or the name of any (t, marker) variable, e.g. "v_par". Default: "t".
max_markersint200At most this many markers are drawn. Default: 200.
tube_radiusfloatNoneDraw the orbits as tubes of this radius. Default: plain lines.
cmapstr or matplotlib colormapNoneThe colormap (not used for "classification"). Default: "viridis".
domainxarray.DataArrayNoneA field with physical coordinates whose outer surface is drawn translucently; other than eta1, eta2, eta3, its dimensions are taken at their first position.
titlestrNoneText in the scene’s corner. Default: "Marker orbits"; "" for none.
plotterpyvista.PlotterNoneDraw into this scene instead of a new one, to combine several views.

Returns

pyvista.Plotter
The plotter with the orbits, not yet shown.

Examples

>>> orbits.plasma.plot.orbits_3d(
... color_by="classification", domain=phi.isel(t=0)
... ).show()

poincaremethod#

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

NameTypeDefaultDescription
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() (surface, island, chaotic) with a legend; None for one color. Default: "line".
sfloat3.0The marker size, in points². Default: 3.
cmapstr or matplotlib colormapNoneThe colormap of "iota" and "connection_length". Default: "viridis".
islandsboolFalseLabel the island chains with their n/m and widths. Default: False.
boundaryxarray.DataArrayNoneA field with physical coordinates whose outermost surface is drawn at the section (physical coordinates only).
max_linesintNoneDraw only the first max_lines lines. Default: all.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**classification{}Options of 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.

Examples

>>> lines.plasma.plot.poincare(color_by="iota")
>>> lines.plasma.plot.poincare(color_by="classification", islands=True)

field_linesmethod#

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

NameTypeDefaultDescription
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_linesint200Draw only the first max_lines lines. Default: 200.
cmapstr or matplotlib colormapNoneThe colormap. Default: "viridis".
boundaryxarray.DataArrayNoneA field with physical coordinates whose outermost surface is drawn in the RZ plane.
axmatplotlib.axes.AxesNoneThe axes to draw into (a 3-D axes for plane="3d"). Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the lines.

Examples

>>> lines.plasma.plot.field_lines(plane="RZ", color_by="iota")
>>> lines.plasma.plot.field_lines(plane="3d", max_lines=20)

footprintmethod#

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

NameTypeDefaultDescription
logboolTrueColor by the decimal logarithm of the connection length. Default: True.
sfloat14.0The marker size, in points². Default: 14.
cmapstr or matplotlib colormapNoneThe colormap. Default: "viridis".
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the scatter; data["footprint"] holds the exit points.

Examples

>>> edge.plasma.plot.footprint()

connection_lengthmethod#

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

NameTypeDefaultDescription
logboolTrueShow the decimal logarithm of the connection length. Default: True.
cmapstr or matplotlib colormapNoneThe colormap. Default: "viridis".
sfloat14.0The marker size of a scatter, in points². Default: 14.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the mesh or scatter; data["connection_length"].

Examples

>>> edge.plasma.plot.connection_length()

weight_histogrammethod#

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

NameTypeDefaultDescription
weightstr'weight'The weight variable. Default: "weight".
t(int, float or sequence)-1The time(s): integer positions (-1 the last) or float nearest values, one or several. Default: -1.
binsint50The number of bins, shared by all times. Default: 50.
logboolTrueA logarithmic count axis. Default: True.
densityboolTrueNormalize each histogram to unit area. Default: True.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and one outline per time; data["statistics"].

Examples

>>> orbits.plasma.plot.weight_histogram(t=[0, 0.5, -1])

marker_densitymethod#

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

NameTypeDefaultDescription
xstr'eta1'The position variable to bin over, e.g. "eta1" or "x". Default: "eta1".
weightstr'weight'The weight variable, for the weighted density; None leaves it out. Default: "weight" (skipped when the Dataset has no such variable).
againstxarray.DataArrayNoneA reference profile over the same coordinate (every other dimension selected, or with t matching markers), drawn dashed. Default: none.
binsint32The number of bins. Default: 32.
normalizeboolTrueDivide 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.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.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.

Examples

>>> orbits.plasma.plot.marker_density(
... x="eta1", against=n.isel(eta2=0, eta3=0), t=-1
... )

lost_fractionmethod#

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

NameTypeDefaultDescription
weightstrNoneWeigh each marker by its initial value of this variable, i.e. count particles rather than markers. Default: count markers.
percentboolTrueShow percentages. Default: True.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the line; data["lost_fraction"].

Examples

>>> orbits.plasma.plot.lost_fraction(weight="weight")

loss_mapmethod#

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

NameTypeDefaultDescription
xstr'v_par'The quantity along the horizontal axis: a variable, or "energy", "pitch" or "speed" (see loss_map()). Default: "v_par".
ystrNoneThe vertical one. Default: "mu", or "v_perp" without mu.
tint or float0The time of the plotted positions: an integer position (default 0) or a float nearest value.
absBcallableNone|B|(x, y, z), for "energy" and "pitch".
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
sint10The marker size, in points². Default: 10.
cmapstr or matplotlib.colors.ColormapNoneThe colormap of the loss time. Default: "plasma".
titlestrNoneThe 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 and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the scatters; data["losses"].

Examples

>>> orbits.plasma.plot.loss_map(x="energy", y="pitch", absB=absB)

Quantitative diagnostics of one dataset, as dataset.plasma.analysis.<quantity>(...).

classify_orbitsmethod#

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() for the criteria.

Parameters

NameTypeDefaultDescription
v_parstr'v_par'The name of the parallel-velocity variable. Default: "v_par".

Returns

xarray.DataArray
The class of each marker, over marker.

Examples

>>> orbits.plasma.analysis.classify_orbits()

orbit_invariantsmethod#

def orbit_invariants(absB=None) -> xr.Dataset

Return the speed, guiding-centre energy and pitch of the saved orbits.

Parameters

NameTypeDefaultDescription
absBcallableNone|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.

Examples

>>> orbits.plasma.analysis.orbit_invariants(absB=absB_xyz)

bounce_periodmethod#

def bounce_period(v_par: str = 'v_par') -> xr.DataArray

Return the bounce period of each trapped marker.

Parameters

NameTypeDefaultDescription
v_parstr'v_par'The name of the parallel-velocity variable. Default: "v_par".

Returns

xarray.DataArray
The bounce period over marker.

Examples

>>> orbits.plasma.analysis.bounce_period()

surface_averagemethod#

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

NameTypeDefaultDescription
namestrrequiredThe variable, e.g. "mod_B".
jacobianstr 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.
domainstruphy domainNoneThe mapping, for the exact √g of a Struphy run.
quadraturedictNoneExplicit weights for the angles, as for [volume_integral()][volume_integral].

Returns

xarray.DataArray
⟨name⟩ over the radius and every non-spatial dimension.

Examples

>>> ev.plasma.analysis.surface_average("mod_B")

poincare_sectionmethod#

def poincare_section(angle: float | None = None) -> xr.Dataset

Return the punctures of a poloidal plane by these traced field lines.

Parameters

NameTypeDefaultDescription
anglefloatNoneThe toroidal logical coordinate of the plane. Default: the traced section.

Returns

xarray.Dataset
The punctures over (puncture, line).

Examples

>>> lines.plasma.analysis.poincare_section(angle=np.pi / 5)

rotational_transformmethod#

def rotational_transform() -> xr.DataArray

Return the rotational transform of each traced field line.

Returns

xarray.DataArray
iota over line.

Examples

>>> lines.plasma.analysis.rotational_transform()

classify_field_linesmethod#

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

NameTypeDefaultDescription
max_denominatorint12The largest m of the rationals considered. Default: 12.
tolerancefloatNoneHow 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.
thresholdfloat0.1The 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_spreadfloatNoneThe 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.

Examples

>>> lines.plasma.analysis.classify_field_lines()

islandsmethod#

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

NameTypeDefaultDescription
max_denominatorint12The largest m of the rationals considered. Default: 12.
tolerancefloatNoneHow close ι must be to n/m; see classify_field_lines().
thresholdfloat0.1The chaos criterion of classify_field_lines(). Default: 0.1.
min_spreadfloatNoneThe surface criterion of classify_field_lines(). Default: half the radial grid spacing.

Returns

xarray.Dataset
Over chain: n, m, width, center, …

Examples

>>> lines.plasma.analysis.islands().to_dataframe()

footprintmethod#

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.

Examples

>>> edge.plasma.analysis.footprint()

seed_gridmethod#

def seed_grid(name: str = 'connection_length') -> xr.DataArray

Return a per-line quantity of these field lines over their grid of seeds.

Parameters

NameTypeDefaultDescription
namestr'connection_length'The per-line variable. Default: "connection_length".

Returns

xarray.DataArray
name over the two varying seed coordinates.

Examples

>>> edge.plasma.analysis.seed_grid("connection_length").plasma.plot.slice()

weight_statisticsmethod#

def weight_statistics(weight: str = 'weight') -> xr.Dataset

Return the statistics of the marker weights over time, with the noise estimate.

Parameters

NameTypeDefaultDescription
weightstr'weight'The weight variable. Default: "weight", Struphy’s.

Returns

xarray.Dataset
mean, std, total, noise, effective_markers, … over t.

Examples

>>> orbits.plasma.analysis.weight_statistics().noise.plasma.plot.timeseries()

marker_densitymethod#

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

NameTypeDefaultDescription
dimsstr or sequence of str('eta1')The position variables to bin over, e.g. ("eta1",) or ("x", "y"). Default: ("eta1",).
binsint or sequence of int32The number of bins, for all or for each. Default: 32.
weightstrNoneWeigh each marker by this variable, e.g. "weight". Default: count the markers.
rangesdictNone{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.

Examples

>>> orbits.plasma.analysis.marker_density(dims="eta1", weight="weight")

lost_fractionmethod#

def lost_fraction(weight: str | None = None) -> xr.DataArray

Return the fraction of markers lost from the domain, over time.

Parameters

NameTypeDefaultDescription
weightstrNoneWeigh each marker by its initial value of this variable, e.g. "weight". Default: count the markers.

Returns

xarray.DataArray
The fraction over t.

Examples

>>> orbits.plasma.analysis.lost_fraction(weight="weight")

loss_mapmethod#

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

NameTypeDefaultDescription
xstr'v_par'The first quantity. Default: "v_par".
ystrNoneThe second quantity. Default: "mu", or "v_perp" without mu.
tint or float0The time of the plotted values: an integer position (default 0, the initial one) or a float nearest value.
absBcallableNone|B|(x, y, z), for "energy" and "pitch" (see orbit_invariants()).

Returns

xarray.Dataset
x, y, lost and loss_time over marker.

Examples

>>> orbits.plasma.analysis.loss_map(x="energy", y="pitch", absB=absB)

The data behind each plot in :class:DatasetPlots, without rendering it.

trajectoriesmethod#

def trajectories(max_markers: int = 200) -> xr.Dataset

Return the marker-position subset DatasetPlots.trajectories() would plot.

Parameters

NameTypeDefaultDescription
max_markersint200Draw 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.

Examples

>>> markers.plasma.data.trajectories(max_markers=50)

scattermethod#

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() would plot.

.to_dataframe() hands them straight to e.g. Plotly Express.

Parameters

NameTypeDefaultDescription
xstrrequiredThe variables for the horizontal and vertical axes.
ystrrequiredThe variables for the horizontal and vertical axes.
colorstrNoneThe variable to color by. Default: none.
color_atint or floatNoneTake 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.

Examples

>>> 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_classificationmethod#

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() would plot.

Parameters

NameTypeDefaultDescription
xstr'v_par'The quantity along the horizontal axis. Default: "v_par".
ystrNoneThe quantity along the vertical axis. Default: the magnetic moment mu (Particles5D), or v_perp if there is no mu (Particles5Dvperp).
v_parstr'v_par'The parallel velocity the classification uses. Default: "v_par".
tint or float0The 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.

Examples

>>> orbits.plasma.data.orbit_classification(x="p_phi")

poincaremethod#

def poincare(angle: float | None = None) -> xr.Dataset

Return the punctures DatasetPlots.poincare() would plot.

Parameters

NameTypeDefaultDescription
anglefloatNoneThe toroidal logical coordinate of the plane. Default: the traced section.

Returns

xarray.Dataset
The punctures over (puncture, line).

Examples

>>> lines.plasma.data.poincare().to_dataframe()

footprintmethod#

def footprint() -> xr.Dataset

Return the exit points DatasetPlots.footprint() would plot.

Returns

xarray.Dataset
The exit points over line, with the connection lengths.

Examples

>>> edge.plasma.data.footprint()

loss_mapmethod#

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() would plot.

Parameters

NameTypeDefaultDescription
xstr'v_par'The first quantity. Default: "v_par".
ystrNoneThe second quantity. Default: "mu", or "v_perp" without mu.
tint or float0The time of the plotted values: an integer position (default 0, the initial one) or a float nearest value.
absBcallableNone|B|(x, y, z), for "energy" and "pitch" (see [orbit_invariants()][orbit_invariants]).

Returns

xarray.Dataset
x, y, lost and loss_time over marker.

Examples

>>> orbits.plasma.data.loss_map(x="energy", y="pitch", absB=absB)