Skip to content

About

Analysis tools for particle velocity distribution functions (VDFs)

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

95 Commits

Folders and files

Repository files navigation

VelocityDistributionFunctions

DOI

Analysis tools for particle velocity distribution functions (VDFs).

Installation: at the Julia REPL, run using Pkg; Pkg.add("VelocityDistributionFunctions")

Quickstart

using VelocityDistributionFunctions

energy = exp10.(range(1, 4; length = 32))  # eV
phi = 11.25:22.5:360                       # deg
theta = 11.25:22.5:180                     # deg
data = rand(32, 16, 8)                     # one scan: data[energy, phi, theta] in :eflux; any axis order, named by the grid
grid = EnergyAngleBins(:energy => energy, :phi => phi, :theta => theta)
B = [1.0, 0.0, 0.0]

pad = angle_distribution(data, grid, :pitch; B, bins = 18)                   # pad.data[pitch, energy]
spec = omni_spectrum(data, grid)                                             # spec[energy]
dirs = directional_spectra(pad.data, pad.centers, 30)                        # dirs.para[energy], ...
m = plasma_moments(data, grid; species = :e, units = :eflux, B)              # m.density, m.magt3, ...
psd = convert_flux_units(data, grid, :eflux => :df_cm; species = :e)
gv = gyroaverage(data, grid, :v_perp => 0:1e6:3e7, :v_para => -3e7:1e6:3e7; species = :e, units = :eflux, B)  # gv.data[v_perp, v_para]

series = rand(32, 16, 8, 100)              # series[energy, phi, theta, time]
ms = plasma_moments(eachslice(series; dims = 4), grid; species = :e, units = :eflux)  # ms.density[time]

The MMS ion moments example adapts instrument data with scan-varying tables and cross-validates against PySPEDAS.

Conventions

  • Angles are in degrees and give the particle velocity direction in physics spherical coordinates: θ is the polar angle from ẑ (0–180°), φ the azimuth from x̂ (0–360°). Instrument look directions (φ_look, θ_look) convert as φ = mod(φ_look + 180, 360), θ = 180 - θ_look.
  • A series is a vector of scans, e.g. eachslice(data; dims) along the time axis dims. Per-scan outputs are stacked with time last; bin edges and centers are shared.
  • In a series, other inputs are shared or given as a vector with one entry per scan: a vector of EnergyAngleBins for varying geometry, eachcol(pa) for pitch centers pa[pitch, time]. When supplied, B, gyro_ref and frame velocity u each take one three-component vector per scan.
  • method = :mean is the solid-angle-weighted mean; :sum the plain sum, for counts.
  • Non-finite values (e.g. NaN for dead or fill bins) are skipped; a bin, group or scan without finite values gives NaN. Set bins to NaN to exclude them, e.g. data[energy .< 10, :, :] .= NaN drops photoelectrons below 10 eV.
  • plasma_moments returns SI with temperatures in eV; gyroaverage returns SI phase-space density.
  • units of data: :eflux [eV/(cm²·s·sr·eV)], :flux [1/(cm²·s·sr·eV)], :df_cm [s³/cm⁶], :df_km [s³/km⁶], :df_m [s³/m⁶].
  • species: :H, :He (α), :O (¹⁶O⁺), :e, or a PlasmaPopulations.jl Particle.

API

name meaning
EnergyAngleBins(axes...; denergy, dphi, dtheta) energy [eV] and velocity-direction (phi, theta [deg]) bin centers and widths. Each argument names a data axis, in order: name => values, or (names...) => (values...) for coordinates sharing one axis (e.g. a flat list of directions). A vector lies along its axis; other arrays broadcast against the data. An angle without an axis spans its full range, e.g. gyrotropic EnergyAngleBins(:theta => pitch, :energy => E) with B = [0, 0, 1]. Cells span θ ± dθ/2, φ ± dφ/2 within θ ∈ [0, 180]; uncovered directions count as empty. Missing widths are estimated from centers on an axis of their own. A bare :energy is an energy axis without values (not for moments)
angle_distribution(data, grid, coord; B, gyro_ref, bins = 12, method = :mean) the mean of data over the cells whose center direction falls in each coord bin, as (; data[bin(, energy)], solid_angle, edges, centers); solid_angle [sr] sums the finite cells of each bin. coord is :pitch (needs B), :gyrophase (needs B and gyro_ref; 0° along the perpendicular projection of gyro_ref, 90° along B × gyro_ref), :phi or :theta; bins is a count or edges [deg]
gyroaverage(data, grid, c1 => bins1, c2 => bins2; species, units, B, u = nothing, sc_pot = 0, oversample = 1) gyrotropic PSD on (:v_perp, :v_para), or a pitch-angle distribution with :pitch and either :energy or :speed. Argument order sets the axes of data and volume. Use u = m.velocity for the plasma frame. Returns (; data, volume, edges, centers); see the docstring for bin coverage and integration
omni_spectrum(data, grid; method = :mean) the mean of data over all directions, [energy] or a number without energies
directional_spectra(S, pitch_angles, loss_cone; half_sector_width, para_tol = 0, perp_tol = 0, method = :mean) omni, parallel, antiparallel and perpendicular means (; omni, para, anti, perp) of S[pitch, rest...] over pitch, e.g. energy spectra; numbers for S[pitch]. half_sector_width [deg] is half the pitch width, estimated from the centers by default
group_mean(data, groups; dims, weights = nothing) mean of data over each group along axis dims, weighted by weights (e.g. channel widths); dims becomes a group axis. groups are index ranges (e.g. [1:3, 4:6]) or values => edges, e.g. energy bands E => [1e3, 1e4, 3e4] with E per scan in a series
plasma_moments(data, grid; species, units, sc_pot = 0, B = nothing) moments as a NamedTuple for one scan or a StructArray for a series, vectors and tensors in the frame of the angles: density [m⁻³], velocity, vthermal [m/s], flux [m⁻² s⁻¹], eflux and plasma-frame heat flux qflux [W/m²], 3×3 mftens, ptens [Pa] and ttens [eV], avgtemp, eigenvalues t3 [eV]. sc_pot [V] gives energies at infinity E + charge * sc_pot (charge in e); bins pushed below zero drop out. B adds magt3 [eV] along (velocity ⊥ B, B × velocity, B) and the temperature symmetry axis symm with symm_theta, symm_phi, symm_ang [deg]. Agyrotropy: PlasmaPopulations.agyrotropy(m.ptens, B)
convert_flux_units(data, grid_or_energy, from => to; species = nothing) data converted between units, with energies from an EnergyAngleBins or an array [eV] that broadcasts against data; species is required between flux and phase-space density

Elsewhere

About

Analysis tools for particle velocity distribution functions (VDFs)

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages