-
Notifications
You must be signed in to change notification settings - Fork 228
Add an advanced tutorial for plotting focal mechanisms (beachballs) #2550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
154 commits
Select commit
Hold shift + click to select a range
9a031b2
Add basic structur and code examples for meca tutorial
yvonnefroehlich 24802bb
Fix typos
yvonnefroehlich 686bf92
[format-command] fixes
actions-bot 744cf3f
Use 'nodal', Adjust front size of 'event_name' label
yvonnefroehlich f3f0bd3
Remove color-coding from section 'Add label'
yvonnefroehlich 9d19715
Add section 'Plot several beachballs'
yvonnefroehlich ba9debf
Expand convention list, Adjust the other lists in the introduction part
yvonnefroehlich 5e12f74
Fix line length
yvonnefroehlich 4a8a24e
Adjust code and comments
yvonnefroehlich e2d705d
Adjust thumbnail figure
yvonnefroehlich 725f54d
Fix code comment
yvonnefroehlich ec06281
Adjust stuff regarding 'input data'
yvonnefroehlich f6b77d1
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich e97f1b4
Use aliases for 'L', 'T', and 'Fr'
yvonnefroehlich 2c31093
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich c0662fb
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 05e323d
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 4a390fc
Add remark regarding GMT issue #7777 and PR #7778
yvonnefroehlich 96ee768
Add empty line after heading in tutorial 'focal_mechanisms.py'
yvonnefroehlich 16fae40
Update code separate in tutorial 'focal_mechanisms.py'
yvonnefroehlich af105a3
Use two empty lines befor sub-sections
yvonnefroehlich a457331
Use empty line after sub-section
yvonnefroehlich 2293b38
Use correct order of regarding sphinx thumbnail
yvonnefroehlich 735b314
Fix typos
yvonnefroehlich a787467
Move 'sphinx_gallery_thumbnail_number' comand line to end of script
yvonnefroehlich f58843b
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 8007aed
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich cc6357e
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich c404293
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich a7c0c9d
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 3319916
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich fbf37f9
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 3cf475e
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 69ce531
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich eff5567
Shorten code and docs
yvonnefroehlich 39f055e
Change study area
yvonnefroehlich b41fde2
Replace tab by four spaces
yvonnefroehlich 0f687c9
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 1d9f05a
Consider maximum line length
be8be06
Follow ruff's C4 rules
yvonnefroehlich 4607189
Adjust colors to shorten script length
yvonnefroehlich e4bf3a7
[format-command] fixes
actions-bot 3cc11a1
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 5166a15
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich da369b6
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 8c8a442
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 118ed00
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 2ce90e8
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 6d870fc
Improve documetation
yvonnefroehlich 6eac949
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 649bf83
Fix length of underline
yvonnefroehlich eec5e37
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 828ef97
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 8ab43e2
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 482452f
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 3c6a225
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 28044fc
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 792be20
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich d35395e
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 2f04a60
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 7f8daa3
General update of code
yvonnefroehlich d018e49
Remove execution permission
yvonnefroehlich b033019
Adjust figure size
yvonnefroehlich ee0c18f
Adjust figure size
yvonnefroehlich 0692453
Adjust figure size
yvonnefroehlich de50cd5
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 515c87b
Fix highlighting
yvonnefroehlich e6e57f7
Fix highlighting
yvonnefroehlich d4a3d56
Use different input formats and events
yvonnefroehlich 257077a
Improve formulation of content list and headings
yvonnefroehlich 2c32da7
Invert colormap
yvonnefroehlich 7b47d2d
Use a continous colormap
yvonnefroehlich d898e0b
Update earthqauke data
yvonnefroehlich 72e5cc6
Update comment | Fix typo
yvonnefroehlich 96f3240
Add comments
yvonnefroehlich 34fbbd5
Add comments
yvonnefroehlich 2347ac7
Update introduction part
yvonnefroehlich 6228447
Add links to pattern resources
yvonnefroehlich e3e0696
Update comments
yvonnefroehlich 4a675b1
Update comments
yvonnefroehlich 48bcdf8
Update comments
yvonnefroehlich 7718e7b
Remove exectuion permission
yvonnefroehlich 998e42d
Update introduction part
yvonnefroehlich 13e600b
Expand comments
yvonnefroehlich f146079
Add example for 'component' parameter
yvonnefroehlich 2260e6c
Update headings
yvonnefroehlich 645f5f1
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 65b09b6
Convert from list to text
yvonnefroehlich 649def2
Expand docs
yvonnefroehlich 091c898
Format introduction part
yvonnefroehlich f759a40
Add blank line
yvonnefroehlich ae2fb87
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 02de7ff
Add section for plotting P and T axes
yvonnefroehlich e7ec741
Remove execution permission
yvonnefroehlich d49ccbb
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich f304b13
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 68b5aa7
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 5dddbc5
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 4622f1e
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich b65f5cf
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 3d235dd
Rewrap line length
yvonnefroehlich 479b1ad
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 5dbea74
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich e5151ff
Remove code examples for T and P axes
yvonnefroehlich bcc8a5d
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich f1b3c14
Fix highlighting, formulations, interpuncation
yvonnefroehlich 34c392c
Define region directly
yvonnefroehlich 5815c98
Remove mixed up variable name
yvonnefroehlich 8716f0a
Fix highlighting
yvonnefroehlich f34979c
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 96bbe1b
Add depth
yvonnefroehlich 5bc0025
Fix comment
yvonnefroehlich e7ad5fe
Fix typo
yvonnefroehlich 000d38b
Fix thumbnail image
yvonnefroehlich e699445
Fix highlighting
yvonnefroehlich 5f6dc3b
Make formulation sound nicer
yvonnefroehlich a02a725
Make formulation seismically for descriptive
yvonnefroehlich 4375ae9
Make formulation more related to the user
yvonnefroehlich c9d07ba
Fix code to comment
yvonnefroehlich f6afebf
Remove training white spaces
yvonnefroehlich 4055d02
Fix code to comment
yvonnefroehlich 57121bf
Move section for *fill up
yvonnefroehlich 350d01d
Explain scale parameter regarding size
yvonnefroehlich abb7ae7
Fix typo
yvonnefroehlich 40a330d
Combine setting up dictionary and converting to dataframe
yvonnefroehlich 15cc0e1
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich b0c7752
Remove datatype from variable name
yvonnefroehlich 5dfdc96
Remove offset parameter for dict input
yvonnefroehlich 8d19aad
Improve explanaition of offset parameter
yvonnefroehlich 5ed896d
Use for loop for component parameter
yvonnefroehlich 379cdb1
Add explanation for muliple beachballs
yvonnefroehlich 4214b71
Remove unneeded pen attribute
yvonnefroehlich 20a70f0
Use math mode
yvonnefroehlich 7031b26
Use zip
yvonnefroehlich a586f11
Fix code style
yvonnefroehlich eb158bb
Adjust spacing
yvonnefroehlich 8f6cab6
Fix math mode
yvonnefroehlich 73f24b4
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 9925eab
Fix math mode
yvonnefroehlich 46dc736
Remove overview list
yvonnefroehlich fb70e78
Remove trailing white space
yvonnefroehlich 6709e51
Fix typo
yvonnefroehlich ddf6211
Use line length
yvonnefroehlich 6574f7e
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich e37421a
Use for loop and dicts
yvonnefroehlich ac88165
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 14b31b4
Fix code style
yvonnefroehlich 4a87d23
Improve docs
yvonnefroehlich 6f449fe
Improve docs
yvonnefroehlich 93712b2
Use equal space between beachballs
yvonnefroehlich 8933633
Merge branch 'main' into add-tutorial-meca
yvonnefroehlich 4489590
Fix typos
yvonnefroehlich 0577297
Merge branch 'main' into add-tutorial-meca
michaelgrund 7e52907
Fix a lot of typos
yvonnefroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,327 @@ | ||
""" | ||
Plotting focal mechanisms | ||
========================= | ||
|
||
Focal mechanisms can be plotted as beachballs with the :meth:`pygmt.Figure.meca` method. | ||
|
||
The focal mechanism data or parameters can be provided as various input types: ASCII | ||
file, :class:`numpy.array`, dictionary, or :class:`pandas.Dataframe`. Different | ||
conventions to define the focal mechanism are supported: Aki and Richards (``"aki"``), | ||
global CMT (``"gcmt"``), moment tensor (``"mt"``), partial focal mechanism | ||
(``"partial"``), and, principal axis (``"principal_axis"``). Please refer to the table | ||
in the documentation of :meth:`pygmt.Figure.meca` regarding how to set up the input data | ||
in respect to the chosen input type and convention (i.e., the expected column order, | ||
keys, or column names). In this tutorial we focus on how to adjust the display of the | ||
beachballs. | ||
""" | ||
|
||
# %% | ||
import pandas as pd | ||
import pygmt | ||
|
||
# Set up arguments for basemap | ||
region = [-5, 5, -5, 5] | ||
projection = "X10c/4c" | ||
frame = ["af", "+ggray90"] | ||
|
||
|
||
# %% | ||
# Setting up the focal mechanism data | ||
# ----------------------------------- | ||
# | ||
# We store focal mechanism parameters for two single events in dictionaries using the | ||
# moment tensor and Aki and Richards conventions: | ||
|
||
# moment tensor convention | ||
mt_single = { | ||
"mrr": 4.71, | ||
"mtt": 0.0381, | ||
"mff": -4.74, | ||
"mrt": 0.399, | ||
"mrf": -0.805, | ||
"mtf": -1.23, | ||
"exponent": 24, | ||
} | ||
# Aki and Richards convention | ||
aki_single = {"strike": 318, "dip": 89, "rake": -179, "magnitude": 7.75} | ||
|
||
|
||
# %% | ||
# Plotting a single beachball | ||
# --------------------------- | ||
# | ||
# Required parameters are ``spec`` and ``scale`` as well as ``longitude``, ``latitude`` | ||
# (event location), and depth (if these values are not included in the argument passed | ||
# to ``spec``). Additionally, the ``convention`` parameter is required if ``spec`` is | ||
# an 1-D or 2-D numpy array; for the input types dictionary and ``pandas.Dataframe``, | ||
# the focal mechanism convention is automatically determined from dictionary keys or | ||
# :class:`pandas.DataFrame` column names. The ``scale`` parameter controls the radius | ||
# of the beachball. By default, the value defines the size for a magnitude of 5 (i.e., | ||
# a scalar seismic moment of :math:`M_0 = 4.0 \times 10^{23}` dyn cm) and the beachball | ||
# size is proportional to the magnitude. Append ``"+l"`` to force the radius to be | ||
# proportional to the seismic moment. | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
fig.meca(spec=mt_single, scale="1c", longitude=0, latitude=0, depth=0) | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Plotting the components of a seismic moment tensor | ||
# -------------------------------------------------- | ||
# | ||
# A moment tensor can be decomposed into isotropic and deviatoric parts. The deviatoric | ||
# part can be further decomposed into multiple parts (e.g., a double couple (DC) and a | ||
# compensated linear vector dipole (CLVD)). Use the ``component`` parameter to specify | ||
# the component you want to plot. | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
for component, longitude in zip(["full", "dc", "deviatoric"], [-2, 0, 2], strict=True): | ||
fig.meca( | ||
spec=mt_single, | ||
scale="1c", | ||
longitude=longitude, | ||
latitude=0, | ||
depth=0, | ||
component=component, | ||
) | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Filling the quadrants | ||
# --------------------- | ||
# | ||
# Use the parameters ``compressionfill`` and ``extensionfill`` to fill the quadrants | ||
# with different colors or patterns. Regarding patterns see the gallery example | ||
# :doc:`Bit and hachure patterns </gallery/symbols/patterns>` and the Technical | ||
# Reference :doc:`Bit and hachure patterns </techref/patterns>`. | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
fig.meca( | ||
spec=mt_single, | ||
scale="1c", | ||
longitude=-2, | ||
latitude=0, | ||
depth=0, | ||
compressionfill="darkorange", | ||
extensionfill="cornsilk", | ||
) | ||
|
||
fig.meca( | ||
spec=mt_single, | ||
scale="1c", | ||
longitude=2, | ||
latitude=0, | ||
depth=0, | ||
compressionfill="p8", | ||
extensionfill="p31", | ||
outline=True, | ||
) | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Adjusting the outlines | ||
# ---------------------- | ||
# | ||
# Use the parameters ``pen`` and ``outline`` for adjusting the circumference of the | ||
# beachball or all lines (i.e, circumference and both nodal planes). | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=-2, | ||
latitude=0, | ||
depth=0, | ||
# Use a 1-point thick, darkorange and solid line | ||
pen="1p,darkorange", | ||
) | ||
|
||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=2, | ||
latitude=0, | ||
depth=0, | ||
outline="1p,darkorange", | ||
) | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Highlighting the nodal planes | ||
# ----------------------------- | ||
# | ||
# Use the parameter ``nodal`` to highlight specific nodal planes. ``"0"`` refers to | ||
# both, ``"1"`` to the first, and ``"2"`` to the second nodal plane(s). Only the | ||
# circumference and the specified nodal plane(s) are plotted, i.e. the quadrants | ||
# remain unfilled (transparent). We can make use of the stacking concept of (Py)GMT, | ||
# and use ``nodal`` in combination with the ``outline``, ``compressionfill`` / | ||
# ``extensionfill`` and ``pen`` parameters. | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=-2, | ||
latitude=0, | ||
depth=0, | ||
nodal="0/1p,black", | ||
) | ||
|
||
# Plot the same beachball three times with different settings: | ||
# (i) Fill the compressive quadrants | ||
# (ii) Plot the first nodal plane and the circumference in darkorange | ||
# (iii) Plot the circumfence in black on top; use "-" to not fill the quadrants | ||
for kwargs in [ | ||
{"compressionfill": "lightorange"}, | ||
{"nodal": "1/1p,darkorange"}, | ||
{"compressionfill": "-", "extensionfill": "-", "pen": "1p,gray30"}, | ||
]: | ||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=0, | ||
latitude=0, | ||
depth=0, | ||
**kwargs, | ||
) | ||
fig.show() | ||
|
||
|
||
# %% | ||
# Adding offset from event location | ||
# --------------------------------- | ||
# | ||
# Specify the optional parameters ``plot_longitude`` and ``plot_latitude``. If ``spec`` | ||
# is an ASCII file with columns for ``plot_longitude`` and ``plot_latitude``, the | ||
# ``offset`` parameter has to be set to ``True``. Besides just drawing a line between | ||
# the beachball and the event location, a small circle can be plotted at the event | ||
# location by appending **+s** and the descired circle diameter. The connecting line as | ||
# well as the outline of the circle are plotted with the setting of pen, or can be | ||
# adjusted separately. The fill of the small circle corresponds to the fill of the | ||
# compressive quadrantes. | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=region, projection=projection, frame=frame) | ||
|
||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=-1, | ||
latitude=0, | ||
depth=0, | ||
plot_longitude=-3, | ||
plot_latitude=2, | ||
) | ||
|
||
fig.meca( | ||
spec=aki_single, | ||
scale="1c", | ||
longitude=3, | ||
latitude=0, | ||
depth=0, | ||
plot_longitude=1, | ||
plot_latitude=2, | ||
offset="+p1p,darkorange+s0.25c", | ||
compressionfill="lightorange", | ||
) | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Plotting multiple beachballs | ||
# ---------------------------- | ||
# | ||
# Now we want to plot multiple beachballs with one call of :meth:`pygmt.Figure.meca`. We | ||
# use data of four earthquakes taken from USGS. For each focal mechanism parameter a | ||
# list with a length corresponding to the number of events has to be given. | ||
|
||
# Set up a pandas.DataFrame with multiple focal mechanism parameters. | ||
aki_multiple = pd.DataFrame( | ||
{ | ||
"strike": [255, 173, 295, 318], | ||
"dip": [70, 68, 79, 89], | ||
"rake": [20, 83, -177, -179], | ||
"magnitude": [7.0, 5.8, 6.0, 7.8], | ||
"longitude": [-72.53, -79.61, 69.46, 37.01], | ||
"latitude": [18.44, 0.90, 33.02, 37.23], | ||
"depth": [13, 19, 4, 10], | ||
"plot_longitude": [-70, -110, 100, 0], | ||
"plot_latitude": [40, 10, 50, 55], | ||
"event_name": [ | ||
"Haiti - 2010/01/12", | ||
"Esmeraldas - 2022/03/27", | ||
"Afghanistan - 2022/06/21", | ||
"Syria/Turkey - 2023/02/06", | ||
], | ||
} | ||
) | ||
|
||
|
||
# %% | ||
# Adding a label | ||
# -------------- | ||
# | ||
# Use the optional parameter ``event_name`` to add a label near the beachball, e.g., | ||
# event name or event date and time. Change the font of the label text by appending | ||
# **+f** and the desired font (size,name,color) to the argument passed to the ``scale`` | ||
# parameter. Additionally, the location of the label relative to the beachball [Default | ||
# is ``"TC"``, i.e., Top Center] can be changed by appending **+j** and an offset can | ||
# be applied by appending **+o** with values for *dx*\ /*dy*. Add a colored [Default is | ||
# white] box behind the label via the label ``labelbox``. Force a fixed size of the | ||
# beachball by appending **+m** to the argument passed to the ``scale`` parameter. | ||
|
||
fig = pygmt.Figure() | ||
fig.coast(region="d", projection="N10c", land="lightgray", frame=True) | ||
|
||
fig.meca(spec=aki_multiple, scale="0.4c+m+f5p", labelbox="white@30", offset="+s0.1c") | ||
|
||
fig.show() | ||
|
||
|
||
# %% | ||
# Using size-coding and color-coding | ||
# ---------------------------------- | ||
# | ||
# The beachball can be sized and colored by the quantities given as ``magnitude`` and | ||
# ``depth``, e.g., by moment magnitude or hypocentral depth, respectively. Use the | ||
# parameter ``cmap`` to pass the descired colormap. Now, the fills of the small circles | ||
# indicating the event locations are given by the colormap. | ||
|
||
fig = pygmt.Figure() | ||
fig.coast(region="d", projection="N10c", land="lightgray", frame=True) | ||
|
||
# Set up colormap and colorbar for hypocentral depth | ||
pygmt.makecpt(cmap="lajolla", series=[0, 20]) | ||
fig.colorbar(frame=["x+lhypocentral depth", "y+lkm"]) | ||
|
||
fig.meca( | ||
spec=aki_multiple, | ||
scale="0.4c+f5p", | ||
offset="0.2p,gray30+s0.1c", | ||
labelbox="white@30", | ||
cmap=True, | ||
outline="0.2p,gray30", | ||
) | ||
|
||
fig.show() | ||
|
||
# sphinx_gallery_thumbnail_number = 8 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.