API Reference

Data Model

SpaceDataModel.AbstractDataVariableType

A variable v of a type derived from AbstractDataVariable should at least implement:

  • Base.parent(v): the parent array of the variable

Optional:

  • times(v): the timestamps of the variable
  • units(v): the units of the variable
  • meta(v): the metadata of the variable
  • name(v): the name of the variable
source
SpaceDataModel.InstrumentType
Instrument <: AbstractInstrument

Fields

  • name: The name of the instrument
  • metadata: Additional metadata
  • datasets: Collection of datasets
source
SpaceDataModel.LDataSetType
LDataSet <: AbstractDataSet

A template for generating datasets with parameterized naming patterns.

Fields

  • format: Format string pattern for the dataset name
  • data: Dictionary of variable patterns
  • metadata: Additional metadata

Examples

using SPEDAS.MMS

# Access FPI dataset specification
lds = mms.datasets.fpi_moms

# Create a concrete dataset with specific parameters
ds = DataSet(lds; probe=1, data_rate="fast", data_type="des")

The format string and variable patterns use placeholders like {probe}, {data_rate}, which are replaced with actual values when creating a concrete DataSet.

source
SpaceDataModel.NoMetadataType
NoMetadata

Indicates an object has no metadata. But unlike using nothing, get, keys and haskey will still work on it, get always returning the fallback argument. keys returns () while haskey always returns false.

source
SpaceDataModel.ProjectType
Project <: AbstractProject

A representation of a project or mission containing instruments and datasets.

Fields

  • name: The name of the project
  • metadata: Additional metadata
  • instruments: Collection of instruments
  • datasets: Collection of datasets
source

Coordinate Transformations

SPEDAS.cotransFunction
cotrans(A, in, out)
cotrans(A, out; in=get_coord(A))

Transform the data to the out coordinate system from the in coordinate system.

This function automatically choose between Julia's GeoCotrans (if available) and Fortran's IRBEM implementation.

References:

source
GeoCotrans.GeoCotransModule

Coordinate systems, transformations, and geomagnetic field models.

Coordinate systems

  • GEO: Geocentric geographic cartesian coordinate system (x [𝐋], y [𝐋], z [𝐋]).
  • GSM: Geocentric Solar Magnetic (GSM) coordinate system.
  • GSE: Geocentric Solar Ecliptic (GSE) coordinate system.
  • GEI: Geocentric Equatorial Inertial (GEI) coordinate system.
  • GDZ: Geodetic (GDZ) coordinate system (altitude [km], latitude [deg], longitude [deg]).
  • MAG: Magnetic (MAG) coordinate system.
  • SPH: Geocentric geographic spherical (SPH) coordinate system (r [𝐋], θ [deg], φ [deg]).
  • J2000: J2000 (J2000) coordinate system.

Coordinate transformations

References

International Geomagnetic Reference Field (IGRF)

The International Geomagnetic Reference Field (IGRF) is a standard mathematical description of the Earth's main magnetic field. It is used widely in studies of the Earth's deep interior, crust, ionosphere, and magnetosphere.

Functions

  • igrf_B: Compute the geomagnetic field (IGRF-14, dipole model)

Examples

r, θ, φ = 6500., 30., 4.
t = Date(2021, 3, 28)
Br, Bθ, Bφ = igrf_B(r, θ, φ, t)

# Input position in geodetic coordinates, output magnetic field in East-North-Up (ENU) coordinates
Be, Bn, Bu = igrf_B(GDZ(0, 60.39299, 5.32415), t)

References

Elsewhere

source
GeoCotrans.GSMType

Geocentric Solar Magnetospheric (GSM)

X points sunward from Earth's center. The X-Z plane is defined to contain Earth's dipole axis (positive North).

source
GeoCotrans.calc_dipole_angleMethod
calc_dipole_angle(g10, g11, h11)

Calculate dipole angle (θ, φ) and dipole strength (b0) from spherical harmonic coefficients g10, g11, h11.

θ: dipole tilt angle (radians) φ: dipole longitude/phase (radians) b0: dipole strength (nT)

source
GeoCotrans.calculate_gstMethod
calculate_gst(time)

Calculate Greenwich sidereal time (GST) in radians from the given time.

Reference: https://aa.usno.navy.mil/faq/GAST, https://github.com/JuliaAstro/AstroLib.jl/blob/main/src/ct2lst.jl

source
GeoCotrans.calculate_gst_altMethod
calculate_gst_alt(time)

Alternative implementation of Greenwich sidereal time calculation based on the reference algorithm from pyspedas.cotrans_tools.csundir_vect.

source
GeoCotrans.car2sphMethod
car2sph(x, y, z)

Convert (x, y, z) in Cartesian coordinate to (r, colat [deg], lon [deg]) in spherical coordinate.

source
GeoCotrans.cdipdirMethod
cdipdir(time)

Compute dipole direction in GEO coordinates. [PySPEDAS]

References

  • https://pyspedas.readthedocs.io/en/latest/coords.html#pyspedas.cotranstools.cotranslib.cdipdir
source
GeoCotrans.csundirMethod
csundir(time)

Calculate the direction of the sun.

Returns

  • gst: Greenwich mean sidereal time (radians)
  • slong: Longitude along ecliptic (radians)
  • sra: Right ascension (radians)
  • sdec: Declination of the sun (radians)
  • obliq: Inclination of Earth's axis (radians)

Notes

  • This function calculates various parameters related to the sun's position needed for coordinate transformations.
source
GeoCotrans.gdz2sphMethod
gdz2sph(alt, lat, lon)

Convert (alt [km], lat [deg], lon [deg]) in Geodetic coordinate to Spherical geocentric coordinate.

source
GeoCotrans.gei2geoMethod
gei2geo(x, t)

Transforms x vector from Geocentric Equatorial Inertial (GEI) to Geographic (GEO) coordinates at time t.

source
GeoCotrans.gei2gsmMethod
gei2gsm(x, t)

Transforms x vector from Geocentric Equatorial Inertial (GEI) to Geocentric Solar Magnetic (GSM) coordinates at time t.

source
GeoCotrans.gei2gsm_matMethod
gei2gsm_mat(time)

Compute the GEI to GSM transformation matrix.

First axis: sun direction (xS, yS, zS) Second axis: y-axis (cross product of dipole and sun, normalized) Third axis: z-axis (cross product of sun and y-axis, normalized)

source
GeoCotrans.geo2geiMethod
geo2gei(x, t)

Transforms x vector from Geographic (GEO) to Geocentric Equatorial Inertial (GEI) coordinates at time t.

source
GeoCotrans.geo2gsmMethod
geo2gsm(x, t)

Transforms x vector from Geographic (GEO) to Geocentric Solar Magnetic (GSM) coordinates at time t.

source
GeoCotrans.get_dipole_termsMethod
get_dipole_terms(g, h)

Compute dipole parameters (θ, φ, x0, y0, z0, b0) from IGRF coefficients.

Returns a named tuple: (θ, φ, x0, y0, z0, b0)

source
GeoCotrans.get_igrf_coeffsMethod
get_igrf_coeffs(time)

Get IGRF-14 coefficients for a given time.

Similar to IRBEM implementation, but with higher precision (IRBEM uses year as the time unit).

source
GeoCotrans.gse2gsmFunction
gse2gsm(x, t)

Transforms x vector from Geocentric Solar Ecliptic (GSE) to Geocentric Solar Magnetic (GSM) coordinates at time t.

See also: gse2gsm_mat

source
GeoCotrans.gse2gsmMethod
gse2gsm(x, t)

Transforms x vector from Geocentric Solar Ecliptic (GSE) to Geocentric Solar Magnetic (GSM) coordinates at time t.

source
GeoCotrans.gse2gsm_matMethod
gse2gsm_mat(time)

Compute the GSE to GSM transformation matrix T3 = <- psi,X>, where the rotation angle psi is the GSE-GSM angle.

This transformation is a rotation in the GSE YZ plane from the GSE Z axis to the GSM Z axis.

source
GeoCotrans.gsm2geiMethod
gsm2gei(x, t)

Transforms x vector from Geocentric Solar Magnetic (GSM) to Geocentric Equatorial Inertial (GEI) coordinates at time t.

source
GeoCotrans.gsm2geoMethod
gsm2geo(x, t)

Transforms x vector from Geocentric Solar Magnetic (GSM) to Geographic (GEO) coordinates at time t.

source
GeoCotrans.gsm2gseMethod
gsm2gse(x, t)

Transforms x vector from Geocentric Solar Magnetic (GSM) to Geocentric Solar Ecliptic (GSE) coordinates at time t.

source
GeoCotrans.igrf_BMethod
igrf_B(r, θ, φ, t; max_degree=IGRF_degree) -> (Br, Bθ, Bφ)

Calculate IGRF model components in geocentric coordinates (r [km], θ [rad], φ [rad]) at time t.

Parameters

  • r: radius [km]
  • θ: colatitude [rad]
  • φ: longitude [rad], positive east
  • maxdegree: highest degree of expansion (1 <= maxdegree <= 13)
source
GeoCotrans.igrf_BMethod
igrf_B(𝐫::CoordinateVector{GDZ}, t; max_degree=IGRF_degree) -> (Be, Bn, Bu)

Calculate IGRF model components in east, north, up (ENU) coordinates for geodetic coordinates 𝐫 at time t.

source
GeoCotrans.igrf_BdMethod
igrf_Bd(r, θ, φ, t; max_degree=IGRF_degree) -> (Br, Bθ, Bφ)

Calculate IGRF model components in geocentric coordinates (r [km], θ [deg], φ [deg]) at time t.

Parameters

  • r: radius [km]
  • θ: colatitude [deg]
  • φ: longitude [deg]
  • maxdegree: highest degree of expansion (1 <= maxdegree <= 13)
source

TPlot

SPEDAS.TPlot.DebouncerType
Debouncer

A struct that creates a debounced version of a function f.

The debounced function will only execute after a specified delay (in seconds) of inactivity. If called again before the delay expires, the timer resets.

source
SPEDAS.TPlot.DualAxisDataType
DualAxisData(data1, data2; meta=nothing)

A type for handling dual-axis data where each field represents data for a different axis. The first field is plotted against the left y-axis and the second field against the right y-axis.

Fields

  • data1: Data for the left y-axis
  • data2: Data for the right y-axis
  • metadata: Metadata for the data (e.g., title)
source
SPEDAS.TPlot.DualPlotType

DualPlot is the plot type associated with plotting function dualplot. Check the docstring for dualplot for further information.

source
SPEDAS.TPlot.FunctionPlotType

FunctionPlot is the plot type associated with plotting function functionplot. Check the docstring for functionplot for further information.

source
SPEDAS.TPlot.LinesPlotType

LinesPlot is the plot type associated with plotting function linesplot. Check the docstring for linesplot for further information.

source
SPEDAS.TPlot.MultiPlotType

MultiPlot is the plot type associated with plotting function multiplot. Check the docstring for multiplot for further information.

source
SPEDAS.TPlot.PanelPlotType

PanelPlot is the plot type associated with plotting function panelplot. Check the docstring for panelplot for further information.

source
SPEDAS.TPlot.SpecPlotType

SpecPlot is the plot type associated with plotting function specplot. Check the docstring for specplot for further information.

source
SPEDAS.TPlot.add_labels!Function

Add labels to a figure, automatically searching for blocks to label.

Notes

  • https://github.com/brendanjohnharris/Foresight.jl/blob/main/src/Layouts.jl#L2
source
SPEDAS.TPlot.auto_figure_sizeMethod
auto_figure_size(tas)

Calculate an appropriate figure size based on the number of plots in the list. Returns a tuple of (width, height) in pixels.

source
SPEDAS.TPlot.dualplotFunction

No docstring defined.

Plot type

The plot type alias for the dualplot function is DualPlot.

Attributes

color2 = (Makie.wong_colors())[end - 1]No docs available.

linestyle2 = :dashNo docs available.

marker2 = :rectNo docs available.

plotfunc = scatterlines!No docs available.

source
SPEDAS.TPlot.dualplot!Function

dualplot! is the mutating variant of plotting function dualplot. Check the docstring for dualplot for further information.

source
SPEDAS.TPlot.functionplotFunction

No docstring defined.

Plot type

The plot type alias for the functionplot function is FunctionPlot.

Attributes

plotfunc = tplot_panel!No docs available.

source
SPEDAS.TPlot.functionplot!Function

functionplot! is the mutating variant of plotting function functionplot. Check the docstring for functionplot for further information.

source
SPEDAS.TPlot.linesplotFunction

No docstring defined.

Plot type

The plot type alias for the linesplot function is LinesPlot.

Attributes

labels = nothingNo docs available.

source
SPEDAS.TPlot.linesplot!Function

linesplot! is the mutating variant of plotting function linesplot. Check the docstring for linesplot for further information.

source
SPEDAS.TPlot.multiplotFunction

No docstring defined.

Plot type

The plot type alias for the multiplot function is MultiPlot.

Attributes

plotfunc = plot!No docs available.

source
SPEDAS.TPlot.multiplot!Function

multiplot! is the mutating variant of plotting function multiplot. Check the docstring for multiplot for further information.

source
SPEDAS.TPlot.multiplot!Method
multiplot!(ax, fs, t0, t1; plotfunc=plot2spec, kwargs...)

Specialized multiplot function for functionplot. Merge specs before plotting so as to cycle through them.

source
SPEDAS.TPlot.multiplotMethod
multiplot(gp, tas::MultiPlottable, args...; axis=(;), kwargs...)

Setup the panel on a position and plot multiple time series on it

source
SPEDAS.TPlot.panelplotFunction

No docstring defined.

Plot type

The plot type alias for the panelplot function is PanelPlot.

Attributes

color = @inherit linecolorNo docs available.

cycle = [:color]No docs available.

plotfunc = plot!No docs available.

source
SPEDAS.TPlot.panelplot!Function

panelplot! is the mutating variant of plotting function panelplot. Check the docstring for panelplot for further information.

source
SPEDAS.TPlot.plotfuncFunction

Determine the plotting function for a given data type. Extend this for custom data types to integrate with the plotting system.

source
SPEDAS.TPlot.plotfunc!Function

Determine the plotting function for a given data type. Extend this for custom data types to integrate with the plotting system.

source
SPEDAS.TPlot.specplotFunction

No docstring defined.

Plot type

The plot type alias for the specplot function is SpecPlot.

Attributes

source
SPEDAS.TPlot.specplot!Function

specplot! is the mutating variant of plotting function specplot. Check the docstring for specplot for further information.

source
SPEDAS.TPlot.spectrogram_y_valuesMethod
spectrogram_y_values(ta; check=false, center=false, transform=identity)

Get y-axis values from a spectrogram array. Can return either bin centers or edges. By default, return bin edges for better compatibility.

Arguments

  • check: If true, check if values are constant along time
  • center: If true, return bin centers instead of edges
  • transform: Optional transform function for edge calculation (e.g., log for logarithmic bins)

Reference: Makie.edges

source
SPEDAS.TPlot.tplotMethod
tplot(f, tas; legend=(; position=Right()), link_xaxes=true, link_yaxes=false, rowgap=5, transform=transform_pipeline, kwargs...)

Lay out multiple time series across different panels (rows) on one Figure / GridPosition f

If legend is nothing, no legend will be added to the plot. Otherwise, legend can be a NamedTuple containing options for legend placement and styling. By default, the time series are transformed via transform_pipeline, which is extensible via transform.

See also: tplot_panel, transform_pipeline, transform

source
SPEDAS.TPlot.tplot_panel!Method
tplot_panel!(ax, args...; kwargs...)

Generic entry point for adding plots to an existing axis ax.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source
SPEDAS.TPlot.tplot_panelMethod
tplot_panel(gp, args...; kwargs...)

Generic entry point for plotting different types of data on a grid position gp.

Transforms the arguments to appropriate types and calls the plotting function. Dispatches to appropriate implementation based on the plotting trait of the transformed arguments.

source
SPEDAS.TPlot.transformMethod
transform(args...; kwargs...)

Transform data into plottable format (e.g., DimArray).

Extend with transform(x::MyType) for custom types.

source
SPEDAS.TPlot.x2tMethod

Convert x to DateTime

Reference:

  • https://docs.makie.org/dev/explanations/dim-converts#Makie.DateTimeConversion
  • https://github.com/MakieOrg/Makie.jl/issues/442
  • https://github.com/MakieOrg/Makie.jl/blob/master/src/dim-converts/dates-integration.jl
source

SPEDAS

SPEDAS.DEFAULTSConstant
SPEDAS.DEFAULTS

A global constant that holds default parameters:

  • add_title::Bool defaults to false.
  • add_colorbar::Bool defaults to true.
  • delay : in seconds, the time interval between updates. Default is 0.25.
  • resample::Int : the number of points to resample to. Default is 6070.
source
SPEDAS.B_x3_errorMethod

Calculate the composite statistical error estimate for ⟨B·x₃⟩: |Δ⟨B·x₃⟩| = √(λ₃/(M-1) + (Δφ₃₂⟨B⟩·x₂)² + (Δφ₃₁⟨B⟩·x₁)²)

Parameters:

  • λ₁, λ₂, λ₃: eigenvalues in descending order
  • M: number of samples
  • B: mean magnetic field vector
  • x₁, x₂, x₃: eigenvectors
source
SPEDAS.ConstantThicknessApproachMethod

Constant Thickness Approach (CTA) for determining boundary normal and velocity. Based on the method described in Haaland et al., Annales Geophysicae, 2004.

source
SPEDAS.ConstantVelocityApproachMethod
CVA(positions, times)

Constant Velocity Approach (CVA) for determining boundary normal and velocity. Solve timing equation: $D * m = Δts$

Parameters:

  • positions: Positions of 4 spacecraft (4×3 array)
  • times: Times of boundary crossing for each spacecraft
source
SPEDAS.amapMethod
amap(f, a, b)

Apply a function f to the intersection of a and b.

https://github.com/rafaqz/DimensionalData.jl/issues/914

source
SPEDAS.binedgesMethod
binedges(centers; transform=identity)

Calculate bin edges from bin centers.

  • For linear spacing, edges are placed halfway between centers.
  • For transformed spacing, edges are placed halfway between transformed centers.

Arguments

  • transform: Function to transform the space (e.g., log for logarithmic spacing)

Example

centers = [1.0, 2.0, 3.0]
edges = binedges(centers)               # Returns [0.5, 1.5, 2.5, 3.5]
edges = binedges(centers, transform=log)  # Returns edges in log space
source
SPEDAS.check_mva_eigenMethod
check_mva_eigen(F; r=5, verbose=false)

Check the quality of the MVA result.

If λ₁ ≥ λ₂ ≥ λ₃ are 3 eigenvalues of the constructed matrix M, then a good indicator of nice fitting LMN coordinate system should have λ₂ / λ₃ > r.

source
SPEDAS.common_timerangeMethod
common_timerange(arrays; query=timeDimType)

Get the common time range (intersection) across multiple arrays. If there is no overlap, returns nothing.

source
SPEDAS.cotransMethod
cotrans(A, in, out)
cotrans(A, out; in=get_coord(A))

Transform the data to the out coordinate system from the in coordinate system.

This function automatically choose between Julia's GeoCotrans (if available) and Fortran's IRBEM implementation.

References:

source
SPEDAS.current_densityMethod
current_density(B, V)

Calculate the current density time series from the magnetic field (B) and plasma velocity (V) time series.

Assume 1-D structure along the z-direction. Remember to transform the coordinates of B and V first (e.g. using mva

source
SPEDAS.dropnaMethod
dropna(da::DimArray, query)

Remove slices containing NaN values along dimensions other than query.

source
SPEDAS.fac_matMethod
fac_mat(vec::AbstractVector; xref=[1.0, 0.0, 0.0])

Generates a field-aligned coordinate (FAC) transformation matrix for a vector.

Arguments

  • vec: A 3-element vector representing the magnetic field
source
SPEDAS.fill_gapsMethod
fill_gaps(times, data; resolution, margin)

Given a sorted vector of time stamps times and corresponding data values, this function inserts missing time stamps with a value of NaN if the gap between consecutive time stamps is larger than resolution + margin.

  • If the gap is only slightly larger (within margin of the resolution), no gap is inserted.
  • The function supports numeric times or DateTime (with appropriate resolution types).

Arguments

  • times: Sorted vector of time stamps.
  • resolution: The expected time difference between consecutive time stamps.
  • margin: Allowed deviation from resolution before inserting missing time stamps.

Returns

A tuple (full_times, full_values) where:

  • full_times is a vector containing all time stamps (original and inserted).
  • full_values is a vector of data values with NaN for inserted gaps.

References

  • https://pyspedas.readthedocs.io/en/latest/modules/pytplot/tplotmath/degap.html
source
SPEDAS.find_continuous_timerangesMethod
find_continuous_timeranges(x, max_dt)

Find continuous time ranges for x (e.g. times or DimArray). max_dt is the maximum time gap between consecutive times.

source
SPEDAS.find_outliersMethod
find_outliers(A, [method, window]; dim = 1, kw...)

Find outliers in data A along the specified dim dimension.

Returns a Boolean array whose elements are true when an outlier is detected in the corresponding element of A.

The default method is :median (other option is :mean), which uses the median absolute deviation (MAD) to detect outliers. When the length of A is greater than 256, it uses a moving window of size 16.

See also: find_outliers_median, find_outliers_mean, isoutlier - MATLAB

source
SPEDAS.find_outliers_meanMethod
find_outliers_mean(x::AbstractVector, window; threshold = 3)

Find outliers that are defined as elements more than three standard deviations from the mean.

This method is faster but less robust than find_outliers_median.

source
SPEDAS.find_outliers_medianMethod
find_outliers_median(x, window; threshold=3)

Find outliers that are defined as elements more than threshold=3 times the scaled median absolute deviation (MAD) from the median.

When window is set to a integer, a moving window of that size is used to compute local MAD. Otherwise, global statistics are used.

References

source
SPEDAS.interpolate_nansMethod
interpolate_nans(da; interp=LinearInterpolation)

Interpolate only the NaN values in da along the specified dimension dims. Non-NaN values are preserved exactly as they are.

The default interpolation method interp is LinearInterpolation.

source
SPEDAS.lingradestMethod
lingradest(
    Bx1, Bx2, Bx3, Bx4,
    By1, By2, By3, By4,
    Bz1, Bz2, Bz3, Bz4,
    R1, R2, R3, R4
)

SPEDAS-argument-compatible version of lingradest.

source
SPEDAS.lingradestMethod
lingradest(B1, B2, B3, B4, R1, R2, R3, R4)

Compute spatial derivatives such as grad, div, curl and curvature using reciprocal vector technique (linear interpolation).

Arguments

  • B1, B2, B3, B4: 3-element vectors giving magnetic field measurements at each probe
  • R1, R2, R3, R4: 3-element vectors giving the probe positions

Returns

A named tuple containing: • Rbary: Barycenter position • Bbc: Magnetic field at the barycenter • Bmag: Magnetic field magnitude at the barycenter • LGBx, LGBy, LGBz: Linear gradient estimators for each component • LD: Linear divergence estimator • LCB: Linear curl estimator • curvature: Field‐line curvature vector • R_c: Field‐line curvature radius

References

Based on the method of Chanteur (ISSI, 1998, Ch. 11).

source
SPEDAS.lingradestMethod
lingradest(B1::AbstractDimArray, args...)

Method for handling dimensional arrays. Takes AbstractDimArray inputs with a time dimension and returns a DimStack containing all computed quantities.

source
SPEDAS.lingradestMethod
lingradest(B1::MatrixLike, args...)

Vectorized method for simplified usage. Returns a StructArray containing the results.

source
SPEDAS.m2nVMethod

Convert slowness vector $𝐦 = 𝐧/V$ to normal vector and velocity

source
SPEDAS.mvaFunction
mva(V, B=V; kwargs...)

Rotate a timeseries V into the LMN coordinates based on the reference field B.

Arguments

  • V: The timeseries data to be transformed, where each column represents a component
  • B: The reference field used to determine the minimum variance directions, where each column represents a component

See also: mva_eigen, rotate

source
SPEDAS.mva_eigenMethod
mva_eigen(B::AbstractMatrix; sort=(;), check=false) -> F::Eigen

Perform minimum variance analysis, returning Eigen factorization object F which contains the eigenvalues in F.values and the eigenvectors in the columns of the matrix F.vectors.

Set check=true to check the reliability of the result.

The kth eigenvector can be obtained from the slice F.vectors[:, k].

source
SPEDAS.nt2dsMethod
nt2ds(nt_arr, dim; fields=propertynames(first(nt_arr)))

Convert a NamedTuple array to a DimStack of DimArrays.

source
SPEDAS.phase_factorMethod

Phase factor exp (i φ) satisfies the following equation

$\exp (4 i φ) = \exp (-2 i γ)$

where

$γ = \arctan (2 Re(𝐮)^𝐓 Im(𝐮) /(Re(𝐮)^2-Im(𝐮)^2))$

source
SPEDAS.polarizationMethod
polarization(S)

Compute the degree of polarization (DOP) p^2 from spectral matrix S.

\[\begin{aligned} p^2 &= 1-\frac{(tr 𝐒)^2-(tr 𝐒^2)}{(tr 𝐒)^2-n^{-1}(tr 𝐒)^2} \\ &= \frac{n(tr 𝐒^2)-(tr 𝐒)^2}{(n-1)(tr 𝐒)^2} \end{aligned}\]

source
SPEDAS.position_tensorMethod

\[𝐑 = ∑_α (𝐫_α-𝐫_b) (𝐫_α-𝐫_b)' = ∑_α 𝐫_α 𝐫_α'-𝐫_b 𝐫_b'\]

with $𝐫_b = ∑_α 𝐫_α / N$ and N is the number of positions.

References

source
SPEDAS.pspectrumMethod
pspectrum(x::AbstractDimArray, spec::Spectrogram)
pspectrum(x::AbstractDimArray; nfft=256, noverlap=128, window=hamming)

Compute the power spectrum (time-frequency representation) of a time series using the short-time Fourier transform.

Returns a DimArray with frequency and original time dimensions.

See also: DSP.Spectrogram, DSP.stft

Reference

source
SPEDAS.reciprocal_vectorMethod
reciprocal_vector(rα, rβ, rγ, rλ)

Compute the reciprocal vector $𝒌_α$ for a vertex of a tetrahedron given the position vectors of all vertices.

The vertices (α, β, γ, λ) must form a cyclic permutation of (1, 2, 3, 4).

source
SPEDAS.reciprocal_vectorMethod
reciprocal_vector(r_βα, r_βγ, r_βλ)

Compute the reciprocal vector $𝒌_α$ for a vertex of a tetrahedron given the relative position vectors.

\[𝒌_α = \frac{𝐫_{βγ} × 𝐫_{βλ}}{𝐫_{βα} ⋅ (𝐫_{βγ} × 𝐫_{βλ})}\]

where $𝐫_{αβ} = r_β - r_α$ are relative position vectors.

References

  • Multi-spacecraft analysis methods revisited : 4.3 Properties of reciprocal vectors
source
SPEDAS.replace_outliers!Method
replace_outliers!(A, method, [find_method, window]; kwargs...)
replace_outliers!(A, method, outliers; kwargs...)

Replaces outliers in A with values determined by the specified method.

Outliers can be detected using find_outliers with optional find_method and window parameters or specified directly as a Boolean array outliers.

method can be one of the following:

  • :linear: Linear interpolation of neighboring, nonoutlier values
  • :previous: Previous nonoutlier value
  • :next: Next nonoutlier value
  • :nearest: Nearest nonoutlier value

See also: filloutliers - MATLAB

source
SPEDAS.resampleMethod
resample(arr, n=DEFAULTS.resample; dim=1, verbose=false)

Resample an array along the dimension dim to n points. If the original length is less than or equal to n, the original array is returned unchanged.

source
SPEDAS.rotateMethod
rotate(ts::AbstractMatrix, mat::AbstractMatrix)

Coordinate-aware transformation of vector/matrix by rotation matrix(s) mat(s). Assume ts is a matrix of shape (n, 3).

source
SPEDAS.set_coordMethod

Set the coordinate system.

Updates legend names and axis labels if they include the coordinate system. Also updates the dimension name if it contains the coordinate system.

Reference:

  • https://pyspedas.readthedocs.io/en/latest/modules/pytplot/dataattgetterssetters.html#set_coords
source
SPEDAS.smoothMethod
smooth(da::AbstractDimArray, window; dim=Ti, suffix="_smoothed", kwargs...)

Smooths a time series by computing a moving average over a sliding window.

The size of the sliding window can be either:

  • Quantity: A time duration that will be converted to number of samples based on data resolution
  • Integer: Number of samples directly

Arguments

  • dims=Ti: Dimension along which to perform smoothing (default: time dimension)
  • suffix="_smoothed": Suffix to append to the variable name in output
  • kwargs...: Additional arguments passed to RollingWindowArrays.rolling
source
SPEDAS.smooth_spectral_matrixMethod
smooth_spectral_matrix(S, aa)

Smooth the spectral matrix $S(f)$ by applying a weighted average over frequency. The smoothing uses a symmetric window aa (for example, a Hamming window) of length M.

Arguments

  • S: Spectral matrix array of size $N_{freq}, n, n$ where n is the number of components.
  • aa: Weighting vector of length M.
source
SPEDAS.spectral_matrixMethod
spectral_matrix(Xf)

Compute the spectral matrix $S$ defined by

\[S_{ij}(f) = X_i(f) X_j^*(f),\]

where $X_i(f)$=Xf[f, i] is the FFT of the i-th component and * denotes complex conjugation.

source
SPEDAS.spectral_matrixMethod
spectral_matrix(X, window)

Compute the spectral matrix $S(f)$ given the time series data X.

Returns a 3-D array of size $N_{freq}, n, n$, where $N_{freq} = \lfloor N/2 \rfloor$ and n is the dimensionality (number of components).

Arguments

  • X: Matrix where each column is a component of the multivariate time series, or a vector of vectors.
  • window: A window function (optional). If not provided, a rectangular window (no windowing) is used.
source
SPEDAS.tclipMethod
tclip(d, t0, t1)

Clip a dimension or DimArray to a time range [t0, t1].

source
SPEDAS.tclipsMethod
tclips(xs...; trange=common_timerange(xs...))

Clip multiple arrays to a common time range trange.

If trange is not provided, automatically finds the common time range across all input arrays.

source
SPEDAS.tcrossMethod
tcross(x, y; dims=TimeDim, stack=nothing)

Compute the cross product of two (arrays of) vectors along the dims dimension.

References:

  • https://docs.xarray.dev/en/stable/generated/xarray.cross.html
source
SPEDAS.tderivMethod
tderiv(data, times; dims = 1)

Compute the time derivative of data with respect to times.

source
SPEDAS.tdotMethod
tdot(x, y; dims=TimeDim)

Dot product of two arrays x and y along the dims dimension.

source
SPEDAS.tfilterFunction
tfilter(da, Wn1, Wn2=samplingrate(da) / 2; designmethod=Butterworth(2))

By default, the max frequency corresponding to the Nyquist frequency is used.

References

  • https://docs.juliadsp.org/stable/filters/
  • https://www.mathworks.com/help/signal/ref/filtfilt.html
  • https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html

Issues

  • DSP.jl and Unitful.jl: https://github.com/JuliaDSP/DSP.jl/issues/431
source
SPEDAS.tgroupbyMethod
tgroupby(x::AbstractDimArray, every, period = every, start_by = :window)

Returns a vector of AbstractDimArrays grouped by time intervals defined by every and period.

source
SPEDAS.tinterpFunction
tinterp(A, B, interp=LinearInterpolation)

Interpolate A to times in B

source
SPEDAS.tinterpFunction
tinterp(A, t; interp=LinearInterpolation)

Interpolate time series A at time point(s) t. Returns interpolated value for single time point or DimArray for multiple time points.

source
SPEDAS.tinterp_nansMethod
tinterp_nans(da::AbstractDimArray; query=timeDimType, kwargs...)

Interpolate only the NaN values in da along the specified dimensions query. Non-NaN values are preserved exactly as they are.

See also interpolate_nans

source
SPEDAS.tmask!Method
tmask!(da, t0, t1)
tmask!(da, it::Interval)
tmask!(da, its)

Mask all data values within the specified time range(s) (t0, t1) / it / its with NaN.

source
SPEDAS.tmeanMethod
tmean(x; query=TimeDim)

Calculate the mean of x along the query dimension (default: TimeDim).

It returns a value if x is a vector along the query dimension, otherwise returns a DimArray with the specified dimension dropped.

source
SPEDAS.tnorm_combineMethod
tnorm_combine(x; dims=timedim(x), name=:magnitude)

Calculate the norm of each slice along query dimension and combine it with the original components.

source
SPEDAS.tresampleFunction
tresample(da::DimArray, n=DEFAULTS.resample; dimtype=Ti)

Resample a DimArray specifically along its dimension of type dimtype to n points. Throws an error if no dimension of type dimtype is found in the array.

source
SPEDAS.tshiftFunction
tshift(x; dim=TimeDim, t0=nothing, new_dim=nothing)

Shift the dim of x by t0.

source
SPEDAS.tsplitFunction
tsplit(da::AbstractDimArray, dim=Ti)

Splits up data along dimension dim.

source
SPEDAS.tstackMethod
tstack(vectors::AbstractVector{<:AbstractVector{T}})

Stack a time series of vectors into a matrix.

By default, each row in the output matrix represents a time point from the input vector of vectors.

source
SPEDAS.tsubtractFunction
tsubtract(x, f=nanmedian; dims=timedim(x))

Subtract a statistic (default function f: nanmedian) along dimensions (default: time dimension) from x.

source
SPEDAS.tviewMethod
tview(d, t0, t1)

View a dimension or DimArray in time range [t0, t1].

source
SPEDAS.twavpolMethod
twavpol(x)

A convenience wrapper around wavpol that works with DimensionalData arrays.

It automatically extracts the time dimension and returns the results as a DimStack with properly labeled dimensions.

source
SPEDAS.wave_normal_angleMethod

Wave normal angle is the angle between (wnx, wny) and the vertical |wnz| Use the imaginary parts of off-diagonals. Define:$A = Im(S₁₂), B = Im(S₁₃), C = Im(S₂₃)$

source
SPEDAS.wavpolMethod
wavpol(X, fs=1; nfft=256, noverlap=div(nfft, 2), smooth_t=_smooth_t(nfft), smooth_f=hamming(3), nbuffers=Threads.nthreads())

Perform polarization analysis of n-component time series data.

For each FFT window (with specified overlap), the routine:

  1. Applies a time-domain window function and computes the FFT to construct the spectral matrix $S(f)$
  2. Applies frequency smoothing using a window function
  3. Computes wave parameters: power, degree of polarization, wave normal angle, ellipticity, and helicity

The analysis assumes the data are in a right-handed, field-aligned coordinate system (with Z along the ambient magnetic field).

Arguments

  • X: Matrix where each column is a component of the multivariate time series
  • fs: Sampling frequency (default: 1)

Keywords

  • nfft: Number of points for FFT (default: 256)
  • noverlap: Number of overlapping points between windows (default: nfft÷2)
  • smooth_t: Time domain window function (default: Hann window)
  • smooth_f: Frequency domain smoothing window (default: 3-point Hamming window)
  • nbuffers: Number of pre-allocated buffers for parallel processing (default: number of threads)

Returns

A named tuple containing:

  • indices: Time indices for each FFT window
  • freqs: Frequency array
  • power: Power spectral density, normalized by frequency bin width and window function
  • degpol: Degree of polarization [0,1]
  • waveangle: Wave normal angle [0,π/2]
  • ellipticity: Wave ellipticity [-1,1], negative for left-hand polarized
  • helicity: Wave helicity

See also: polarization, wave_normal_angle, wpol_helicity

source
SPEDAS.window_bf_sizesMethod
window_bf_sizes(window)

Converts a window specification to backward and forward window sizes.

When window is a positive integer scalar, the window is centered about the current element and contains window-1 neighboring elements. If window is even, then the window is centered about the current and previous elements.

source
SPEDAS.wpol_helicityMethod
wpol_helicity(S, waveangle)

Compute helicity and ellipticity for a single frequency.

Arguments

  • S: Spectral matrix for a single frequency, size (3,3)
  • waveangle: Wave normal angle for this frequency

Returns

  • helicity: Average helicity across the three components
  • ellipticity: Average ellipticity across the three components
source
SPEDAS.ΔφijMethod
Δφij(λᵢ, λⱼ, λ₃, M)

Calculate the phase error between components i and j according to: |Δφᵢⱼ| = |Δφⱼᵢ| = √(λ₃/(M-1) * (λᵢ + λⱼ - λ₃)/(λᵢ - λⱼ)²)

Parameters:

  • λᵢ: eigenvalue i
  • λⱼ: eigenvalue j
  • λ₃: smallest eigenvalue (λ₃)
  • M: number of samples
source
SPEDAS.ω2fMethod

Convert angular frequency to frequency

Reference: https://www.wikiwand.com/en/articles/Angular_frequency

source
SPEDAS.@load_project_configMacro
@load_project_config(file)

Load configuration from a file and export all key-value pairs as constants. The macro evaluates in the calling module's context.

source