forked from GenericMappingTools/pygmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery example to showcase blockmean (GenericMappingTools#1598)
Co-authored-by: Will Schlitzer <schlitzer90@gmail.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
- Loading branch information
1 parent
1a30f9e
commit d9db5c5
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,63 @@ | ||
""" | ||
Blockmean | ||
--------- | ||
The :meth:`pygmt.blockmean` method calculates different quantities | ||
inside blocks/bins whose dimensions are defined via the ``spacing`` parameter. | ||
The following examples show how to calculate the averages of the given values | ||
inside each bin and how to report the number of points inside each bin. | ||
""" | ||
|
||
import pygmt | ||
|
||
# Load sample data | ||
data = pygmt.datasets.load_japan_quakes() | ||
# Select only needed columns | ||
data = data[["longitude", "latitude", "depth_km"]] | ||
|
||
# Set the region for the plot | ||
region = [130, 152.5, 32.5, 52.5] | ||
# Define spacing in x and y direction (150 by 150 minute blocks) | ||
spacing = "150m" | ||
|
||
fig = pygmt.Figure() | ||
|
||
# Calculate mean depth in km from all events within 150x150 minute | ||
# bins using blockmean | ||
df = pygmt.blockmean(data=data, region=region, spacing=spacing) | ||
# convert to grid | ||
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing) | ||
|
||
fig.grdimage( | ||
grid=grd, | ||
region=region, | ||
frame=["af", '+t"Mean earthquake depth inside each block"'], | ||
cmap="batlow", | ||
) | ||
# plot slightly transparent landmasses on top | ||
fig.coast(land="darkgray", transparency=40) | ||
# plot original data points | ||
fig.plot( | ||
x=data.longitude, y=data.latitude, style="c0.3c", color="white", pen="1p,black" | ||
) | ||
fig.colorbar(frame=["x+lkm"]) | ||
|
||
fig.shift_origin(xshift="w+5c") | ||
|
||
# Calculate number of total locations within 150x150 minute bins via | ||
# blockmean's summary parameter | ||
df = pygmt.blockmean(data=data, region=region, spacing=spacing, summary="n") | ||
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing) | ||
|
||
fig.grdimage( | ||
grid=grd, | ||
region=region, | ||
frame=["af", '+t"Number of points inside each block"'], | ||
cmap="batlow", | ||
) | ||
fig.coast(land="darkgray", transparency=40) | ||
fig.plot( | ||
x=data.longitude, y=data.latitude, style="c0.3c", color="white", pen="1p,black" | ||
) | ||
fig.colorbar(frame=["x+lcount"]) | ||
|
||
fig.show() |