Skip to content
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
50d5364
Add draft of JN for pandas - dataframe for scatterplot and histogram
yvonnefroehlich Dec 24, 2024
465470e
Include output figure
yvonnefroehlich Jan 4, 2025
4629685
Reduce resolution of output image in JN
yvonnefroehlich Jan 4, 2025
994ee17
Follow coding style
yvonnefroehlich Jan 5, 2025
d0b965a
Adjust filename
yvonnefroehlich Jan 5, 2025
4a7d267
Remove comments
yvonnefroehlich Oct 16, 2025
522f97d
Move to normal python script (temporaly)
yvonnefroehlich Nov 5, 2025
47ba3ed
Remove / uncomment histogram
yvonnefroehlich Nov 5, 2025
8cb30e8
Rename files and save output figure
yvonnefroehlich Nov 12, 2025
c1fa0bd
Add histogram back
yvonnefroehlich Nov 12, 2025
718043d
Add codes for epicenters map with depth section
yvonnefroehlich Nov 13, 2025
d8238d7
Add two histograms and use mapproject to determine the height
yvonnefroehlich Nov 15, 2025
6c1bfad
Add inset map showing study area globally
yvonnefroehlich Nov 15, 2025
9691062
Only pass symbol via style
yvonnefroehlich Nov 16, 2025
1fffdd2
Merge remote-tracking branch 'origin/main' into fig/pandas
yvonnefroehlich Nov 16, 2025
e5e533f
Merge remote-tracking branch 'origin/fig/pandas' into fig/pandas
yvonnefroehlich Nov 16, 2025
312a93d
Adjust annotations and ticks of frame of historgrams
yvonnefroehlich Nov 16, 2025
d629171
Adjust size and position of inset
yvonnefroehlich Nov 16, 2025
2114217
Add draft for plotting beachball via meca
yvonnefroehlich Nov 16, 2025
163ba84
Add legend for size-coding of moment magnitude
yvonnefroehlich Nov 16, 2025
6386a9d
Add histogram for moment magnitude as inset
yvonnefroehlich Nov 16, 2025
00caf3e
Remove beachball
yvonnefroehlich Nov 16, 2025
3d59b2f
Improve code
yvonnefroehlich Nov 16, 2025
a312faf
Improve code
yvonnefroehlich Nov 16, 2025
62086f1
Remove unit from argument passed to the projection parameter
yvonnefroehlich Nov 17, 2025
f7c7b14
Remove comment
yvonnefroehlich Nov 17, 2025
0c7e1dd
Use shortcut Mw for moment magnitude
yvonnefroehlich Nov 17, 2025
391080e
Remove comment
yvonnefroehlich Nov 17, 2025
f3140b3
Remove code for second version
yvonnefroehlich Nov 17, 2025
a2e325f
Remove old files
yvonnefroehlich Nov 17, 2025
bcc2e13
Request real data
yvonnefroehlich Nov 17, 2025
a346b03
Adjust size coding
yvonnefroehlich Nov 17, 2025
b3f76ac
Use magnitude range 4 to 6.5
yvonnefroehlich Nov 17, 2025
7534574
Improve offset for legend
yvonnefroehlich Nov 17, 2025
37c09db
Remove sorting by moment magnitude
yvonnefroehlich Nov 17, 2025
6bdc2f7
Change from japan to myanmar
yvonnefroehlich Nov 18, 2025
0c8e75b
Add beachball for myanmar earthquake
yvonnefroehlich Nov 18, 2025
a913291
Adjust study area | Use moment magnitude range 4 to 6.5
yvonnefroehlich Nov 18, 2025
761d76e
Adjust moment magnitude ragne
yvonnefroehlich Nov 18, 2025
a326d2e
Make maps consistent
yvonnefroehlich Nov 18, 2025
1a02fa6
Polish maps
yvonnefroehlich Nov 18, 2025
a312aea
Focus on moment magnitude
yvonnefroehlich Nov 18, 2025
9bdbbd3
Limit hypocentral depth
yvonnefroehlich Nov 19, 2025
143b3bb
Extend magnitude range | Reduce circle size
yvonnefroehlich Nov 19, 2025
1607022
Adjust code to test different regions
yvonnefroehlich Nov 20, 2025
7d3e43f
Rename file
yvonnefroehlich Nov 20, 2025
2924e23
Rename file
yvonnefroehlich Nov 20, 2025
92bf26e
Increase size of histogram and adjust the offset
yvonnefroehlich Nov 21, 2025
41cab14
Remove unneeded variables
yvonnefroehlich Nov 21, 2025
c1d1cac
Focus on Indonesia
yvonnefroehlich Nov 21, 2025
11b43ad
Fix typo
yvonnefroehlich Nov 22, 2025
fdb496f
Directly import the Box class
yvonnefroehlich Nov 26, 2025
e537f2b
Fill legend box with white
yvonnefroehlich Nov 26, 2025
206f8cd
Update output image
yvonnefroehlich Nov 26, 2025
decccde
Import Box directly
yvonnefroehlich Nov 26, 2025
d398690
Add outline around legend box
yvonnefroehlich Nov 26, 2025
cc64ea8
Remove blank line
yvonnefroehlich Nov 26, 2025
83f652f
Use the same font size for annotations and labels of histogram
yvonnefroehlich Nov 26, 2025
a82687d
Remove triangle for extrem values from colorbar
yvonnefroehlich Nov 26, 2025
e639681
Set minimum of CPT to 0 km
yvonnefroehlich Nov 26, 2025
8ea9fa8
Update output image
yvonnefroehlich Nov 26, 2025
cfd9af5
No fill color for histogram | Move size legend to TM | Use box=True
yvonnefroehlich Nov 26, 2025
ed591dc
Adjust position of legend
yvonnefroehlich Nov 26, 2025
b9fda48
Move legend box back and fill it with white color
yvonnefroehlich Nov 26, 2025
97a8c7c
Remove variable for URL
yvonnefroehlich Nov 27, 2025
ccba97d
Remove longitude and latitude from request
yvonnefroehlich Nov 27, 2025
bdbbaaf
Add querries for longitude and latitude
yvonnefroehlich Nov 27, 2025
3e48031
Follow coding style
yvonnefroehlich Nov 27, 2025
12e6237
Merge remote-tracking branch 'origin/main' into fig/pandas
yvonnefroehlich Nov 27, 2025
dd91f37
Merge remote-tracking branch 'origin/main' into fig/pandas
yvonnefroehlich Nov 27, 2025
bed7149
Reorder parameter for following the main text
yvonnefroehlich Nov 28, 2025
12e8fb3
Plot colorbar after plotting data points
yvonnefroehlich Nov 28, 2025
ab74ba2
Use all magnitudes
yvonnefroehlich Nov 28, 2025
c1df2e3
Merge remote-tracking branch 'origin/main' into fig/pandas
yvonnefroehlich Nov 29, 2025
dbfeb4c
Sort data via pandas instead of during the request
yvonnefroehlich Nov 29, 2025
00e7e12
Limit magnitude to 9 in histogram
yvonnefroehlich Nov 30, 2025
7eab108
Write 'Magnitude M' not only 'M' for histogram x label
yvonnefroehlich Nov 30, 2025
3b2d9f5
Do not adjust Font size for histogram
yvonnefroehlich Nov 30, 2025
6fe7ee5
Move codes to JN | Remove .py and PNG files | Remove execution permis…
yvonnefroehlich Nov 30, 2025
aa06195
Remove variable name form x label of histogram
yvonnefroehlich Nov 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Fig4_PyGMT_pandas.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "533bc728-db2c-4f3a-ab3f-1f4f2c9ecd69",
"metadata": {},
"outputs": [],
"source": [
"# Copy finale version of script from normal Python file"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added Fig4_PyGMT_pandas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions Fig4_PyGMT_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import io

import pandas as pd
import pygmt
import requests
from pygmt.params import Box

Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
params = {
"format": "csv",
"starttime": "2000-01-01",
"endtime": "2025-10-30",
"mindepth": 70,
"minmagnitude": 5,
"orderby": "magnitude",
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
}
r = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query", params=params)
df_eqs = pd.read_csv(io.StringIO(r.text))
df_eqs = df_eqs[
(df_eqs["longitude"] >= 91)
& (df_eqs["longitude"] <= 134)
& (df_eqs["latitude"] >= -22)
& (df_eqs["latitude"] <= 19)
& (df_eqs["magType"] != "mb")
Comment thread
seisman marked this conversation as resolved.
Outdated
]
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated

fig = pygmt.Figure()
fig.basemap(region=[91, 134, -22, 19], projection="M15c", frame=True)
fig.coast(land="gray95", shorelines="gray50")

# Plot epicenters with color (hypocentral depth) or size (moment magnitude)
pygmt.makecpt(cmap="SCM/navia", series=[0, 700], reverse=True, transparency=30)
fig.colorbar(frame=["xaf+lHypocentral depth", "y+lkm"])
Comment thread
seisman marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we just simplify it to:

Suggested change
fig.colorbar(frame=["xaf+lHypocentral depth", "y+lkm"])
fig.colorbar(frame="af+lHypocentral depth (km)")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm. I placed the unit as y label to avoid that we have to think about having units in brackets or using a /🙃😅.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, we can keep it now. But I feel the frame parameter is still not Pythonic and we may need to implement the Frame class anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, yes, the frame parameter is maybe the most complicated parameter in GMT / PyGMT and provides a huge amount of quite different functionalities 🙂.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, maybe we should have a look at the author guidelines of $G^3$ if there are any rules how to set units in figures.

fig.plot(
x=df_eqs.longitude,
y=df_eqs.latitude,
size=0.005 * 2**df_eqs.mag,
fill=df_eqs.depth,
cmap=True,
style="c",
pen="gray10",
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
)
# Add legend for size-coding
legend = io.StringIO(
"\n".join(f"S 0.4 c {0.005 * 2**mag:.2f} - 1p 1 Mw {mag}" for mag in [5, 6, 7])
Comment thread
michaelgrund marked this conversation as resolved.
Outdated
Comment thread
seisman marked this conversation as resolved.
Outdated
)
fig.legend(spec=legend, position="jBR+o0.2c+l2", box=Box(fill="white", pen="black"))

# Add histogram for moment magnitude distribution
with fig.inset(position="jBL+w7c/4c+o0.2c", margin=(1.2, 0.2, 0.9, 0.2), box=True):
with pygmt.config(FONT="8p"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need to set the FONT here?

@yvonnefroehlich yvonnefroehlich Nov 30, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would remove it; please see my comment #5 (comment). And in addition, there are different themes in GMT which also affect the defaults. I think having different font sizes look OK.

image Fig4_PyGMT_pandas_fontsize_same

fig.histogram(
region=[4.8, 10.2, 0, 0],
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
projection="X?/?",
frame=["WSrt", "xa1f0.2+lMw", "yaf+lCounts"],
data=df_eqs.mag,
series=0.2,
fill="darkgray",
pen="lightgray",
histtype=0,
)

fig.show()
fig.savefig("Fig4_PyGMT_pandas.png")