Monday, April 13, 2020

Running ObsPy in Jupyter Notebooks


Following the guide at

https://seismo.berkeley.edu/wiki_cider/images/1/10/Waite_cider_2019_tutorial.pdf


one sets up the ObsPy environment in Anaconda with the packages needed to make the notebooks go.

To review, setting up the ObsPy environment may have been done already, but if not, FIRST run these commands in a terminal window:

conda config --add channels conda-forge


• The above command sets conda to install packages from a certain place (conda-forge.org). The next command creates an environment called obspy (but you can call it just about anything) with python version 3.7.

conda create -n obspy python=3.7

• Next you will activate that newly created environment, in my installation I use "source" rather than "conda" for the activate command


source activate obspy

• You will notice that the command line prompt now has the name of the environment in parentheses (obspy). Now install obspy, and all the packages it depends on:


conda install obspy

conda will look for the obspy package at conda-forge, download it, and install it. You will be prompted a couple times for confirmation of download/install.

You have installed the obspy package, but there are a few more things that are useful to add. This one adds functionality to jupyter notebook to allow for environment switching

conda install nb_conda

• This should already be installed, but check.  In my case I had already installed basemap in my obspy environment

conda install basemap

• This adds more plotting functions.

conda install ipympl

• And, finally

 conda install jupyter


Using jupyter notebook

• Jupyter notebook is a web-browser tool that allows you to create python scripts and run then in an interactive mode. It a bit easier to use than the command line in python so lets move to that
  1. open terminal/xterm (osx or linux)
  2. activate the obspy environment on the command line
  3. then start jupyter notebook from the command line
  4. This will open a new browser window with the jupyter notebook
Now you can create a new notebook or an existing one (they have file extensions (.ipynb for ipython notebook)

cd Desktop/RData/ObsPy
source activate obspy
jupyter notebook

At this point you can cut and paste python commands into the notebook boxes and execute them one by one.  The notebook can be saved as an *.ipynb file for later use.  Be careful which directory you are in, or else you will be storing notebook files in your home directory.

 
Link