Skip to main content

Space Physics made EASY: one function for in-situ space physics data.

PyPI Tests Documentation DOI Chat on Matrix Try on MyBinder

import speasy as spz
ace_mag = spz.get_data("amda/imf", "2016-6-2", "2016-6-5")
ace_mag.plot();

ACE interplanetary magnetic field

That's it. Three lines, and you have three days of ACE magnetic field data, with time, units and labels. The same call works for tens of thousands of products from many data centers.

Many data sources, one get_data(product, start, stop) call, one SpeasyVariable that converts to numpy, pandas, xarray and astropy

Why Speasy

  • One call for many archives. AMDA, CDAWeb, ESA's Cluster Science Archive, SSCWeb, CDPP 3DView, the U. Iowa ephemeris tool, every server of the HAPI server list, and your own archives described in a YAML file. See the data providers page.
  • Find data by tab-completion. Browse spz.inventories.tree.<provider> in IPython or Jupyter, down to each product.
  • Fast on the second request. Data is cached on your disk, and a community cache server speeds up the first one.
  • Reproducible studies. A DataIndex keeps exactly the data a study used. It never expires, works offline, and exports as a single file to share with a colleague.
  • Fits the tools you already use. Numpy functions work directly on Speasy variables, and they convert to pandas, xarray and astropy.
  • Your own products. Register a Python function as a virtual product, and use it like any other product.
  • Also from the shell, and from Julia. A speasy command downloads, converts and pre-fetches data. Speasy.jl brings the same API to Julia.

Prefer clicking to coding? SciQLop is a graphical interface built on Speasy.

Installation

Speasy needs Python 3.10 or newer:

$ python -m pip install speasy

Or try the command line without installing anything, with uv:

$ uvx speasy get amda/imf 2018-06-01 2018-06-02

The first request for some data needs internet access; after that, it comes from the local cache. Behind a proxy or a firewall? See the configuration page.

Examples

Browse instead of typing ids

Every provider is a tree you can explore with tab-completion. This is the same product as above:

import speasy as spz
amda_tree = spz.inventories.data_tree.amda
ace_mag = spz.get_data(amda_tree.Parameters.ACE.MFI.ace_imf_all.imf, "2016-6-2", "2016-6-5")

Any HAPI server

The Dst index during the May 2024 geomagnetic storm, from the World Data Center in Kyoto:

import speasy as spz
dst = spz.get_data("hapi/wdc_kyoto_hapi/hour_dst/dstValue", "2024-05-09", "2024-05-14")
dst.plot();

Dst index, May 2024 storm

Several instruments on one figure

Magnetic field, electron and ion data from MMS1, on a shared time axis:

import speasy as spz
import matplotlib.pyplot as plt

mms1 = spz.inventories.tree.cda.MMS.MMS1
fig = plt.figure(figsize=(8, 16), layout="constrained")
axes = fig.add_gridspec(6, hspace=0).subplots(sharex=True)

plots = [
    (mms1.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gse_srvy_l2_clean, axes[0]),
    (mms1.SCM.MMS1_SCM_SRVY_L2_SCSRVY.mms1_scm_acb_gse_scsrvy_srvy_l2, axes[1]),
    (mms1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_bulkv_gse_fast, axes[2]),
    (mms1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_temppara_fast, axes[3]),
    (mms1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_tempperp_fast, axes[3]),
    (mms1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_energyspectr_omni_fast, axes[4]),
    (mms1.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_energyspectr_omni_fast, axes[5]),
]

for product, ax in plots:
    spz.get_data(product, "2019-01-02T15", "2019-01-02T22").replace_fillval_by_nan().plot(ax=ax)

MMS1 multiple time series

Many products, many intervals, one call

The result holds one list per product, with one variable per interval:

import speasy as spz
products = [
    spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_vth,
    spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_pdyn,
    spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_n,
    spz.inventories.tree.cda.Wind.WIND.MFI.WI_H2_MFI.BGSE,
    spz.inventories.tree.ssc.Trajectories.wind,
]
intervals = [["2010-01-02", "2010-01-02T10"], ["2009-08-02", "2009-08-02T10"]]
data = spz.get_data(products, intervals)

Numpy works directly

Compute the field magnitude yourself, and check it against the one MMS provides:

import speasy as spz
import numpy as np
mms1 = spz.inventories.tree.cda.MMS.MMS1
b = spz.get_data(mms1.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gsm_srvy_l2, "2017-01-01T02:00:00", "2017-01-01T02:00:15")
b.replace_fillval_by_nan(inplace=True)
bt = b["Bt"]
b = b["Bx GSM", "By GSM", "Bz GSM"]
computed_norm = np.sqrt(np.sum(b ** 2, axis=1))
print(f"Type of computed_norm: {type(computed_norm)}")
print("Same as the provided magnitude?", bool(np.allclose(computed_norm, bt)))

Type of computed_norm: <class 'speasy.products.variable.SpeasyVariable'> Same as the provided magnitude? True

Convert to pandas, xarray or astropy

import speasy as spz
ace_mag = spz.get_data("amda/imf", "2016-6-2", "2016-6-5")
print(type(ace_mag.to_dataframe()).__name__)
print(type(ace_mag.to_dataarray()).__name__)
print(type(ace_mag.to_astropy_table()).__name__)

DataFrame DataArray Table

Resample one product onto another

Interpolate ion temperatures onto the magnetic field timestamps:

import speasy as spz
from speasy.signal.resampling import interpolate
import matplotlib.pyplot as plt
mms1 = spz.inventories.tree.cda.MMS.MMS1

b, Tperp, Tpara = spz.get_data(
    [
        mms1.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gsm_srvy_l2,
        mms1.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_tempperp_fast,
        mms1.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_temppara_fast,
    ],
    "2017-01-01T02:00:00",
    "2017-01-01T02:00:15",
)

Tperp_interp, Tpara_interp = interpolate(b, [Tperp, Tpara])

plt.figure()
ax = b.plot()
plt.plot(Tperp_interp.time, Tperp_interp.values, marker="+")
plt.plot(Tpara_interp.time, Tpara_interp.values, marker="+")
plt.tight_layout()

Resampling

Your own products

A virtual product is a Python function that Speasy serves like any other product:

import numpy as np
import speasy as spz
from speasy.virtual_products import register_virtual_product

@register_virtual_product("virtual/ace/b_magnitude", meta={"units": "nT"}, labels=["|B|"])
def ace_b_magnitude(start, stop):
    b = spz.get_data("amda/imf", start, stop)
    return np.sqrt(np.sum(b ** 2, axis=1))

spz.get_data("virtual/ace/b_magnitude", "2016-6-2", "2016-6-5").plot();

ACE field magnitude, from a virtual product

Keep a study's data

Inside a DataIndex block, get_data stores what it downloads in a folder. Next time, the same calls are served from that folder, even offline. Export it as one file, and a colleague gets exactly the same data:

import speasy as spz

with spz.DataIndex("my_study") as study:
    ace_mag = spz.get_data("amda/imf", "2016-6-2", "2016-6-5")  # downloaded, kept in my_study/
study.export_data("my_study.tar")                                # one file to send

# On your colleague's machine:
with spz.DataIndex("their_copy") as copy:
    copy.import_data("my_study.tar")
    ace_mag = spz.get_data("amda/imf", "2016-6-2", "2016-6-5")  # read from their_copy/, no download

Documentation

The documentation covers each data provider, configuration, the command line, and has a gallery of examples. Speasy's plots are meant for quick looks; for publication figures, use Matplotlib directly, or SciQLop for interactive exploration.

Help us improve Speasy

Citing Speasy

If Speasy helped your research, please cite it. GitHub's "Cite this repository" button, on the right of this page, gives a ready-made reference from CITATION.cff. Every release also has a Zenodo DOI.

Thanks

Speasy only exists thanks to the data centers and teams who produce, archive and serve the data, and to the HAPI community for a shared standard. The development of Speasy is supported by the CDPP.

Metadata

Release files for speasy 1.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speasy 1.10.0
File Size Uploaded Provenance Actions
speasy-1.10.0.tar.gz 13.3 MB Without provenance Details for speasy-1.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for speasy 1.10.0
File Interpreter ABI Platform Actions
speasy-1.10.0-py3-none-any.whl Python 3 none any Details for speasy-1.10.0-py3-none-any.whl

Total release size: 13.6 MB

Release files / speasy-1.10.0.tar.gz

Download URL speasy-1.10.0.tar.gz
Size 13.3 MB
Tags Source
SHA-256 checksum
How to use checksums
a4e3054a3509effc03a92a4293f1a3327d521b056fd0ecad18ad2fe24fcf4799
BLAKE2b-256 checksum
How to use checksums
bab611a41080de745f7e183293e4e777c2fa9aaf0cb8f40c7885f84147214003
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / speasy-1.10.0-py3-none-any.whl

Download URL speasy-1.10.0-py3-none-any.whl
Size 270.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
632f77efad9feb410e0a435846b5254d0d98e810c1d75447604c472ba25eeefd
BLAKE2b-256 checksum
How to use checksums
11feba22b9e3504d546f68d1886461935949c6abb06844a6816501665b1d041e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for speasy 1.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.10.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page