Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 Fig6_PyGMT_dataprocessing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "825fcbfa-7ade-4eab-9a85-b7505013befd",
"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 Fig6_PyGMT_dataprocessing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions Fig6_PyGMT_dataprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pygmt

df_bath = pygmt.datasets.load_sample_data("bathymetry")
region_study = [
min(df_bath.longitude),
max(df_bath.longitude),
min(df_bath.latitude),
max(df_bath.latitude),
]

region_sel = [360 - 114, 360 - 111, 22, 26]
df_bath_sel = pygmt.select(data=df_bath, region=region_sel)

block_size = "10m" # arc-minutes
# Count data points within each block
df_bath_sel_count = pygmt.blockmean(
data=df_bath_sel, spacing=block_size, region=region_study, summary="n"
)
# Calculate mean bathymetry within each block
df_bath_sel_mean = pygmt.blockmean(
data=df_bath_sel, spacing=block_size, region=region_study
)

# Convert tabular data to GMT-ready grid
grd_bath_sel_count = pygmt.xyz2grd(
data=df_bath_sel_count, region=region_study, spacing=block_size
)
grd_bath_sel_mean = pygmt.xyz2grd(
data=df_bath_sel_mean, region=region_study, spacing=block_size
)

# -----------------------------------------------------------------------------
fig = pygmt.Figure()

for block_value in ["counts", "mean bathymetry in meters"]:
match block_value:
case "counts":
grd_block = grd_bath_sel_count
case "mean bathymetry in meters":
grd_block = grd_bath_sel_mean

fig.coast(region=region_study, projection="M12c", land="gray", frame=True)

# Plot all data points in black
fig.plot(data=df_bath, style="p0.4p", fill="black")

# Plot grid color-coded by number of data points within each block
fig.grdimage(grid=grd_block, cmap="SCM/batlow", nan_transparent=True)
fig.colorbar(frame=f"x+l{block_value} per block")

# Plot data points within subregion in white
fig.plot(data=df_bath_sel, style="p0.4p", fill="white")

fig.shift_origin(xshift="w+2c")

fig.show()
fig.savefig(fname="Fig6_PyGMT_dataprocessing.png")