Skip to content

Commit

Permalink
Also improve select and grdlandmask
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jul 22, 2024
1 parent 88be372 commit b493d81
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
8 changes: 5 additions & 3 deletions pygmt/src/coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def coast(
resolution
Select the resolution of the coastline dataset to use. The available resolutions
from highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``,
``"low"``, and ``"crude"``. Default is ``"auto"`` to automatically select the
most suitable resolution given the chosen map scale.
``"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
Expand Down Expand Up @@ -208,7 +209,8 @@ def coast(
"""At least one of the following parameters must be specified:
lakes, land, water, rivers, borders, dcw, Q, or shorelines"""
)
# resolution

# Resolution
if kwargs.get("D") is not None:
kwargs["D"] = kwargs["D"][0]

Expand Down
30 changes: 18 additions & 12 deletions pygmt/src/grdlandmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
grdlandmask - Create a "wet-dry" mask grid from shoreline data base
"""

from typing import Literal

from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
Expand All @@ -22,7 +24,11 @@
x="cores",
)
@kwargs_to_strings(I="sequence", R="sequence", N="sequence", E="sequence")
def grdlandmask(outgrid: str | None = None, **kwargs):
def grdlandmask(
outgrid: str | None = None,
resolution: Literal["full", "high", "intermediate", "low", "crude"] = "low", # noqa: ARG001
**kwargs,
):
r"""
Create a grid file with set values for land and water.
Expand All @@ -43,17 +49,13 @@ def grdlandmask(outgrid: str | None = None, **kwargs):
{spacing}
{region}
{area_thresh}
resolution : str
*res*\[\ **+f**\]. Select the resolution of the data set to use
((**f**)ull, (**h**)igh, (**i**)ntermediate, (**l**)ow, or
(**c**)rude). The resolution drops off by ~80% between data sets.
[Default is **l**]. Append **+f** to automatically select a lower
resolution should the one requested not be available
[abort if not found]. Alternatively, choose (**a**)uto to automatically
select the best resolution given the chosen region. Note that because
the coastlines differ in details a node in a mask file using one
resolution is not guaranteed to remain inside [or outside] when a
different resolution is selected.
resolution
Ignored unless ``mask`` is set. 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. Note that because the coastlines differ in details it is not
guaranteed that a point will remain inside [or outside] when a different
resolution is selected.
bordervalues : bool, str, float, or list
Nodes that fall exactly on a polygon boundary should be
considered to be outside the polygon [Default considers them to be
Expand Down Expand Up @@ -97,6 +99,10 @@ def grdlandmask(outgrid: str | None = None, **kwargs):
if kwargs.get("I") is None or kwargs.get("R") is None:
raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")

# Resolution
if kwargs.get("D") is not None:
kwargs["D"] = kwargs["D"][0]

Check warning on line 104 in pygmt/src/grdlandmask.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/grdlandmask.py#L104

Added line #L104 was not covered by tests

with Session() as lib:
with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
kwargs["G"] = voutgrd
Expand Down
22 changes: 12 additions & 10 deletions pygmt/src/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def select(
data=None,
output_type: Literal["pandas", "numpy", "file"] = "pandas",
outfile: str | None = None,
resolution: Literal["full", "high", "intermediate", "low", "crude"] = "low", # noqa: ARG001
**kwargs,
) -> pd.DataFrame | np.ndarray | None:
r"""
Expand Down Expand Up @@ -116,16 +117,13 @@ def select(
<reference/file-formats.html#optional-segment-header-records>`
*polygonfile*. For spherical polygons (lon, lat), make sure no
consecutive points are separated by 180 degrees or more in longitude.
resolution : str
*resolution*\ [**+f**].
Ignored unless ``mask`` is set. Selects the resolution of the coastline
data set to use ((**f**)ull, (**h**)igh, (**i**)ntermediate, (**l**)ow,
or (**c**)rude). The resolution drops off by ~80% between data sets.
[Default is **l**]. Append (**+f**) to automatically select a lower
resolution should the one requested not be available [Default is abort
if not found]. Note that because the coastlines differ in details
it is not guaranteed that a point will remain inside [or outside] when
a different resolution is selected.
resolution
Ignored unless ``mask`` is set. 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. Note that because the coastlines differ in details it is not
guaranteed that a point will remain inside [or outside] when a different
resolution is selected.
gridmask : str
Pass all locations that are inside the valid data area of the grid
*gridmask*. Nodes that are outside are either NaN or zero.
Expand Down Expand Up @@ -205,6 +203,10 @@ def select(
>>> # longitudes 246 and 247 and latitudes 20 and 21
>>> out = pygmt.select(data=ship_data, region=[246, 247, 20, 21])
"""
# Resolution
if kwargs.get("D") is not None:
kwargs["D"] = kwargs["D"][0]

Check warning on line 208 in pygmt/src/select.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/select.py#L208

Added line #L208 was not covered by tests

output_type = validate_output_table_type(output_type, outfile=outfile)

column_names = None
Expand Down

0 comments on commit b493d81

Please sign in to comment.