GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - SciQLop/speasy: Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)

BranchesTags
Open more actions menu

Latest commit

 

History

1,480 Commits
1,480 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
README_files
README_files
 
 
docs
docs
 
 
logo
logo
 
 
plan
plan
 
 
scripts
scripts
 
 
speasy
speasy
 
 
tests
tests
 
 
.coveragerc
.coveragerc
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.readthedocs.yaml
.readthedocs.yaml
 
 
AUTHORS.rst
AUTHORS.rst
 
 
CITATION.cff
CITATION.cff
 
 
CLAUDE.md
CLAUDE.md
 
 
CONTRIBUTING.rst
CONTRIBUTING.rst
 
 
HISTORY.rst
HISTORY.rst
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
codecov.yml
codecov.yml
 
 
environment.yml
environment.yml
 
 
lgtm.yml
lgtm.yml
 
 
pyproject.toml
pyproject.toml
 
 
pytest.ini
pytest.ini
 
 
uv.lock
uv.lock
 
 

Repository files navigation

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

  • Tell us how you use Speasy in our user survey.
  • Report bugs or request features in the issues.
  • Ask questions in the discussions or on Matrix.
  • Want to add a data provider? See the contributing guide.

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.

About

Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)

Topics

amdacdawebcnesesanasa-apiplasma-physicspnstpyhcpython-3python3sciqlopspace-physicsspace-plasmasscwebwebservices

Resources

Readme
MIT license

Contributing

Contributing
Activity
Custom properties

Stars

37 stars

Watchers

5 watching

Forks

12 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.