pyrfu.pyrf#

Generic routines to build, transform and analyse space plasma time series: time series construction, time conversions, coordinate systems, signal processing, wave analysis, multi-spacecraft methods and plasma parameters.

from pyrfu import pyrf

Time series construction#

ts_scalar

Create a time series containing a 0th order tensor

ts_vec_xyz

Create a time series containing a 1st order tensor.

ts_tensor_xyz

Create a time series containing a 2nd order tensor.

ts_spectr

Create a time series containing a spectrum

ts_skymap

Creates a skymap of the distribution function.

ts_time

Creates time line in DataArray.

ts_append

Concatenate two time series along the time axis.

dist_append

Concatenate two distribution skymaps along the time axis.

Time series utilities#

time_clip

Time clip the input (if time interval is TSeries clip between start and stop).

resample

Resample inp to the time line of ref.

t_eval

Evaluates the input time series at the target time.

start

Gives the first time of the time series.

end

Gives the last time of the time series in unix format.

extend_tint

Extends time interval.

calc_dt

Compute time step of the input time series.

calc_fs

Computes the sampling frequency of the input time series.

find_closest

Finds pairs that are closest to each other in two time series.

remove_repeated_points

Remove repeated elements in DataArray, Dataset or structure data.

date_str

Creates a string corresponding to time interval for output plot naming.

Time format conversions#

cdfepoch2datetime64

Converts CDF epochs to numpy.datetime64 with nanosecond precision.

datetime2iso8601

Transforms datetime to TT2000 string format.

datetime642iso8601

Convert datetime64 in ns units to ISO 8601 time format .

datetime642ttns

Converts datetime64 to epoch_tt2000 (nanoseconds since J2000).

datetime642unix

Converts datetime64 in ns units to unix time.

iso86012datetime

Convert ISO 8601 time to datetime.

iso86012datetime64

Convert ISO8601 time format to datetime64 in ns units.

iso86012timevec

Convert ISO 8601 time string into time vector.

iso86012unix

Converts time in iso format to unix

timevec2iso8601

Convert time vector into ISO 8601 format YYYY-MM-DDThh:mm:ss.mmmuuunnn.

ttns2datetime64

Convert time in epoch_tt2000 (nanoseconds since J2000) to datetime64 in ns units.

unix2datetime64

Converts unix time to datetime64 in ns units.

Vector and tensor operations#

dot

Compute dot product of two fields.

cross

Compute cross product of two fields.

norm

Computes the magnitude of the input field.

normalize

Normalizes the input field.

trace

Computes trace of the time series of 2nd order tensors.

dec_par_perp

Decomposes a vector into par/perp to B components.

cart2sph

Cartesian to spherical coordinate transform.

cart2sph_ts

Computes magnitude, theta and phi angle from column vector xyz (first column is x ....) theta is 0 at equator.

sph2cart

Transform spherical to cartesian coordinates

solid_angle

Calculates the solid angle of three vectors making up a triangle in a unit sphere with the sign taken into account.

Coordinate systems#

cotrans

Coordinate transformation GE0/GEI/GSE/GSM/SM/MAG as described in [R93910b019a51-1]

gse2gsm

Converts GSE to GSM.

convert_fac

Transform to a field-aligned coordinate (FAC) system.

new_xyz

Transform the input field to the new frame.

mva

Compute the minimum variance frame.

mva_gui

GUI to interactively perform minimum variance analysis (MVA) on time series data by selecting the time interval to apply MVA on.

mean

Put inp into mean field coordinates defined by position vector r and magnetic field b if earth magnetic dipole axis z is given then uses another algorithm (good for auroral passages).

eb_nrf

Find E and B in MP system given B and MP normal vector.

l_shell

Compute spacecraft position L Shell for a dipole magnetic field according to IGRF.

Filtering and signal processing#

filt

Filters input quantity.

lowpass

Filter the data through low or highpass filter with max frequency f_cut and subtract from the original.

medfilt

Applies a median filter over npts points to inp.

movmean

Computes running average of the inp over window_size points.

mean_field

Estimate the mean and wave fields.

ts_convolve

Compute the convolution of a time series of N-dimensional data with a N-dimensional kernel.

integrate

Integrate time series.

gradient

Computes time derivative of the input variable.

sliding_derivative

Compute the sliding time derivative of a time series using central differences.

autocorr

Compute the autocorrelation function.

corr_deriv

Correlate the derivatives of two time series

Spectral and wave analysis#

psd

Estimate power spectral density using Welch's method.

wave_fft

Short-Time Fourier Transform.

wavelet

Computes wavelet spectrogram based on fast FFT algorithm.

compress_cwt

Compress the wavelet transform averaging over blocks of nc time steps.

ebsp

Calculates wavelet spectra of E&B and Poynting flux using wavelets (Morlet wavelet).

wavepolarize_means

Analysis the polarization of magnetic wave using "means" method

poynting_flux

Estimates Poynting flux at electric field sampling as

match_phibe_dir

Get propagation direction by matching dBpar and "phi".

match_phibe_v

Get propagation velocity by matching dBpar and phi.

Turbulence and intermittency#

increments

Returns the increments of a time series.

struct_func

Returns the structure function of a time series

pvi

Returns the Partial Variance of Increments (PVI) of a time series.

Multi-spacecraft methods#

avg_4sc

Computes the input quantity at the center of mass of the MMS tetrahedron.

nanavg_4sc

Average data from 4 spacecrafts while ignoring NaN values.

c_4_k

Calculates reciprocal vectors in barycentric coordinates.

c_4_grad

Calculate gradient of physical field using 4 spacecraft technique in [Ra4e11c05c7b9-2] [Ra4e11c05c7b9-3].

c_4_j

Calculate the current density using the four spacecraft technique.

c_4_v

Calculates velocity or time shift of discontinuity as in [Rb7b35f387832-6].

st_diff

Computes velocity of the structure using spatio-temporal derivative method [Rfdd5e57aa6d8-13] [Rfdd5e57aa6d8-14] as

pid_4sc

Compute Pi-D term using definition of [R8b551134d697-1] as :

pvi_4sc

Compute the Partial Variance of Increments (PVI) using the definition in [R64a80c2671ce-1] as

Plasma parameters#

plasma_calc

Computes plasma parameters including characteristic length and time scales.

iplasma_calc

Interactive function to calcute plasma paramters.

plasma_beta

Computes plasma beta at magnetic field sampling

dynamic_press

Computes dynamic pressure.

e_vxb

Computes the convection electric field \(V\times B\) (default) or the \(E\times B/|B|^{2}\) drift velocity (flag="exb").

edb

Compute Ez under assumption \(\mathbf{E}.\mathbf{B}=0\) or \(\mathbf{E}.\mathbf{B} \approx 0\)

vht

Estimate velocity of the De Hoffman-Teller frame from the velocity estimate the electric field eht=-vht x b

estimate

Estimate values for some everyday stuff.

Pressure tensor, anisotropy and agyrotropy#

pres_anis

Compute pressure anisotropy factor:

anisotropy_thresholds

Compute the thresholds for temperature anisotropy instabilities based on plasma species and growth rate.

calc_ag

Compute Che's agyrotropy coefficient.

calc_agyro

Compute agyrotropy coefficient as

calc_dng

Computes Aunai's agyrotropy coefficient.

calc_sqrtq

Computes agyrotropy coefficient as in [R397062005517-1]

Velocity distribution functions#

average_vdf

Time averages the velocity distribution functions over n_pts in time.

int_sph_dist

Integrate a spherical distribution function to a line/plane.

Shocks and boundaries#

shock_normal

Calculates shock normals with different methods.

shock_parameters

Calculate shock related plasma parameters.

magnetosphere

Returns the location of magnetopause.

Statistics and histograms#

histogram

Computes 1D histogram of the inp with bins bins

histogram2d

Computes 2d histogram of inp2 vs inp1 with nbins number of bins.

brazil

Computes 2D histogram and PDF (Brazil plot style) for plasma data.

mean_bins

Computes mean of values of y corresponding to bins of x.

median_bins

Computes median of values of y corresponding to bins of x

optimize_nbins_1d

Estimates the number of bins for 1d histogram that minimizes the risk function in [R10e5c351ffb9-1] , obtained by direct decomposition of the MISE following the method described in [R10e5c351ffb9-2] .

optimize_nbins_2d

Estimates the number of bins for 2d histogram that minimizes the risk function in [R0adc3d7e4a0c-1] , obtained by direct decomposition of the MISE following the method described in [R0adc3d7e4a0c-2] .

waverage

Computes weighted average.

Data files and external data#

read_cdf

Reads a .cdf file and returns a dictionary with the fields contained in the file.

get_omni_data

Downloads OMNI data.