GMT seems to be a common tool for drawing the epicenter ball (beachball) that represents the focal mechanism of an earthquake, but Python and the visualization library Matplotlib in it. ) Can also be used. As far as I can tell, the main methods for drawing the source sphere using Python are as follows.
As for GMT, there are so many instruction books written by active researchers, and there is already a commentary article for QGIS, so ** Here, I will introduce how to draw a single source sphere for ObsPy in 4. .. ** **
The displayed earthquake data is randomly selected and downloaded from the earthquake mechanism (National Research Institute for Earth Science and Disaster Prevention: Search for Mechanism Solution) published by National Research Institute for Earth Science and Disaster Prevention. The images on this page were drawn by individuals as demonstrations and do not require academic significance in the results.
Please use the script on this page at your own risk.
Drawing example
1. Table of Contents 2. Purpose of this page 3. Usage environment 4. How to install ObsPy 5. Draw something for the time being 6. Demonstration 7. Conclusion 8. References
Write a source sphere as a Matplotlib subplot.
Matplotlib used the one that was included by default when Anaconda was installed. ObsPy required future, scipy, sqlalchemy, numpy, lxml, setuptools, decorator, matplotlib, requests, etc., so if you get an error during the installation, suspect them. If you install it according to the normal procedure, these will be installed automatically.
Officially, it is recommended to install it in a virtual environment using Anaconda [^ 3]. In particular,
conda config --add channels conda-forge
in the command to add the conda-forge channel to Anaconda's configuration.conda create -n obspy python = 3.8
etc.conda activate obspy
etc.conda install obspy
.It will be the flow. For details, see "How to create a conda virtual environment" and "How to install a conda package". The above flow is a translation of the following page as it is, so it is strongly recommended to check it before doing it.
Installation via Anaconda · obspy/obspy Wiki · GitHub
In my own environment, I used pip to enter in one shot (because it is a personal computer that can be broken). Type pip install obspy
at the command prompt and it handles all the dependencies. However, when building an environment on Windows, we do not recommend it because there are some contents on the net that it is generally better to do it virtually. Also, if you want a higher version, there is a github repository at the link below, so you may be able to install it from there (I have no experience).
GitHub - obspy/obspy: ObsPy: A Python Toolbox for seismology/seismological observatories.
While referring to the official tutorial of ObsPy (Link 1, Link 2), try executing the following script. Matplotlib.pyplot.show () didn't work well in my own environment, so I set up to create a PNG image (test.png) for the time being.
test.py
import matplotlib.pyplot as plt
from obspy.imaging.beachball import beach
fig = plt.Figure(figsize=(6,6)) # matplotlib.pyplot.Figure 600x600(px)
np1 = [249,15,127] #Focal mechanism I want to draw Part 1
mt = [-1.2676, 1.8667, -0.5991, 0.7903, 1.6198, -0.9791] #Focal mechanism I want to draw Part 2
beach1 = beach(np1, xy=(25, 25), width=30)
beach2 = beach(mt, xy=(75, 75), width=50)
ax = fig.add_subplot(111, facecolor="white")
ax.plot([25, 75], [75, 25], "rv", ms=20)
ax.add_collection(beach1)
ax.add_collection(beach2)
ax.set_xlim((0, 100))
ax.set_ylim((0, 100))
fig.savefig("test.png ")
plt.close()
result
If the environment is in place, you should be able to execute it without difficulty. As you can see from the image above, it has the following features.
Based on the tutorial script, I created a demo script.
beachball_demo.py
import matplotlib.pyplot as plt
from obspy.imaging.beachball import beach
fig = plt.Figure(figsize=(18,6))
#Drawing by strike, tilt, and slip angle
ax1 = fig.add_subplot(1,3,1, facecolor="white") #The background color is white
np1 = [249,15,127] # strike, dip, rake
explanation = "Earthquake\n2003-09-26 04:50" #Text on the epicenter sphere
explanation2 = "strike : " + str(int(np1[0])) + '\n' + "dip : " + str(int(np1[1])) + '\n' + "rake : " + str(int(np1[2])) #Similarly
beach1 = beach(np1, xy=(50, 50), width=50, facecolor="black") # obspy.imaging.Drawing item by beach ball Blue by default in your own environment
ax1.set_aspect("equal")#Align the scale of the xy axis
ax1.add_collection(beach1) #Insert beach ball
ax1.text(50,85,explanation,fontsize=20,horizontalalignment='center',verticalalignment='center') #Text placement. The center of the box(50,85)To be
ax1.text(50,12,explanation2,fontsize=20,horizontalalignment='center',verticalalignment='center') #Similarly
ax1.set_xlim((0, 100)) #For convenience, such coordinate values are given.
ax1.set_ylim((0, 100)) #Similarly
ax1.axes.xaxis.set_visible(False) #Hide scale
ax1.axes.yaxis.set_visible(False) #Similarly
#Drawing with a moment tensor
ax2 = fig.add_subplot(1,3,2, facecolor="white")
mt = [-1.2676, 1.8667, -0.5991, 0.7903, 1.6198, -0.9791] # mrr(mzz) mtt(mxx) mff(myy) mrt(mxz) mrf(-myz) mtf(-mxy)
explanation = "Earthquake\n2020-12-31 23:45"
explanation2 = "mrr : " + str(mt[0]) + '\n' + "mtt : " + str(mt[1]) + '\n' + "mff : " + str(mt[2])
explanation3 = "mrt : " + str(mt[3]) + '\n' + "mrf : " + str(mt[4]) + '\n' + "mtf : " + str(mt[5])
beach2 = beach(mt, xy=(50, 50), width=50, facecolor="red")#Make it red
ax2.set_aspect("equal")
ax2.add_collection(beach2)
ax2.text(50,85,explanation,fontsize=20,horizontalalignment='center',verticalalignment='center')
ax2.text(2,12,explanation2,fontsize=20,horizontalalignment='left',verticalalignment='center') #Adjust the coordinate values to the left
ax2.text(52,12,explanation3,fontsize=20,horizontalalignment='left',verticalalignment='center')
ax2.set_xlim((0, 100))
ax2.set_ylim((0, 100))
ax2.axes.xaxis.set_visible(False)
ax2.axes.yaxis.set_visible(False)
#Appropriate scatter plot unrelated to the earthquake
ax3 = fig.add_subplot(1,3,3, facecolor="white")
ax3.scatter([10, 49, 46, 90, 24], [45, 57, 32, 67, 2],color="black")
ax3.set_aspect("equal")
ax3.set_xlim((0, 100))
ax3.set_ylim((0, 100))
ax3.set_xlabel('x', fontsize=20)
ax3.set_ylabel('y', fontsize=20)
ax3.set_title("Some plot", fontsize=20)
plt.tight_layout()#So that the labels do not overlap
fig.savefig("beachball_demo.png ") #Save as png image
#fig.show() #It did not activate in its own environment
plt.close()
result
It seems to work well v (-∀-) v
By applying this script, I think you can draw the source sphere in the image plotting other data. However, most of the demand for epicenter spheres is to plot on a map, so if you want to complete them on Python, you need to link with a map library such as Cartopy (I can follow that at the moment). Is not ) . For plotting on maps, ObsPy's official documentation has a script that uses mpl_toolkits.basemap (link), but the new release of mpl_toolkits.basemap that you are using will be stopped in 2020. It is supposed to be [^ 2], and it is recommended to use Cartopy as a successor. I will try it if I have a chance.
Regarding drawing on the map, I think that there are more references in GMT and QGIS at present, so it is recommended to refer to them.
===== 2021/01/15 postscript: It turned out that cooperation with Cartopy is possible. [Python, ObsPy] I drew a beach ball on the map with Cartopy + ObsPy
Recommended Posts