准备工作#
本节贡献者: 田冬冬
最近更新日期: 2022-06-12
预计花费时间: 10 分钟
这一章,我们将使用 Python 语言和 ObsPy 软件包 学习并掌握地震学数据的获取、处理和分析。在开始本章内容之前,读者应:
阅读《Python 语言》一节,并安装 Miniconda
掌握 Python 的基本语法并了解如何执行 Python 代码
安装依赖包#
本章中的地震学实践需要使用如下 Python 包:
ObsPy: 用于地震数据获取、处理和分析
cartopy: 用于绘制地图
JupyterLab: 基于浏览器的交互式开发环境
通过如下命令安装所需依赖包:
$ conda install obspy cartopy jupyterlab
检查当前环境#
开启一个终端,在终端中键入 jupyter lab 命令来启动 JupyterLab。
在 JupyterLab 中新建一个 Notebook,并在 Notebook 中执行如下命令以检查当前环境。
import platform
import obspy
import matplotlib
import numpy
import cartopy
print("Python: ", platform.python_version())
print("ObsPy: ", obspy.__version__)
print("Matplotlib: ", matplotlib.__version__)
print("NumPy: ", numpy.__version__)
print("cartopy: ", cartopy.__version__)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 3
1 import platform
----> 3 import obspy
4 import matplotlib
5 import numpy
File ~/micromamba/envs/seismo-learn/lib/python3.13/site-packages/obspy/__init__.py:44
41 msg = ('pkg_resources is deprecated as an API')
42 warnings.filterwarnings(
43 'ignore', message=msg, category=DeprecationWarning, module='obspy')
---> 44 from obspy.core.utcdatetime import UTCDateTime # NOQA
45 from obspy.core.util import _get_version_string
46 __version__ = _get_version_string(abbrev=10)
File ~/micromamba/envs/seismo-learn/lib/python3.13/site-packages/obspy/core/__init__.py:120
12 """
13 obspy.core - Core classes of ObsPy
14 ==================================
(...) 117 .. _NumPy: http://www.numpy.org
118 """
119 # don't change order
--> 120 from obspy.core.utcdatetime import UTCDateTime # NOQA
121 from obspy.core.util.attribdict import AttribDict # NOQA
122 from obspy.core.trace import Stats, Trace # NOQA
File ~/micromamba/envs/seismo-learn/lib/python3.13/site-packages/obspy/core/utcdatetime.py:21
18 import warnings
20 import numpy as np
---> 21 from obspy.core.util.deprecation_helpers import ObsPyDeprecationWarning
24 # based on https://www.myintervals.com/blog/2009/05/20/iso-8601, w/ week 53 fix
25 _ISO8601_REGEX = re.compile(r"""
26 ^
27 ([\+-]?\d{4}(?!\d{2}\b))
(...) 40 $
41 """, re.VERBOSE)
File ~/micromamba/envs/seismo-learn/lib/python3.13/site-packages/obspy/core/util/__init__.py:22
20 # import order matters - NamedTemporaryFile must be one of the first!
21 from obspy.core.util.attribdict import AttribDict
---> 22 from obspy.core.util.base import (ALL_MODULES, DEFAULT_MODULES,
23 NATIVE_BYTEORDER, NETWORK_MODULES,
24 NamedTemporaryFile, _read_from_plugin,
25 create_empty_data_chunk, get_example_file,
26 get_script_dir_name, MATPLOTLIB_VERSION,
27 SCIPY_VERSION, NUMPY_VERSION,
28 CARTOPY_VERSION, CatchAndAssertWarnings)
29 from obspy.core.util.misc import (BAND_CODE, CatchOutput, complexify_string,
30 guess_delta, score_at_percentile,
31 to_int_or_zero, SuppressOutput)
32 from obspy.core.util.obspy_types import (ComplexWithUncertainties, Enum,
33 FloatWithUncertainties)
File ~/micromamba/envs/seismo-learn/lib/python3.13/site-packages/obspy/core/util/base.py:26
23 from pathlib import PurePath
25 import numpy as np
---> 26 import pkg_resources
27 from pkg_resources import get_entry_info, iter_entry_points
29 from obspy.core.util.misc import to_int_or_zero, buffered_load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'