Python is an interpreted, high-level, general-purpose programming language. It is FREE and OPEN-SOURCE! Unlike MATLAB, the basic Python libraries have limited capability for scientific research. Seismologists need extra open-source Python libraries (e.g. numpy, scipy, matplotlib) for data analysis and plotting.
NumPy: a library for large, multi-dimensinal arrays and matrices, required by any scientific research
SciPy: a library for scientific computing, requiring NumPy, required by any scientific research
Matplotlib: a library for plotting
Pandas: a library for data structures and data analysis
ObsPy: a project specifically for processing seismic data
macOS and most Linux distributions have their own pre-installed Python, it's highly recommended to install the Anaconda distribution in your HOME directory.
Anaconda is a FREE and OPEN-SOURCE distribution of the Python languages, designed for scientific computing that aims to simplify package installation and management.
With anaconda installed, you will have full control of your Python and installed packages, avoid the risk messing up your operation system, and have more than 1000 popular Python packages available.
To install Anaconda on your own PC, please refer to the official installation guide on macOS, Windows, and Linux.
After installing Anaconda, you may want to remove "base" before your terminal prompt. Add an extra line to your .condarc file (usually in ~/):
changeps1: False
The installed Anaconda in /opt/software does not work. You need to install your own Anaconda so you can control your python version and packages. Please refer to https://wiki.hpcc.msu.edu/display/ITH/Using+conda for more details.
After successfully installing Anaconda, you need to change the environment:
Run conda create --name HPCCPy python=3.7 to create an isolated environment in your HOME directory. In my case, the environment name is HPCCPy, and the Python version is 3.7. You can change it to other names and versions.
Add following line to your ~/.bashrc file, then you're almost set. Remember to log out and then login again to check if it works.
module unload Python
export PATH=${PATH}:/opt/software/Anaconda3/4.2.0/bin
source activate HPCCPy
There are several ways to install Python packages. The most convenient ways are conda and pip. If you want to install Python package, it's recommended to check if it's available from conda. If not, then you can pip.
conda is the package manager provide d by Anaconda:
# Search packages
conda search numpy
# Install packages
conda install numpy
pip is the built-in package manager of Python:
# Search packages
pip install numpy
# Install pacakges
pip install numpy
Run following commands to install some most commonly used packages for scientific computing:
conda install ipython numpy scipy matplotlib pandas
conda install obspy --channel conda-forge
The official Python Tutorial: https://docs.python.org/3/tutorial
Scipy Lecture Notes: http://scipy-lectures.org/
A Visual Intro to NumPy and Data Representation: https://jalammar.github.io/visual-numpy/
Here are some catalogs of earthquakes in Tonga, relocated by Wei et al. [2019, Science Adv.]: (python-traning.zip)
4 of them (ISClauraw?.lst) include more than 700 earthquakes that were recorded by local seismic stations and relocated by Antelope (a seismic software). 'ISCid.lst' is an ISC catalog that should include most of these earthquakes. Generally speaking, we think the local catalogs (ISClauraw?.lst) should provide better hypocenters as the earthquakes are constrained by local stations. On the other hand, the ISC catalog assigns each earthquake a unique ID which has a broader usage. Please write a Python script to associate these catalogs, i.e., create a new catalog in which each earthquake has a high-precision hypocenter from the local catalogs and a unique ISC ID. 'assISCid.py' serves as a reference, but probably doesn't work well. You can digest this Python script and write your own.
Reference: Wei, S. S., D. A. Wiens, P. E. van Keken, and C. Cai (2017), Slab temperature controls on the Tonga double seismic zone and slab mantle dehydration, Science Adv., 3, e1601755, doi: 10.1126/sciadv.1601755.