-
Notifications
You must be signed in to change notification settings - Fork 228
Figure.coast/pygmt.select/pygmt.grdlandmask: Use long names ("crude"/"low"/"intermediate"/"high"/"full") for the 'resolution' parameter #3013
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
Changes from 13 commits
44f983f
4fae745
5fac3ae
5e1ebe8
2cbe6c9
e24bbd8
1267a9c
aaeb5f4
af1fb75
c4b9692
4c64859
8a57f61
5f6d3a1
39987aa
ba50993
50f6406
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
coast - Plot continents, countries, shorelines, rivers, and borders. | ||
""" | ||
|
||
from typing import Literal | ||
|
||
from pygmt.clib import Session | ||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import ( | ||
|
@@ -11,6 +13,7 @@ | |
kwargs_to_strings, | ||
use_alias, | ||
) | ||
from pygmt.src._common import _parse_coastline_resolution | ||
|
||
__doctest_skip__ = ["coast"] | ||
|
||
|
@@ -20,7 +23,6 @@ | |
A="area_thresh", | ||
B="frame", | ||
C="lakes", | ||
D="resolution", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After removing |
||
E="dcw", | ||
F="box", | ||
G="land", | ||
|
@@ -37,7 +39,13 @@ | |
t="transparency", | ||
) | ||
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") | ||
def coast(self, **kwargs): | ||
def coast( | ||
self, | ||
resolution: Literal[ | ||
"auto", "full", "high", "intermediate", "low", "crude", None | ||
] = None, | ||
**kwargs, | ||
): | ||
r""" | ||
Plot continents, countries, shorelines, rivers, and borders. | ||
|
||
|
@@ -73,10 +81,12 @@ def coast(self, **kwargs): | |
parameter. Optionally, specify separate fills by appending | ||
**+l** for lakes or **+r** for river-lakes, and passing multiple | ||
strings in a list. | ||
resolution : str | ||
**f**\|\ **h**\|\ **i**\|\ **l**\|\ **c**. | ||
Select the resolution of the data set to: (**f**\ )ull, (**h**\ )igh, | ||
(**i**\ )ntermediate, (**l**\ )ow, and (**c**\ )rude. | ||
resolution | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Select the resolution of the coastline dataset to use. The available resolutions | ||
from highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``, | ||
``"low"``, and ``"crude"``, which drops by 80% between levels. Default is | ||
``"auto"`` to automatically select the most suitable resolution given the chosen | ||
map scale. | ||
land : str | ||
Select filling of "dry" areas. | ||
rivers : int, str, or list | ||
|
@@ -200,5 +210,8 @@ def coast(self, **kwargs): | |
"lakes, land, water, rivers, borders, dcw, Q, or shorelines." | ||
) | ||
raise GMTInvalidInput(msg) | ||
|
||
kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution)) | ||
|
||
Comment on lines
+214
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The simplest form of this line is:
but to support short-form parameters like
The
It's fine, but then ruff will complain that the |
||
with Session() as lib: | ||
lib.call_module(module="coast", args=build_arg_list(kwargs)) |
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.
Thoughts on making a StrEnum out of this?
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.
What are the benefits? This private function will likely be removed after #3239 is implemented.
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.
GMT uses short-form arguments, but we prefer long-form arguments in PyGMT. Another example is in #3012. It will be a lot of work if we define StrEnum for all these cases. #3239 proposed a more general solution for it.
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.
Yeah,
StrEnum
will be a lot more work, and we'll need to bring in something like pydantic (mentioned at #3239 (comment)) to fully enable runtime checks. Ok to keep this as is for now, and wait for #3239.