pyrfu#

Space plasma physics in Python

pyrfu is an open-source package for in-situ space plasma data analysis, based on the IRFU-MATLAB library. It covers the Magnetospheric Multiscale (MMS) mission from data access to particle distributions and wave analysis, and general plasma physics tools.

$ python -m pip install pyrfu
Wavelet spectra of the magnetic and electric fields and wave ellipticity computed with pyrfu from MMS burst data.

PyPI version Supported Python versions Continuous integration DOI MIT license

What you can do with pyrfu#

MMS data access

Find, download and load MMS data from a local archive, the SDC or AWS in one call, as xarray time series.

Loading data
Particle distributions

FPI skymaps: omni-directional and pitch-angle distributions, projections, reduced 1D and 2D distributions and moments.

FPI particle distributions
Waves and polarization

Wavelet and Fourier spectra, polarization analysis, Poynting flux and four-spacecraft dispersion relations.

Spectral and wave analysis
Multi-spacecraft methods

Curlometer current density, gradients, timing velocities and four-spacecraft averages.

Multi-spacecraft methods
Coordinates and time series

Geophysical coordinate transformations, field-aligned and minimum variance frames, filtering and resampling.

Coordinate systems
Plotting

Publication-ready time series, spectrograms and particle distribution plots with matplotlib.

pyrfu.plot

Quickstart#

import matplotlib.pyplot as plt
from pyrfu import mms, pyrf
from pyrfu.plot import plot_line

# Path to the MMS data
mms.db_init(default="local", local="/Volumes/mms")

# Load the magnetic field and the ion bulk velocity
tint = ["2019-09-14T07:54:00.000", "2019-09-14T08:11:00.000"]
b_gsm = mms.get_data("b_gsm_fgm_srvy_l2", tint, 1)
v_gse_i = mms.get_data("vi_gse_fpi_fast_l2", tint, 1)

# Transform the ion bulk velocity to GSM coordinates
v_gsm_i = pyrf.cotrans(v_gse_i, "gse>gsm")

f, axs = plt.subplots(2, sharex="all")
plot_line(axs[0], b_gsm)
plot_line(axs[1], v_gsm_i)

More in the examples gallery.

Documentation#

Installation

Install from PyPI or from the sources.

Installation
Examples

Notebooks for MMS, dispersion relations and more.

Examples
API reference

Every function, grouped by topic.

API reference
Contributing

Code style, tests and how to contribute.

Contributing

Citing pyrfu#

If you use pyrfu in your research, please cite it using its Zenodo DOI 10.5281/zenodo.10678695 (the Zenodo page also lists the DOI of each release):

@software{richard2024pyrfu,
  author    = {Richard, Louis and Khotyaintsev, Yuri V. and Vaivads, Andris and
               Graham, Daniel B. and Norgren, Cecilia and Johlander, Andreas},
  title     = {Python RymdFysik Utilities (PyRFU): An Open-Source Python Package
               for Advanced In-Situ Space Plasma Analysis},
  year      = {2024},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.10678695},
  url       = {https://doi.org/10.5281/zenodo.10678695}
}

pyrfu was developed at the Swedish Institute of Space Physics (IRF) in Uppsala, building on the IRFU-MATLAB library, and is now maintained at the Rudolf Peierls Centre for Theoretical Physics, University of Oxford. It is distributed under the MIT license.