Skip to content
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

WIP: Add tutorial showing how to plot focal mechanisms (beachballs) #2550

Draft
wants to merge 124 commits into
base: main
Choose a base branch
from

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented May 29, 2023

Description of proposed changes

This PR aims to add a tutorial showing how to plot focal mechanisms using pygmt.Figure.meca. It focuses on how the display of the beachballs can be adjusted and modified:

  • Filling the quadrants
  • Plotting the P and T axes
  • Plotting the components of a seismic moment tensor
  • Adjusting the outlines
  • Highlighting the nodal planes
  • Adding offset from the event location
  • Adding a label
  • Using size-coding and color-coding

Related PRs (need to be merged before this PR is mergd)

Backup of code for plotting the P and T axes

# %%
# Plotting the P and T axes
# -------------------------
#
# Wait for PR #3526

fig = pygmt.Figure()
fig.basemap(region=[-size, size] * 2, projection=projection, frame=frame)

fig.meca(
    spec=mt_dict_single,
    scale="1c",
    longitude=-2,
    latitude=0,
    Fa=True,
)

fig.meca(
    spec=mt_dict_single,
    scale="1c",
    longitude=2,
    latitude=0,
    Fa="0.2c/cd",  # Compute and plot P and T axes with symbols, Adjust size and symbols
    Fe="darkorange",  # Adjust fill of T axis symbol
    Fg="gray30",  # Adjust fill of P axis symbol
    Ft="0.8p,cornsilk",  # Adjust outline of T axis symbol
    Fp="0.8p,gray60",  # Adjust outline of P axis symbol
)

fig.show()

Preview: https://pygmt-dev--2550.org.readthedocs.build/en/2550/tutorials/advanced/focal_mechanisms.html

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label May 29, 2023
@yvonnefroehlich yvonnefroehlich added this to the 0.11.0 milestone May 29, 2023
@yvonnefroehlich yvonnefroehlich self-assigned this May 29, 2023
@yvonnefroehlich yvonnefroehlich marked this pull request as draft May 29, 2023 19:07
@yvonnefroehlich yvonnefroehlich changed the title Add tutorial showing how to plot focal mechanisms (beachballs) WIP: Add tutorial showing how to plot focal mechanisms (beachballs) May 29, 2023
@yvonnefroehlich
Copy link
Member Author

/format

@seisman seisman added this to the 0.15.0 milestone Mar 9, 2025
#
# Store focal mechanism parameters for one event in a dictionary following the

# moment tensor convention
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason that you need to define two focal mechanims here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I think I wanted to have the moment tensor convention for section "Plotting the components of a seismic moment tensor" (around line 109) and later the Aki and Richards convention for the sections "Adjusting the outlines" (around line 143) and "Highlighting the nodal planes" (around line 173).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see your points. What about renaming them to shorter names like meca_aki/meca_mt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea of the variable names was convention_datatype_amount:

  • aki_dict_single
  • mt_dict_single
  • aki_dict_multiple
  • aki_df_multiple

Comment on lines +289 to +308
# Set up a dictionary
aki_dict_multiple = {
"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",
],
}
# Convert to a pandas.DataFrame
aki_df_multiple = pd.DataFrame(aki_dict_multiple)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aki_df_dict is not used:

Suggested change
# Set up a dictionary
aki_dict_multiple = {
"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",
],
}
# Convert to a pandas.DataFrame
aki_df_multiple = pd.DataFrame(aki_dict_multiple)
# Set up a pandas.DataFrame with multiple focal mechanism parameters.
aki_df_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",
],
}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants