From b493d81225ad6f49386ede7899088d214ecb77bf Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 22 Jul 2024 23:07:40 +0800 Subject: [PATCH] Also improve select and grdlandmask --- pygmt/src/coast.py | 8 +++++--- pygmt/src/grdlandmask.py | 30 ++++++++++++++++++------------ pygmt/src/select.py | 22 ++++++++++++---------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index d7ad8ea7d29..e456fc74a55 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -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 @@ -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] diff --git a/pygmt/src/grdlandmask.py b/pygmt/src/grdlandmask.py index 6d4a57242f3..93061baee1c 100644 --- a/pygmt/src/grdlandmask.py +++ b/pygmt/src/grdlandmask.py @@ -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 @@ -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. @@ -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 @@ -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] + with Session() as lib: with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd: kwargs["G"] = voutgrd diff --git a/pygmt/src/select.py b/pygmt/src/select.py index 75f4fa802ef..4faf1afb479 100644 --- a/pygmt/src/select.py +++ b/pygmt/src/select.py @@ -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""" @@ -116,16 +117,13 @@ def select( ` *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. @@ -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] + output_type = validate_output_table_type(output_type, outfile=outfile) column_names = None