“Seismic Signal Denoising and Decomposition Using Deep Neural Networks“ 代码复现


英文题目:Seismic Signal Denoising and Decomposition Using Deep Neural Networks

中文题目:基于深度神经网络的地震信号去噪与分解

源码:DeepDenoiser

作者:Zhu, Weiqiang and Mousavi, S. Mostafa and Beroza, Gregory C.

时间:2019

期刊/等级:CCF B / SCI 2区

BibTex:


@article{ WOS:000496155200082,
Author = {Zhu, Weiqiang and Mousavi, S. Mostafa and Beroza, Gregory C.},
Title = {Seismic Signal Denoising and Decomposition Using Deep Neural Networks},
Journal = {IEEE TRANSACTIONS ON GEOSCIENCE AND REMOTE SENSING},
Year = {2019},
Volume = {57},
Number = {11},
Pages = {9476-9488},
Month = {NOV},
DOI = {10.1109/TGRS.2019.2926772},
ISSN = {0196-2892},
EISSN = {1558-0644},
ResearcherID-Numbers = {Mousavi, S. Mostafa/H-9475-2019
   },
ORCID-Numbers = {Mousavi, S. Mostafa/0000-0001-5091-5370
   Zhu, Weiqiang/0000-0003-2889-1493},
Unique-ID = {WOS:000496155200082},
}

摘要:

Frequency filtering is widely used in routine processing of seismic data to improve the signal-to-noise ratio (SNR) of recorded signals and by doing so to improve subsequent analyses. In this paper, we develop a new denoising/decomposition method, DeepDenoiser, based on a deep neural network. This network is able to simultaneously learn a sparse representation of data in the timefrequency domain and a non-linear function that maps this representation into masks that decompose input data into a signal of interest and noise (defined as any non-seismic signal). We show that DeepDenoiser achieves impressive denoising of seismic signals even when the signal and noise share a common frequency band. Because the noise statistics are automatically learned from data and require no assumptions, our method properly handles white noise, a variety of colored noise, and non-earthquake signals. DeepDenoiser can significantly improve the SNR with minimal changes in the waveform shape of interest, even in the presence of high noise levels. We demonstrate the effect of our method on improving earthquake detection. There are clear applications of DeepDenoiser to seismic imaging, micro-seismic monitoring, and preprocessing of ambient noise data. We also note that the potential applications of our approach are not limited to these applications or even to earthquake data and that our approach can be adapted to diverse signals and applications in other settings.


一、配置环境

  1. 进入代码目录
    cd DeepDenoiser-master
  2. 根据自带的.yml创建新的conda环境
    conda env create --file env.yml
  3. 配置清华源
    3.1 各系统都可以通过修改用户目录下的 .condarc 文件来使用 TUNA 镜像源。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。
    3.2 到电脑的“用户”文件夹中,找到 .condarc 文件并打开,把 清华镜像站-anaconda镜像页 上的 condarc 配置语句复制进去即可。
    3.3 在 Anaconda Prompt 中运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。
    3.4 输入 conda info 检查是否配置成功。
  4. 查看所有环境
    conda env list
  5. 查看当前环境下的包
    conda list

二、执行示例代码

1. Interactive example


sys.path.insert(0, os.path.abspath("../"))

这段代码的作用是将当前代码文件所在的目录的父目录添加到 Python 的模块搜索路径中。
具体来说,sys.path 是一个包含 Python 模块搜索路径的列表,Python 解释器会在这些路径中查找需要导入的模块。
os.path.abspath("../") 返回当前代码文件所在目录的父目录的绝对路径,也就是将相对路径 "../" 转换为绝对路径。
sys.path.insert(0, ...) 则是将该绝对路径添加到 sys.path 列表的最前面,这样 Python 解释器在搜索模块时就会先从这个路径中查找,以确保能够正确地导入相关模块。

sys.path

查看Python 模块搜索路径的全部列表,每运行一次 insert ,该列表下都会多一个路径,可以通过下述代码删除路径。

sys.path.remove(os.path.abspath("../"))

Warning: 不要手贱


stream = obspy.read()

Basic Usage
在大多数情况下,文件名被指定为 read() 的唯一参数。为了快速开始,您可以省略所有参数,ObsPy将创建并返回一个基本的地震记录示例。
可以通过下述代码查看示例数据。

print(stream)
stream[0].data

data_id = stream[0].get_id()[:-1]

去除id最后一位,如原id为BW.RJOB..EHE,则返回BW.RJOB..EH


## Add some noise
noisy_data = data + np.random.randn(*data.shape)*np.max(data)/20

np.random.randn() 是 NumPy 库中的一个函数,用于生成符合标准正态分布(均值为 0,标准差为 1)的随机数。
data.shape 返回 data 数组的形状,是一个元组,例如 (3000, 3) 表示 data 数组有 3000 行、3 列。*data.shape 的作用是将这个元组中的两个元素解包成函数的两个参数,例如 np.random.randn(3000, 3)
因此,这个语句的作用是生成一个与 data 形状相同的数组,其中的每个元素都是符合标准正态分布的随机数。随机数的大小约为原始数据中的最大值除以 20。
这个数组通常用于添加随机噪声,以测试和评估地震信号处理算法的鲁棒性和可靠性。


plt.subplot(331)

plt.subplot() 是 Matplotlib 库中的一个函数,用于在一个多子图的绘图区域中创建一个子图。它的参数可以是三个整数,例如 plt.subplot(331),表示将绘图区域分成 3 行 3 列的子图,当前创建的子图位于第 1 行第 1 列。
因此,这个语句的作用是创建一个 3x3 的绘图区域,并将当前子图设为第 1 个子图,后续的绘图操作将在这个子图中进行。在绘制多个子图时,可以多次调用 plt.subplot() 函数,以创建不同的子图。如果需要在多个子图之间切换,可以使用 plt.subplot() 函数的返回值作为当前子图的句柄,例如 ax = plt.subplot(331),然后在后续的绘图操作中使用 ax 来指定当前子图。


2. Batch Prediction example


在当前文件夹下打开 cmd ,下载测试数据。

cd DeepDenoiser
wget https://github.com/wayneweiqiang/PhaseNet/releases/download/test_data/test_data.zip
unzip test_data.zip

DeepDeniser目前支持三种数据格式:numpy 和 mseed

  • For numpy format:
python deepdenoiser/predict.py --model_dir=model/190614-104802 --data_list=test_data/npz.csv --data_dir=test_data/npz --format=numpy --save_signal --plot_figure
  • For mseed format:
python deepdenoiser/predict.py --model_dir=model/190614-104802 --data_list=test_data/mseed.csv --data_dir=test_data/mseed --format=mseed --save_signal --plot_figure

PROJECT_ROOT = os.path.realpath(os.path.join(os.path.abspath(''), ".."))

PROJECT_ROOT 是一个字符串变量,它的值是当前 Python 代码文件所在目录的父目录绝对路径
在这个语句中,os.path.abspath('') 返回当前 Python 代码文件所在的目录的绝对路径,例如 /home/user/code/,然后 os.path.join() 函数将这个路径和字符串 ".." 组合起来,得到 /home/user/,即当前目录的父目录绝对路径。最后,os.path.realpath() 函数对这个路径进行规范化处理,得到一个标准的绝对路径,例如 /mnt/c/Users/user/
因此,这个语句的作用是将当前 Python 代码文件所在目录的父目录的绝对路径存储在变量 PROJECT_ROOT 中,方便后续代码中的路径操作。


enumerate(sorted(glob.glob(os.path.join(PROJECT_ROOT, "output/results/*npz"))))

这行代码通过 glob.glob() 函数搜索指定目录下的文件,并返回文件名列表。具体来说,这行代码的含义是:
使用 os.path.join(PROJECT_ROOT, "output/results/*npz") 得到一个带有通配符的文件路径,例如 /home/user/output/results/*npz,该路径表示 PROJECT_ROOT 目录下的 output/results 子目录中的所有以 .npz 结尾的文件。
使用 glob.glob() 函数搜索符合条件的文件,得到一个文件名列表。
使用 sorted() 函数对文件名列表进行排序,以确保文件按照字母顺序排列。
使用 enumerate() 函数遍历排好序的文件名列表,并返回每个文件名的索引和值。
因此,这行代码的作用是获取 PROJECT_ROOT/output/results 目录下所有以 .npz 结尾的文件名,并按照字母顺序排序,然后枚举这些文件名,依次处理每个文件。


raw_signal = np.load(os.path.join(PROJECT_ROOT, "test_data/npz/", fp.split("/")[-1]))["data"][5000:8000,-1]

该行代码报错,修改为:

raw_signal = np.load(os.path.join(PROJECT_ROOT, "test_data/npz/", fp.split("/")[-1].split("\\")[-1]))["data"][5000:8000,-1]

同样的,将下述代码进行修改:

# plt.suptitle(fp.split("/")[-1])
plt.suptitle(fp.split("/")[-1].split("\\")[-1])

plt.tight_layout()

plt.tight_layout() 是一个自动调整子图参数的函数,使得子图能够填充整个图像区域,从而避免坐标轴标签重叠。如果子图没有重叠,则不会有明显的影响。
当使用matplotlib创建多个子图并排放置在同一画布上时,有时候会发现它们之间会有重叠的问题。此时,可以使用 plt.tight_layout() 调整子图之间的空白区域,以解决子图之间的重叠问题。
在调用 plt.show() 之前调用 plt.tight_layout() 可以确保图形输出时子图之间的间隔被最小化。

猜你喜欢

转载自blog.csdn.net/qq_43377653/article/details/129151082