-
Notifications
You must be signed in to change notification settings - Fork 235
Figure.grdview: Add parameters surftype/dpi/mesh_fill/nan_transparent/monochrome to control surfure types #4234
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
base: main
Are you sure you want to change the base?
Conversation
ce5fc8f to
d3c7bd2
Compare
d3c7bd2 to
2f32c36
Compare
pygmt/src/grdview.py
Outdated
| ), | ||
| Alias(dpi, name="dpi"), | ||
| Alias(meshfill, name="meshfill"), | ||
| Alias(monochrome, name="monochrome", prefix="+m"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't +m be a suffix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full syntax is -Qc|i|m[x|y]|s[m][color][+m]. It's a suffix for the -Q option, but for monochrome, it's a prefix. Since monochrome is a boolean, monochrome would be +m, so here it makes no difference if +m is a prefix or a suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, got it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that after the suffix feature is implemented in #4259, this +m does need to be a prefix, otherwise a list of values will be returned, xref #4259 (comment).
pygmt/src/grdview.py
Outdated
| "image": "c" if nan_transparent is True else "i", | ||
| "waterfallx": "mx", | ||
| "waterfally": "my", | ||
| } | ||
|
|
||
| # surftype was aliased to Q previously. | ||
| _old_surftype_syntax = surftype not in _surtype_mapping and surftype is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test to ensure that backwards compatibility is preserved when a user passes surftype="c", but did not set nan_transparent=True (which is added in this PR). The output grdview plot should still have NaN transparency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in aa9eb73.
69c28ef to
16051a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors PyGMT’s Figure.grdview -Q option into explicit, Pythonic parameters (surftype, dpi, mesh_fill, nan_transparent, monochrome) and updates tests/examples accordingly.
Changes:
- Add a dedicated
-Qalias builder and expose newgrdviewparameters to control surface rendering modes. - Expand/refresh
grdviewtests (including image baselines) to cover the new parameterization and validation behavior. - Update gallery/tutorial examples to use the new long-form
surftypevalues.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
pygmt/src/grdview.py |
Introduces _alias_option_Q, adds new grdview parameters, updates docs, and validates parameter combinations. |
pygmt/tests/test_grdview.py |
Adds unit + image tests for new -Q parameterization; updates existing tests to new surftype values; updates validation tests. |
pygmt/tests/baseline/test_grdview_with_cmap_for_surface_monochrome_plot.png.dvc |
Removes baseline for deleted test. |
pygmt/tests/baseline/test_grdview_with_cmap_for_perspective_surface_plot.png.dvc |
Removes baseline for deleted test. |
pygmt/tests/baseline/test_grdview_with_cmap_for_image_plot.png.dvc |
Removes baseline for deleted test. |
pygmt/tests/baseline/test_grdview_surftype.png.dvc |
Adds baseline for new surftype coverage image test. |
pygmt/tests/baseline/test_grdview_monochrome.png.dvc |
Adds baseline for new monochrome image test. |
pygmt/tests/baseline/test_grdview_mesh_pen_and_mesh_fill.png.dvc |
Adds baseline for new mesh pen/fill image test. |
pygmt/tests/baseline/test_grdview_image_dpi.png.dvc |
Adds baseline for new image DPI test. |
examples/tutorials/advanced/draping_on_3d_surface.py |
Updates surftype usage to new long-form values. |
examples/tutorials/advanced/3d_perspective_image.py |
Updates surftype usage to new long-form values and adjusts inline comments. |
examples/gallery/3d_plots/grdview_surface.py |
Updates example code to use surftype="surface". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
| @pytest.mark.mpl_image_compare | ||
| def test_grdview_with_cmap_for_image_plot(xrgrid): | ||
| """ | ||
| Run grdview by passing in a grid and setting a colormap for producing an image plot. | ||
| """ | ||
| fig = Figure() | ||
| fig.grdview(grid=xrgrid, cmap="SCM/oleron", surftype="i") | ||
| return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superseded by test_grdview_surftype
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_grdview_with_cmap_for_surface_monochrome_plot(xrgrid): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superseded by test_grdview_monochrome
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superseded by test_grdview_surftype
| - ``"surface"``: surface plot. | ||
| - ``"surface+mesh"``: surface plot with mesh lines drawn on top of the surface. | ||
| - ``"image"``: image plot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used surftype="sim" before here. It's been a few years so I can't remember, but maybe check if -Qsim is equal to -Qsm, or if we need to add a surface+image+mesh option 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surftype="sim" is identical to surftype="s":
import pygmt
grd_relief = pygmt.datasets.load_earth_relief(
resolution="15m", region=[-25, -13, 63.2, 66.7]
)
args = dict(
region=[-25, -13, 63.2, 66.7],
projection="M10c",
perspective=(-150, 25),
cmap="SCM/oleron",
frame=True,
zsize="1.5c",
plane="+ggray",
)
fig = pygmt.Figure()
fig.grdview(grid=grd_relief, surftype="sim", **args)
fig.shift_origin(xshift="w+2c")
fig.grdview(grid=grd_relief, surftype="surface", **args)
fig.show()
-Qsim is taken as -Qs based on the GMT source code https://github.com/GenericMappingTools/gmt/blob/a091f7542cfded0ab0cc7f7fe1f899790b5eed56/src/grdview.c#L773-L777.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, glad to know we don't need to add more combinations!
| - ``"surface"``: surface plot. | ||
| - ``"surface+mesh"``: surface plot with mesh lines drawn on top of the surface. | ||
| - ``"image"``: image plot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, glad to know we don't need to add more combinations!
| surftype | ||
| Specify surface type for the grid. Valid values are: | ||
|
|
||
| - ``"mesh"``: mesh plot [Default]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is technically None if no argument is passed to surftype. Should we remove the [Default] then, or allow for surftype=True to mean surftype="m"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel surftype=True is not intuitive, mainly because:
surftype=Falseis meaningless in this context (Falseusually means "disable")surftype=Trueis mapped to-Qbut-Qwithout any arguments is invalid in GMT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, so let's just remove the [Default] to only allow string literals
| - ``"mesh"``: mesh plot [Default]. | |
| - ``"mesh"``: mesh plot. |
and probably need to update the docs to remove [Default] too at https://docs.generic-mapping-tools.org/6.6/grdview.html#q if -Q by itself is invalid. Unless I'm missing some context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Default" actually means -Q is not required, and if not given, -Qm is used.
This PR improves
grdview's-Qoption in a more Pythonic way by splitting it into multiple parameters:surftypedpinan_transparentmonochromemesh_fillAddress #4208 (comment).
Preview at https://pygmt-dev--4234.org.readthedocs.build/en/4234/api/generated/pygmt.Figure.grdview.html
Example