1. ObsPy是什么?

ObsPy is an open-source project dedicated to provide a Python framework for processing seismological data. It provides parsers for common file formats, clients to access data centers and seismological signal processing routines which allow the manipulation of seismological time series.

The goal of the ObsPy project is to facilitate rapid application development for seismology.

2. ObsPy安装

推荐阅读:利用 Anaconda 安装 ObsPy.

测试是否安装成功:

lenovo@YQ:~$ source activate obspy  [激活ObsPy]

(obspy) lenovo@YQ:~$ python3  [已经在ObsPy环境,输入python亦或python3进入Python环境]
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from obspy import read [执行此步骤,如未报错,证明安装成功]
>>> st = read('http://examples.obspy.org/RJOB_061005_072159.ehz.new')
>>> print(st)
1 Trace(s) in Stream:
.RJOB..Z | 2005-10-06T07:21:59.850000Z - 2005-10-06T07:24:59.845000Z | 200.0 Hz, 36000 samples

>>> [Ctrl+D] [退出Python]

(obspy) lenovo@YQ:~$ source deactivate  [退出ObsPy]
lenovo@YQ:~$

3. 常见错误

1.出现ModuleNotFoundError: No module named 'obspy';有两个原因,第一是ObsPy没安装成功,请检查是否漏掉安装步骤。第二是系统默认的Python环境和ObsPy安装的Python环境不一致,示例如下:

lenovo@YQ:~/Obspy$ source activate obspy
(obspy) lenovo@YQ:~/Obspy$ python [默认Python 3.5.2]
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from obspy import read
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'obspy'
>>> [Ctrl+D]
(obspy) lenovo@YQ:~/Obspy$ python3 [Python 3.5.5]
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from obspy import read
>>> 

2.出现AttributeError: Unknown property axisbg或者AttributeError: 'Axes' object has no attribute 'set_axis_bgcolor',这系列问题都是因为在matplotlib 2.0.0及以上版本里,The axisbg and axis_bgcolor properties on Axes have been deprecated in favor of facecolor.

解决办法:找到报错时提示的文件,如

/home/lenovo/.pyenv/versions/anaconda3-4.4.0/envs/obspy/lib/python3.5/site-packages/obspy/imaging/waveform.py
/home/lenovo/.pyenv/versions/anaconda3-4.4.0/envs/obspy/lib/python3.5/site-packages/obspy/imaging/maps.py

waveform.py ,maps.py诸如此类的文件里面的axisbg改成facecolor:

axisbg=self.background_color 改为 facecolor=self.face_color
ax.set_axis_bgcolor 改为 ax.set_facecolor
....

3.出现ImportError: Neither Basemap nor Cartopy could be imported.

conda install basemap

4.出现KeyError: 'PROJ_LIB'.

sudo echo "export PROJ_LIB=$CONDA_PREFIX/share/proj" >> ~/.bashrc
source ~/.bashrc

References: