-
Notifications
You must be signed in to change notification settings - Fork 254
Add blockmedian and surface gallery example #4771
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
seisman
merged 13 commits into
GenericMappingTools:main
from
Aayush7788:docs-blockmedian-surface
Aug 12, 2026
+81
−0
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7f5c0dc
Add blockmedian and surface gallery example
Aayush7788 3ff5eeb
Apply review suggestions
Aayush7788 a6a497c
Merge remote-tracking branch 'upstream/main' into docs-blockmedian-su…
Aayush7788 09f57c7
Address additional review comments
Aayush7788 9362660
Update examples/gallery/images/gridding_with_surface.py
Aayush7788 d1af0bc
Update examples/gallery/images/gridding_with_surface.py
Aayush7788 ad0979e
Update examples/gallery/images/gridding_with_surface.py
Aayush7788 516bad2
Explain surface data bounds
Aayush7788 9cd8375
Merge remote-tracking branch 'upstream/main' into docs-blockmedian-su…
Aayush7788 31a926b
Use blockmedian center parameter
Aayush7788 0f4d230
Polish gridding gallery example
Aayush7788 131c457
Polish gridding gallery example
Aayush7788 de86b11
Address gallery review comments
Aayush7788 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
Some comments aren't visible on the classic Files Changed page.
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,81 @@ | ||
| """ | ||
| Gridding scattered data | ||
| ======================= | ||
|
|
||
| The :func:`pygmt.surface` function interpolates irregularly spaced (x, y, z) | ||
| observations onto a regular grid. Before interpolation, it's usually recommended to | ||
| preprocess the data using one of :func:`pygmt.blockmean`, :func:`pygmt.blockmedian`, and | ||
| :func:`pygmt.blockmode`, to avoid aliasing short wavelengths, by returning one value for | ||
| every occupied block. | ||
|
|
||
| """ | ||
|
|
||
| # %% | ||
| import pygmt | ||
| from pygmt.params import Axis, Frame, Position | ||
|
|
||
| # Load irregular ship-track observations of bathymetry off Baja California. | ||
| data = pygmt.datasets.load_sample_data(name="bathymetry") | ||
|
|
||
| region = [245, 255, 20, 30] | ||
| spacing = "5m" # 5 arc-minutes | ||
|
|
||
| # Calculate one representative median value for each occupied block. | ||
| reduced_data = pygmt.blockmedian(data=data, region=region, spacing=spacing, center=True) | ||
|
|
||
| # Interpolate the reduced observations onto a regular grid. The value "d" | ||
| # constrains the grid to the minimum and maximum input data values. | ||
| grid = pygmt.surface( | ||
| data=reduced_data, region=region, spacing=spacing, lower="d", upper="d" | ||
| ) | ||
|
seisman marked this conversation as resolved.
|
||
|
|
||
| fig = pygmt.Figure() | ||
| pygmt.makecpt(cmap="gmt/geo", series=[-7500, 0, 500]) | ||
| pygmt.config(FONT_TITLE="12p", MAP_TITLE_OFFSET="4p") | ||
|
|
||
| with fig.subplot(nrows=1, ncols=2, figsize=("20c", "9c")): | ||
| # Block-median observations. | ||
| with fig.set_panel(panel=0): | ||
| fig.basemap( | ||
| region=region, | ||
| projection="M?", | ||
| frame=Frame( | ||
| axis=Axis(annot=2, tick=1), | ||
| title="Block-median observations", | ||
| ), | ||
| ) | ||
| fig.plot( | ||
| x=reduced_data.longitude, | ||
| y=reduced_data.latitude, | ||
| fill=reduced_data.bathymetry, | ||
| style="c0.05c", | ||
| cmap=True, | ||
| ) | ||
| fig.coast(land="gray", shorelines="0.5p,black") | ||
|
|
||
| # Interpolated surface grid. | ||
| with fig.set_panel(panel=1): | ||
| fig.grdimage( | ||
| grid=grid, | ||
| region=region, | ||
| projection="M?", | ||
| frame=Frame( | ||
| axis=Axis(annot=2, tick=1), | ||
| title="Interpolated surface", | ||
| ), | ||
| cmap=True, | ||
| ) | ||
| fig.coast(land="gray", shorelines="0.5p,black") | ||
|
|
||
| # Position the color bar using explicit plot coordinates: | ||
| # 10 cm is the horizontal center of the 20 cm wide subplot. | ||
| fig.colorbar( | ||
| position=Position(("10c", "-1.2c"), cstype="plotcoords", anchor="TC"), | ||
| length=12, | ||
| width=0.4, | ||
| orientation="horizontal", | ||
| annot=1000, | ||
| label="Bathymetry (m)", | ||
| ) | ||
|
|
||
| fig.show() | ||
Oops, something went wrong.
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.