diff --git a/pygmt/src/_common.py b/pygmt/src/_common.py index 378376415e4..ec9583e31c3 100644 --- a/pygmt/src/_common.py +++ b/pygmt/src/_common.py @@ -244,55 +244,3 @@ def from_params( if set(param_list).issubset(set(params)): return cls(convention, component=component) raise GMTValueError(params, description="focal mechanism parameters") - - -def _parse_coastline_resolution( - resolution: Literal["auto", "full", "high", "intermediate", "low", "crude", None], -) -> Literal["a", "f", "h", "i", "l", "c", None]: - """ - Parse the 'resolution' parameter for coastline-related functions. - - Parameters - ---------- - resolution - 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. Alternatively, choose - ``"auto"`` to automatically select the most suitable resolution given the chosen - map scale or region. ``None`` means using the default resolution. - - Returns - ------- - The single-letter resolution code or ``None``. - - Raises - ------ - GMTValueError - If the resolution is invalid. - - Examples - -------- - >>> _parse_coastline_resolution("full") - 'f' - >>> _parse_coastline_resolution("f") - 'f' - >>> _parse_coastline_resolution(None) - >>> _parse_coastline_resolution("invalid") - Traceback (most recent call last): - ... - pygmt...GMTValueError: Invalid .... Expected .... - """ - if resolution is None: - return None - - _valid_res = {"auto", "full", "high", "intermediate", "low", "crude"} - - if resolution in _valid_res: # Long-form arguments. - return resolution[0] # type: ignore[return-value] - - if resolution in {_res[0] for _res in _valid_res}: # Short-form arguments. - return resolution # type: ignore[return-value] - - raise GMTValueError( - resolution, choices=_valid_res, description="GSHHG coastline resolution" - ) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 5cc38899eb6..497869faeed 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -14,7 +14,6 @@ kwargs_to_strings, use_alias, ) -from pygmt.src._common import _parse_coastline_resolution __doctest_skip__ = ["coast"] @@ -24,7 +23,6 @@ A="area_thresh", B="frame", C="lakes", - D="resolution-", E="dcw", F="box", G="land", @@ -68,6 +66,7 @@ def coast( Full GMT docs at :gmt-docs:`coast.html`. {aliases} + - D=resolution - J=projection Parameters @@ -214,9 +213,19 @@ def coast( ) raise GMTInvalidInput(msg) - kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution)) - aliasdict = AliasSystem( + D=Alias( + resolution, + name="resolution", + mapping={ + "auto": "a", + "full": "f", + "high": "h", + "intermediate": "i", + "low": "l", + "crude": "c", + }, + ), J=Alias(projection, name="projection"), ).merge(kwargs) diff --git a/pygmt/src/grdlandmask.py b/pygmt/src/grdlandmask.py index 53e4df5dc6e..b96a5e8c551 100644 --- a/pygmt/src/grdlandmask.py +++ b/pygmt/src/grdlandmask.py @@ -16,7 +16,6 @@ kwargs_to_strings, use_alias, ) -from pygmt.src._common import _parse_coastline_resolution __doctest_skip__ = ["grdlandmask"] @@ -24,7 +23,6 @@ @fmt_docstring @use_alias( A="area_thresh", - D="resolution-", I="spacing", R="region", V="verbose", @@ -53,6 +51,7 @@ def grdlandmask( Full GMT docs at :gmt-docs:`grdlandmask.html`. {aliases} + - D=resolution - E=bordervalues - N=maskvalues @@ -118,9 +117,19 @@ def grdlandmask( msg = "Both 'region' and 'spacing' must be specified." raise GMTInvalidInput(msg) - kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution)) - aliasdict = AliasSystem( + D=Alias( + resolution, + name="resolution", + mapping={ + "auto": "a", + "full": "f", + "high": "h", + "intermediate": "i", + "low": "l", + "crude": "c", + }, + ), N=Alias(maskvalues, name="maskvalues", sep="/", size=(2, 5)), E=Alias(bordervalues, name="bordervalues", sep="/", size=4), ).merge(kwargs) diff --git a/pygmt/src/select.py b/pygmt/src/select.py index 2bcfcd7a0b5..18758e6ab46 100644 --- a/pygmt/src/select.py +++ b/pygmt/src/select.py @@ -16,7 +16,6 @@ use_alias, validate_output_table_type, ) -from pygmt.src._common import _parse_coastline_resolution __doctest_skip__ = ["select"] @@ -78,6 +77,7 @@ def select( Full GMT docs at :gmt-docs:`gmtselect.html`. {aliases} + - D=resolution - J=projection Parameters @@ -211,8 +211,6 @@ def select( >>> # longitudes 246 and 247 and latitudes 20 and 21 >>> out = pygmt.select(data=ship_data, region=[246, 247, 20, 21]) """ - kwargs["D"] = kwargs.get("D", _parse_coastline_resolution(resolution)) - output_type = validate_output_table_type(output_type, outfile=outfile) column_names = None @@ -220,6 +218,18 @@ def select( column_names = data.columns.to_list() aliasdict = AliasSystem( + D=Alias( + resolution, + name="resolution", + mapping={ + "auto": "a", + "full": "f", + "high": "h", + "intermediate": "i", + "low": "l", + "crude": "c", + }, + ), J=Alias(projection, name="projection"), ).merge(kwargs) diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 61ff8fcb405..78650014a80 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -76,26 +76,6 @@ def test_coast_dcw_list(): return fig -@pytest.mark.mpl_image_compare(filename="test_coast_world_mercator.png") -def test_coast_resolution_short_form(): - """ - Test using the short form of the 'resolution' parameter. - - This test is the same as test_coast_world_mercator, but uses the short form of - the 'resolution' parameter. - """ - fig = Figure() - fig.coast( - region=[-180, 180, -80, 80], - projection="M15c", - frame="af", - land="#aaaaaa", - D="crude", - water="white", - ) - return fig - - def test_coast_resolution_long_short_form_conflict(): """ Test that using the short form of the 'resolution' parameter conflicts with