array.plasma.analysis
Numerical diagnostics of one labeled xarray.DataArray, as array.plasma.analysis.<method>(...). They return labeled arrays and Datasets, so their results can be plotted with .plasma.plot in turn.
array.plasma.analysis
Section titled “array.plasma.analysis”Quantitative diagnostics of one array, as array.plasma.analysis.<quantity>(...).
growth_rate
Section titled “growth_rate”growth_ratemethod#
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
Returns
FitResult or None.rate,.intercept,.timeand.fitted;Nonewith fewer than two valid samples.
Examples
>>> energy.plasma.analysis.growth_rate(window=(0.0, 5.0), amplitude=True).ratedamping_rate
Section titled “damping_rate”damping_ratemethod#
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
Returns
FitResult or None- The fit to the peaks; the rate is negative for damping.
Nonewith fewer than two valid peaks.
Examples
>>> energy.plasma.analysis.damping_rate(amplitude=True).rateoscillation_frequency
Section titled “oscillation_frequency”oscillation_frequencymethod#
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 Noneomega,periodand thetimesof the crossings or peaks used;Nonewith fewer than two.
Examples
>>> probe.plasma.analysis.oscillation_frequency(window=(5.0, 40.0)).omegamap_coordinate
Section titled “map_coordinate”map_coordinatemethod#
def map_coordinate(dim: str, mapping, *, name: str | None = None, units: str | None = None, label: str | None = None) -> xr.DataArrayReplace 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.
Examples
>>> 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”envelopemethod#
def envelope() -> xr.DataArrayReturn the local maxima of this time series.
Returns
xarray.DataArray- The peaks, over their times
t.
normmethod#
def norm(dims=None, squared: bool = False) -> xr.DataArrayReturn the L2 norm over dims (default: every dimension except t).
Parameters
Returns
xarray.DataArray- The norm over the remaining dimensions, e.g.
t.
Examples
>>> div_B.plasma.analysis.norm()driftmethod#
def drift(ref=None) -> xr.DataArrayReturn 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.
Examples
>>> energy.plasma.analysis.drift().plasma.plot.timeseries()relative_error
Section titled “relative_error”relative_errormethod#
def relative_error(ref=None, skip_first: bool = True) -> xr.DataArrayReturn 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.
Examples
>>> energy.plasma.analysis.relative_error(ref=exact_solution)spatial_average
Section titled “spatial_average”spatial_averagemethod#
def spatial_average(dims=None) -> xr.DataArrayReturn 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.
Examples
>>> distribution.plasma.analysis.spatial_average()velocity_moments
Section titled “velocity_moments”velocity_momentsmethod#
def velocity_moments(dims=None) -> xr.DatasetReturn density, mean velocity and variance of a binned distribution over its velocity dimensions.
See 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.
Examples
>>> distribution.plasma.analysis.velocity_moments()dispersion
Section titled “dispersion”dispersionmethod#
def dispersion(dim: str | None = None, detrend: bool = True) -> xr.DataArrayReturn 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()). 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
Returns
xarray.DataArray- The power over
omegaand the wavenumber.
Examples
>>> spectrum = E.isel(eta2=0, eta3=0).plasma.analysis.dispersion()fit_branches
Section titled “fit_branches”fit_branchesmethod#
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.
Examples
>>> field.plasma.analysis.dispersion().plasma.analysis.fit_branches(... n_branches=2... )fftmethod#
def fft(dim: str, detrend: bool = False, window: str | None = None) -> xr.DataArrayReturn the two-sided Fourier coefficients along dim.
Parameters
Returns
xarray.DataArray- The complex coefficients.
Examples
>>> phi.plasma.analysis.fft(dim="eta1")time_fft
Section titled “time_fft”time_fftmethod#
def time_fft(detrend: bool = False, window: str | None = None) -> xr.DatasetReturn the one-sided temporal coefficients and the power per bin.
Parameters
Returns
xarray.Datasetcoefficientsandpoweroveromegaand the other dimensions.
Examples
>>> phi.plasma.analysis.time_fft(detrend=True)filter_time
Section titled “filter_time”filter_timemethod#
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.
Examples
>>> band = phi.plasma.analysis.filter_time(dims=("eta1", "eta2", "eta3"))band_filter
Section titled “band_filter”band_filtermethod#
def band_filter(omega_lo: float, omega_hi: float, *, detrend: bool = False) -> xr.DataArrayReturn only the frequencies in [omega_lo, omega_hi].
Parameters
Returns
xarray.DataArray- The filtered signal, on this array’s grid.
Examples
>>> phi.plasma.analysis.band_filter(0.08, 0.11)spectral_peaks
Section titled “spectral_peaks”spectral_peaksmethod#
def spectral_peaks(n_peaks: int = 3, dims=None, omega_min: float = 1e-08, detrend=True, window=None) -> xr.DatasetReturn 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.
Examples
>>> phi.plasma.analysis.spectral_peaks(n_peaks=2)spectrogram
Section titled “spectrogram”spectrogrammethod#
def spectrogram(length, step=None, detrend: bool = True, window: str | None = 'hann') -> xr.DataArrayReturn 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, ...),tbeing each window’s center.
Examples
>>> signal.plasma.analysis.spectrogram(length=200.0, step=10.0)mode_spectrum
Section titled “mode_spectrum”mode_spectrummethod#
def mode_spectrum(dims=None, names=('m', 'n'), periods=None, scale=None) -> xr.DataArrayReturn 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()), ("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()), 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
namesand every remaining dimension.
Examples
>>> modes = phi.plasma.analysis.mode_spectrum()mode_amplitudes
Section titled “mode_amplitudes”mode_amplitudesmethod#
def mode_amplitudes(top: int | None = None, real: bool = True, relative: bool = False) -> xr.DataArrayReturn 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
modeand every remaining dimension.
Examples
>>> phi.plasma.analysis.mode_spectrum().plasma.analysis.mode_amplitudes(top=4)mode_structure
Section titled “mode_structure”mode_structuremethod#
def mode_structure(omega: float, *, window: str | None = 'hann', detrend: bool = True) -> xr.DataArrayReturn the complex amplitude at the exact frequency omega at every point.
Parameters
Returns
xarray.DataArray- The complex amplitude over every dimension but
t.
Examples
>>> phi.plasma.analysis.mode_structure(omega)cross_spectrum
Section titled “cross_spectrum”cross_spectrummethod#
def cross_spectrum(other: xr.DataArray, *, dims=None, detrend: bool = True, window=None) -> xr.DatasetReturn 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 overomega.
Examples
>>> u.plasma.analysis.cross_spectrum(b, dims="eta3")matrix_pencil
Section titled “matrix_pencil”matrix_pencilmethod#
def matrix_pencil(n_modes: int = 1, pencil: int | None = None, detrend: bool = False) -> xr.DatasetReturn 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.Datasetomega,gamma,amplitudeandphasealongmode, strongest first.
Examples
>>> probe.plasma.analysis.matrix_pencil(n_modes=1)gradient
Section titled “gradient”gradientmethod#
def gradient(domain=None) -> xr.DataArrayReturn 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
componentdimension(x, y, z).
Examples
>>> phi.plasma.analysis.gradient()surface_average
Section titled “surface_average”surface_averagemethod#
def surface_average(jacobian=None, domain=None, quadrature=None) -> xr.DataArrayReturn 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.
Examples
>>> ev.mod_B.plasma.analysis.surface_average(jacobian=ev.Jac)rational_surfaces
Section titled “rational_surfaces”rational_surfacesmethod#
def rational_surfaces(count: int = 4, nfp: int | None = None, max_denominator: int = 12) -> xr.DataArrayReturn 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()), else 1. |
max_denominator | int | 12 | The largest m. Default: 12. |
Returns
xarray.DataArray- The positions over
surface, with the coordinatesn,mandvalue.
Examples
>>> ev.iota.plasma.analysis.rational_surfaces(count=3)errormethod#
def error(exact, *, norm: str = 'rms', relative: bool = False, dims=None, weighted: bool = False, domain=None, args=None) -> xr.DataArrayReturn 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.
Examples
>>> T.plasma.analysis.error(exact, relative=True)>>> T.plasma.analysis.error(exact, norm="max")project_mode
Section titled “project_mode”project_modemethod#
def project_mode(dim: str, number: float, kind: str = 'sin', period: float = 1.0, bin_correction: bool = False) -> xr.DataArrayReturn 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.
Examples
>>> rho.plasma.analysis.project_mode(dim="eta2", number=3, kind="complex")divergence
Section titled “divergence”divergencemethod#
def divergence(components: str = 'cartesian', domain=None) -> xr.DataArrayReturn 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
componentdimension.
Examples
>>> B.plasma.analysis.divergence()curlmethod#
def curl(components: str = 'cartesian', domain=None) -> xr.DataArrayReturn 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
componentdimension.
Examples
>>> B.plasma.analysis.curl()flux_function
Section titled “flux_function”flux_functionmethod#
def flux_function() -> xr.DataArrayReturn the flux (or stream) function of this 2-D in-plane field.
Returns
xarray.DataArray- The flux function, without the
componentdimension.
Examples
>>> B.plasma.analysis.flux_function()cylindrical_components
Section titled “cylindrical_components”cylindrical_componentsmethod#
def cylindrical_components() -> xr.DataArrayReturn the Cartesian components rotated to (R, phi, Z).
Returns
xarray.DataArray- The vector field in cylindrical components.
Examples
>>> E.plasma.analysis.cylindrical_components()toroidal_components
Section titled “toroidal_components”toroidal_componentsmethod#
def toroidal_components(R0: float, Z0: float = 0.0) -> xr.DataArrayReturn the Cartesian components rotated to (radial, poloidal, toroidal) about an axis at R0.
Parameters
Returns
xarray.DataArray- The vector field in toroidal components.
Examples
>>> u.plasma.analysis.toroidal_components(R0=3.0)polar_coordinates
Section titled “polar_coordinates”polar_coordinatesmethod#
def polar_coordinates(center=(0.0, 0.0)) -> xr.DataArrayReturn this array with coordinates r and theta in the X-Y plane.
Parameters
Returns
xarray.DataArray- This array with the added coordinates.
Examples
>>> n.plasma.analysis.polar_coordinates(center=(0.0, 0.0))trace_branch
Section titled “trace_branch”trace_branchmethod#
def trace_branch(theory, *, window: float = 0.2, k_range=None, threshold: float = 0.001) -> xr.DatasetReturn 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 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.
Examples
>>> 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_endpointmethod#
def drop_periodic_endpoint(dim: str, *, period: float = 1.0) -> xr.DataArrayReturn this array without a duplicated periodic endpoint along dim.
Parameters
Returns
xarray.DataArray- This array, one point shorter along
dimif its last point repeats the first.
field_lines
Section titled “field_lines”field_linesmethod#
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.DatasetTrace 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(). |
**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.
Examples
>>> 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_alongmethod#
def sample_along(lines: xr.Dataset) -> xr.DataArrayReturn 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.
Examples
>>> 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_wavenumbermethod#
def parallel_wavenumber(lines: xr.Dataset | None = None, method: str = 'fft', detrend: bool = True) -> xr.DataArrayReturn 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(), 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.DataArrayk_paralleloverlineand the other dimensions.
Examples
>>> phi.plasma.analysis.parallel_wavenumber(lines=lines)boozer_spectrum
Section titled “boozer_spectrum”boozer_spectrummethod#
def boozer_spectrum(top: int | None = None, angles: str = 'boozer') -> xr.DataArrayReturn 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(withm,n) and the radius.
Examples
>>> boozer.mod_B.plasma.analysis.boozer_spectrum(top=8)quasisymmetry_error
Section titled “quasisymmetry_error”quasisymmetry_errormethod#
def quasisymmetry_error(helicity='QA', angles: str = 'boozer') -> xr.DataArrayReturn 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(). |
Returns
xarray.DataArrayf_QSover the radius.
Examples
>>> boozer.mod_B.plasma.analysis.quasisymmetry_error(helicity="QH")critical_points
Section titled “critical_points”critical_pointsmethod#
def critical_points(refine: bool = True) -> xr.DatasetReturn the O-points and X-points of this flux function (at every time).
Parameters
Returns
xarray.Dataset- The points over
point(andt): positions, values and kinds.
Examples
>>> B.plasma.analysis.flux_function().plasma.analysis.critical_points()reconnected_flux
Section titled “reconnected_flux”reconnected_fluxmethod#
def reconnected_flux(relative: bool = True, o_point=None, x_point=None) -> xr.DataArrayReturn the reconnected flux over time: this flux function between an O- and an X-point.
Parameters
Returns
xarray.DataArrayΔΨ(t).
Examples
>>> A = B.plasma.analysis.flux_function()>>> A.plasma.analysis.reconnected_flux().plasma.plot.timeseries(... fit=(10.0, 30.0)... )