Getting Started with pySPEDAS: Difference between revisions

From SPEDAS Wiki
Jump to navigation Jump to search
No edit summary
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Welcome to pySPEDAS ==
== Welcome to pySPEDAS ==


pySPEDAS is the SPEDAS software in the python programming language. It is currently in development (beta).  
pySPEDAS is an implementation of the SPEDAS framework in Python.


Examples and tutorials can be found in the companion projects:
=== Requirements ===
pyspedas_examples
* Python 3.7 and later (as of pySPEDAS v1.2)
mms_examples


== pySPEDAS releases ==
* [https://github.com/spedas/pyspedas GitHub (bleeding edge and major releases)]
* [https://pypi.org/project/pyspedas/ PyPI (latest stable release)]
== Installing Python ==
We suggest that you install Python using the Anaconda distribution; step-by-step instructions for installing Anaconda can be found at:
* macOS: https://docs.anaconda.com/anaconda/install/mac-os/
* Windows: https://docs.anaconda.com/anaconda/install/windows/
* Linux: https://docs.anaconda.com/anaconda/install/linux/
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.


== pySPEDAS releases ==
== 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:
 
<syntaxhighlight lang="cmd">
python -m venv pyspedas
</syntaxhighlight>
 
And enter into that virtual environment by running the 'activate' script with:
 
=== macOS and Linux ===
<syntaxhighlight lang="cmd">
source pyspedas/bin/activate
</syntaxhighlight>
 
=== Windows ===
<syntaxhighlight lang="cmd">
.\pyspedas\Scripts\activate
</syntaxhighlight>
 
== Installing pySPEDAS ==
 
The first time you enter your virtual environment, you’ll have to install pyspedas; this is as simple as:
 
<syntaxhighlight lang="cmd">
pip install pyspedas
</syntaxhighlight>
 
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:


* [https://github.com/spedas/pyspedas github source code]
<syntaxhighlight lang="cmd">
* [https://pypi.org/project/pyspedas/ pip release]
pip install pyspedas --upgrade
* [https://anaconda.org/spedas/pyspedas conda release]
</syntaxhighlight>


== Setting your local data directory ==


== Install pySPEDAS ==
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).


An easy way to install pyspedas is to install the latest Anaconda distribution:
Mission specific data directories (e.g., 'MMS_DATA_DIR') can also be set, and these will override 'SPEDAS_DATA_DIR'


* https://www.anaconda.com/distribution/
=== Network mirror for the MMS dataset ===


If you have a mirror of the MMS dataset on your local network, you may want to set the MMS_MIRROR_DATA_DIR environment variable.


Then, open the anaconda prompt and type:
If set, when you use the no_update keyword in the load routines (or if don’t have an internet connection), the load routines will check the mirror for data. Just as in IDL, data files found on the network mirror will be copied to your local data directory before loading them.


<pre>conda install -c spedas pyspedas</pre>
== Checking that everything is working ==


This will install all required files. To test the installation, you can open a command prompt, type 'python' to start the python interpreter and then type:
The quickest way to check if everything is working is to load some data; once you’re inside Python in your virtual environment, try:


<pre>
<syntaxhighlight lang="python">
import pyspedas
import pyspedas
pyspedas.version()
pyspedas.mms.fgm()
</pre>
</syntaxhighlight>


The installed version of pyspedas should be printed.
This should load some default data (srvy mode, probe 1) for Oct 16, 2015. You can then plot the FGM data with:


<syntaxhighlight lang="python">
from pytplot import tplot
tplot('mms1_fgm_b_gse_srvy_l2')
</syntaxhighlight>


You can also install pyspedas using pip:
== Using Jupyter notebooks with your virtual environment ==


<pre>pip install pyspedas</pre>
To get virtual environments working with Jupyter, there are a few extra steps:


in the virtual environment, type:


== Examples ==
<syntaxhighlight lang="cmd">
pip install ipykernel
python -m ipykernel install --user --name pyspedas --display-name "Python (pySPEDAS)"
</syntaxhighlight>


There are two projects that contain examples of using 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)"


* [https://github.com/spedas/mms-examples github source code for mms-examples]
== Examples ==
* [https://github.com/spedas/pyspedas_examples github source code for pyspedas_examples]


These can be installed using conda or pip:
There are two repositories that contain examples of using pyspedas:


<pre>
MMS Examples
conda install -c spedas pyspedas_examples
* [https://github.com/spedas/mms-examples Jupyter notebooks containing MMS examples]
</pre>


or
Examples for other missions and general webinars
* [https://github.com/spedas/pyspedas_examples Jupyter notebooks containing pySPEDAS examples]


<pre>
You can also browse the README.md files using GitHub for more information and examples, e.g.,
pip install pyspedas_examples
</pre>


* [https://github.com/spedas/pyspedas/blob/master/pyspedas/mms/README.md MMS README.md file]


== Comparison of pySPEDAS to SPEDAS ==
== Comparison of pySPEDAS to SPEDAS ==
Line 69: Line 122:
* [[Spectrogram]]
* [[Spectrogram]]
* [[Wavelet]]
* [[Wavelet]]
* [[Cotrans]]

Revision as of 23:10, 18 May 2021

Welcome to pySPEDAS

pySPEDAS is an implementation of the SPEDAS framework in Python.

Requirements

  • 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:

<syntaxhighlight lang="cmd"> python -m venv pyspedas </syntaxhighlight>

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

macOS and Linux

<syntaxhighlight lang="cmd"> source pyspedas/bin/activate </syntaxhighlight>

Windows

<syntaxhighlight lang="cmd"> .\pyspedas\Scripts\activate </syntaxhighlight>

Installing pySPEDAS

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

<syntaxhighlight lang="cmd"> pip install pyspedas </syntaxhighlight>

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:

<syntaxhighlight lang="cmd"> pip install pyspedas --upgrade </syntaxhighlight>

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'

Network mirror for the MMS dataset

If you have a mirror of the MMS dataset on your local network, you may want to set the MMS_MIRROR_DATA_DIR environment variable.

If set, when you use the no_update keyword in the load routines (or if don’t have an internet connection), the load routines will check the mirror for data. Just as in IDL, data files found on the network mirror will be copied to your local data directory before loading them.

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:

<syntaxhighlight lang="python"> import pyspedas pyspedas.mms.fgm() </syntaxhighlight>

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

<syntaxhighlight lang="python"> from pytplot import tplot tplot('mms1_fgm_b_gse_srvy_l2') </syntaxhighlight>

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:

<syntaxhighlight lang="cmd"> pip install ipykernel python -m ipykernel install --user --name pyspedas --display-name "Python (pySPEDAS)" </syntaxhighlight>

(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)"

Examples

There are two repositories that contain examples of using pyspedas:

MMS Examples

Examples for other missions and general webinars

You can also browse the README.md files using GitHub for more information and examples, e.g.,

Comparison of pySPEDAS to SPEDAS

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