不经意间看到一篇文章,讲述了有关谷歌地球的绘制方法,而在谷歌地球上可以轻松地扩展和缩小区域。在谷歌地图上画一个地震球,就能轻易看出地震发生的原因。本文介绍如何将一个小型的地震球显示在谷歌上。
这个道理,也是比较好理解的:
使用obspy.imaging.be ach ball
制作一个地震球,并将其作为 PNG文件的一张照片
使用 simplekml
产生含有点数的 KML档案,同时各点与一次地震相关联,将点号设定为震源球形图像。
在这个例子中, catalog.dat
是这样的:
# origin latitude longitude depth mag strike dip rake
20161223172502 36.7282 141.8532 39.67 4.9 4 53 -97
20161228123849 36.7202 140.5742 10.84 5.9 307 52 -118
20161230200827 37.3550 141.4098 27.35 5.1 21 56 -82
以下为 Python 脚本,在 Python 3.6、ObsPy 1.1.0 和 simplekml 1.3.0 下测试通过。
Python脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import matplotlib.pyplot as plt
import simplekml
from obspy.imaging.beachball import beachball
beachball_dir = "beachballs"
if not os.path.exists(beachball_dir):
os.mkdir(beachball_dir)
kml = simplekml.Kml()
with open("catalog.dat") as f:
for line in f:
# skip comment lines
if line.startswith('#'):
continue
items = line.split()
event_id = items[0]
latitude, longitude, depth, magnitude, strike, dip, rake = map(
float, items[1:])
# plot beachballs and save as PNG file
outfile = "{}/{}.png".format(beachball_dir, event_id)
beachball([strike, dip, rake], outfile=outfile)
# must close to avoid opening too many figures one time
plt.close()
# add points to KML file
point = kml.newpoint(name=None)
point.coords = [(longitude, latitude)]
point.description = event_id
# style.iconstyle.scale controls the size of beachball
point.style.iconstyle.scale = 1.5
point.style.iconstyle.icon.href = outfile
kml.save("beachballs.kml")
执行该脚本后会得到KML文件 beachballs.kml
,用Google Earth打开KML文件,效果如下图 所示。
📮评论