智能摘要 AI
本文介绍了如何在谷歌地球中展示小型地震球的方法。通过使用Python脚本结合`obspy.imaging.beachball`库生成地震球PNG图片,并利用`simplekml`库创建包含地震信息的KML文件。具体步骤包括读取地震数据(如时间、经纬度、深度等),生成对应的地震球图像并保存,然后将其添加到KML文件中。最终生成的KML文件可在谷歌地球中打开,直观展示地震分布及其特征。
不经意间看到一篇文章,讲述了有关谷歌地球的绘制方法,而在谷歌地球上可以轻松地扩展和缩小区域。在谷歌地图上画一个地震球,就能轻易看出地震发生的原因。本文介绍如何将一个小型的地震球显示在谷歌上。
这个道理,也是比较好理解的:
使用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文件,效果如下图 所示。



评论 (0)