Difference between revisions of "Getting Started with pySPEDAS"

From SPEDAS Wiki
Jump to navigation Jump to search
Line 34: Line 34:
=== macOS and Linux ===
=== macOS and Linux ===
<syntaxhighlight lang="cmd">
<syntaxhighlight lang="cmd">
source environment-name/bin/activate
source pyspedas/bin/activate
=== Windows ===
=== Windows ===
<syntaxhighlight lang="cmd">
<syntaxhighlight lang="cmd">

Revision as of 23:01, 18 May 2021

Welcome to pySPEDAS

pySPEDAS is an implementation of the SPEDAS framework in Python.


  • Python 3.7 and later (as of pySPEDAS v1.2)

pySPEDAS releases

Installing Python

We suggest that you install Python using the Anaconda distribution; step-by-step instructions for installing Anaconda can be found at:

Once Anaconda is installed, you should be able to open Python in your terminal window by typing "python". Note: your Python version will be the first line displayed; Python 3.7 or later is required.

Creating a virtual environment

To avoid potential dependency issues with other Python packages, it’s best to create a virtual environment in Python

You can create a virtual environment in your terminal with:

python -m venv pyspedas

And enter into that virtual environment by running the 'activate' script with:

macOS and Linux

source pyspedas/bin/activate



Installing pySPEDAS

The first time you enter your virtual environment, you’ll have to install pyspedas; this is as simple as:

pip install pyspedas

This should go out and find all of the required libraries and install them inside the virtual environment.

If you would like to upgrade your copy of the pySPEDAS libraries inside of your virtual environment, use:

pip install pyspedas --upgrade

Setting your local data directory

The recommended way of setting your local data directory is to set the 'SPEDAS_DATA_DIR' environment variable. 'SPEDAS_DATA_DIR' acts as a root data directory for all missions, and will also be used by IDL (if you’re running a recent copy of the bleeding edge).

Mission specific data directories (e.g., 'MMS_DATA_DIR') can also be set, and these will override 'SPEDAS_DATA_DIR'

Checking that everything is working

The quickest way to check if everything is working is to load some data; once you’re inside Python in your virtual environment, try:

import pyspedas

This should load some default data (srvy mode, probe 1) for Oct 16, 2015. You can then plot the FGM data with:

from pytplot import tplot

Using Jupyter notebooks with your virtual environment

To get virtual environments working with Jupyter, there are a few extra steps:

in the virtual environment, type:

pip install ipykernel
python -m ipykernel install --user --name pyspedas --display-name "Python (pySPEDAS)"

(note: "pyspedas" is the name of your virtual environment)

Then once you open the notebook, go to "Kernel" then "Change kernel" and select the one named "Python (pySPEDAS)"


There are two projects that contain examples of using pyspedas:

MMS Examples

Examples for other missions and general webinars

Comparison of pySPEDAS to SPEDAS

Some examples that demonstrate how to achieve the same results using either IDL SPEDAS or python pySPEDAS.