diff --git a/doc/techref/common_parameters.md b/doc/techref/common_parameters.md index db6fb888481..aaa4d4e6ecd 100644 --- a/doc/techref/common_parameters.md +++ b/doc/techref/common_parameters.md @@ -22,13 +22,13 @@ ``verbose`` Select verbosity level, which modulates the messages written to stderr. - Choose among 7 levels of verbosity [Default is ``"w"``]: + Choose among 7 levels of verbosity [Default is ``"warning"``]: - - ``"q"``: Quiet, not even fatal error messages are produced - - ``"e"``: Error messages only - - ``"w"``: Warnings [Default] - - ``"t"``: Timings (report runtimes for time-intensive algorithms) - - ``"i"``: Informational messages (same as ``verbose=True``) - - ``"c"``: Compatibility warnings - - ``"d"``: Debugging messages + - ``"quiet"``: Quiet, not even fatal error messages are produced + - ``"error"``: Error messages only + - ``"warning"``: Warnings [Default] + - ``"timing"``: Timings (report runtimes for time-intensive algorithms) + - ``"info"``: Informational messages (same as ``verbose=True``) + - ``"compat"``: Compatibility warnings + - ``"debug"``: Debugging messages ``` diff --git a/pygmt/alias.py b/pygmt/alias.py index b41bd9ec7f4..e2ff50339af 100644 --- a/pygmt/alias.py +++ b/pygmt/alias.py @@ -217,7 +217,14 @@ class AliasSystem(UserDict): >>> from pygmt.helpers import build_arg_list >>> >>> def func( - ... par0, par1=None, par2=None, frame=False, repeat=None, panel=None, **kwargs + ... par0, + ... par1=None, + ... par2=None, + ... frame=False, + ... repeat=None, + ... panel=None, + ... verbose=None, + ... **kwargs, ... ): ... aliasdict = AliasSystem( ... A=[ @@ -227,6 +234,7 @@ class AliasSystem(UserDict): ... B=Alias(frame, name="frame"), ... D=Alias(repeat, name="repeat"), ... ).add_common( + ... V=verbose, ... c=panel, ... ) ... aliasdict.merge(kwargs) @@ -238,9 +246,10 @@ class AliasSystem(UserDict): ... frame=True, ... repeat=[1, 2, 3], ... panel=(1, 2), + ... verbose="debug", ... J="X10c/10c", ... ) - ['-Amytext+o12/12', '-B', '-D1', '-D2', '-D3', '-JX10c/10c', '-c1,2'] + ['-Amytext+o12/12', '-B', '-D1', '-D2', '-D3', '-JX10c/10c', '-Vd', '-c1,2'] """ def __init__(self, **kwargs): @@ -276,6 +285,20 @@ def add_common(self, **kwargs): """ for key, value in kwargs.items(): match key: + case "V": + alias = Alias( + value, + name="verbose", + mapping={ + "quiet": "q", + "error": "e", + "warning": "w", + "timing": "t", + "info": "i", + "compat": "c", + "debug": "d", + }, + ) case "J": alias = Alias(value, name="projection") case "c": diff --git a/pygmt/src/basemap.py b/pygmt/src/basemap.py index b252cd6eb03..ad9966dc083 100644 --- a/pygmt/src/basemap.py +++ b/pygmt/src/basemap.py @@ -2,6 +2,8 @@ basemap - Plot base maps and frames. """ +from typing import Literal + from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -17,14 +19,18 @@ F="box", Td="rose", Tm="compass", - V="verbose", f="coltypes", p="perspective", t="transparency", ) @kwargs_to_strings(R="sequence", p="sequence") def basemap( - self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs + self, + projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + panel: int | tuple[int, int] | bool = False, + **kwargs, ): r""" Plot base maps and frames. @@ -41,6 +47,7 @@ def basemap( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -89,6 +96,7 @@ def basemap( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/binstats.py b/pygmt/src/binstats.py index 3029cdff732..f20ceff111b 100644 --- a/pygmt/src/binstats.py +++ b/pygmt/src/binstats.py @@ -18,7 +18,6 @@ N="normalize", R="region", S="search_radius", - V="verbose", W="weight", a="aspatial", b="binary", @@ -49,6 +48,8 @@ def binstats( "sum", ] = "number", quantile_value: float = 50, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -66,6 +67,7 @@ def binstats( {aliases} - C = statistic + - V = verbose Parameters ---------- @@ -151,7 +153,10 @@ def binstats( "sum": "z", }, ), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) if statistic == "quantile": aliasdict["C"] += f"{quantile_value}" diff --git a/pygmt/src/blockm.py b/pygmt/src/blockm.py index 0ef5510f4fa..6f2920f7591 100644 --- a/pygmt/src/blockm.py +++ b/pygmt/src/blockm.py @@ -7,6 +7,7 @@ import numpy as np import pandas as pd from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import ( build_arg_list, @@ -74,7 +75,6 @@ def _blockm( I="spacing", R="region", S="summary", - V="verbose", a="aspatial", b="binary", d="nodata", @@ -94,6 +94,8 @@ def blockmean( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -111,6 +113,7 @@ def blockmean( Full GMT docs at :gmt-docs:`blockmean.html`. {aliases} + - V = verbose Parameters ---------- @@ -162,6 +165,11 @@ def blockmean( >>> # Calculate block mean values within 5 by 5 arc-minute bins >>> data_bmean = pygmt.blockmean(data=data, region=[245, 255, 20, 30], spacing="5m") """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + return _blockm( block_method="blockmean", data=data, @@ -170,7 +178,7 @@ def blockmean( z=z, output_type=output_type, outfile=outfile, - **kwargs, + **aliasdict, ) @@ -178,7 +186,6 @@ def blockmean( @use_alias( I="spacing", R="region", - V="verbose", a="aspatial", b="binary", d="nodata", @@ -198,6 +205,8 @@ def blockmedian( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -215,6 +224,7 @@ def blockmedian( Full GMT docs at :gmt-docs:`blockmedian.html`. {aliases} + - V = verbose Parameters ---------- @@ -260,6 +270,11 @@ def blockmedian( ... data=data, region=[245, 255, 20, 30], spacing="5m" ... ) """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + return _blockm( block_method="blockmedian", data=data, @@ -268,7 +283,7 @@ def blockmedian( z=z, output_type=output_type, outfile=outfile, - **kwargs, + **aliasdict, ) @@ -276,7 +291,6 @@ def blockmedian( @use_alias( I="spacing", R="region", - V="verbose", a="aspatial", b="binary", d="nodata", @@ -296,6 +310,8 @@ def blockmode( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -313,6 +329,7 @@ def blockmode( Full GMT docs at :gmt-docs:`blockmode.html`. {aliases} + - V = verbose Parameters ---------- @@ -356,6 +373,11 @@ def blockmode( >>> # Calculate block mode values within 5 by 5 arc-minute bins >>> data_bmode = pygmt.blockmode(data=data, region=[245, 255, 20, 30], spacing="5m") """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + return _blockm( block_method="blockmode", data=data, @@ -364,5 +386,5 @@ def blockmode( z=z, output_type=output_type, outfile=outfile, - **kwargs, + **aliasdict, ) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 01fdd932ebf..2cae7050dbc 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -31,7 +31,6 @@ N="borders", R="region", S="water", - V="verbose", W="shorelines", p="perspective", t="transparency", @@ -43,6 +42,8 @@ def coast( resolution: Literal[ "auto", "full", "high", "intermediate", "low", "crude", None ] = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -68,6 +69,7 @@ def coast( {aliases} - D = resolution - J = projection + - V = verbose - c = panel Parameters @@ -229,6 +231,7 @@ def coast( ), ).add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/colorbar.py b/pygmt/src/colorbar.py index 861c69e87fa..4741d11b3fd 100644 --- a/pygmt/src/colorbar.py +++ b/pygmt/src/colorbar.py @@ -2,6 +2,8 @@ colorbar - Plot gray scale or color scale bar. """ +from typing import Literal + from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -20,7 +22,6 @@ L="equalsize", Q="log", R="region", - V="verbose", W="scale", Z="zfile", p="perspective", @@ -28,7 +29,12 @@ ) @kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence") def colorbar( - self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs + self, + projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + panel: int | tuple[int, int] | bool = False, + **kwargs, ): r""" Plot gray scale or color scale bar. @@ -45,6 +51,7 @@ def colorbar( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -149,6 +156,7 @@ def colorbar( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index b33bcdce986..e43c6f25366 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -2,6 +2,8 @@ contour - Contour table data by direct triangulation. """ +from typing import Literal + from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -24,7 +26,6 @@ N="no_clip", R="region", S="skip", - V="verbose", W="pen", b="binary", d="nodata", @@ -44,6 +45,8 @@ def contour( y=None, z=None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -59,6 +62,7 @@ def contour( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -156,6 +160,7 @@ def contour( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/dimfilter.py b/pygmt/src/dimfilter.py index 28a83584c8d..a95a5d6e7bc 100644 --- a/pygmt/src/dimfilter.py +++ b/pygmt/src/dimfilter.py @@ -2,8 +2,11 @@ dimfilter - Directional filtering of grids in the space domain. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -18,11 +21,14 @@ I="spacing", N="sectors", R="region", - V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") def dimfilter( - grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, **kwargs + grid: PathLike | xr.DataArray, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Directional filtering of grids in the space domain. @@ -46,6 +52,7 @@ def dimfilter( Full GMT docs at :gmt-docs:`dimfilter.html`. {aliases} + - V = verbose Parameters ---------- @@ -143,13 +150,19 @@ def dimfilter( "distance, filters, or sectors." ) raise GMTInvalidInput(msg) + + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="dimfilter", args=build_arg_list(kwargs, infile=vingrd) + module="dimfilter", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/filter1d.py b/pygmt/src/filter1d.py index e0ed391f096..101cd9c9f1d 100644 --- a/pygmt/src/filter1d.py +++ b/pygmt/src/filter1d.py @@ -7,6 +7,7 @@ import numpy as np import pandas as pd from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -18,15 +19,13 @@ @fmt_docstring -@use_alias( - E="end", - F="filter_type", - N="time_col", -) +@use_alias(E="end", F="filter_type", N="time_col") def filter1d( data: PathLike | TableLike, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -43,6 +42,7 @@ def filter1d( Full GMT docs at :gmt-docs:`filter1d.html`. {aliases} + - V = verbose Parameters ---------- @@ -117,6 +117,11 @@ def filter1d( output_type = validate_output_table_type(output_type, outfile=outfile) + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="vector", data=data) as vintbl, @@ -124,6 +129,6 @@ def filter1d( ): lib.call_module( module="filter1d", - args=build_arg_list(kwargs, infile=vintbl, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=vintbl, outfile=vouttbl), ) return lib.virtualfile_to_dataset(vfname=vouttbl, output_type=output_type) diff --git a/pygmt/src/grd2cpt.py b/pygmt/src/grd2cpt.py index bf1b6197eaa..c85dd7f9a4e 100644 --- a/pygmt/src/grd2cpt.py +++ b/pygmt/src/grd2cpt.py @@ -2,6 +2,8 @@ grd2cpt - Make linear or histogram-equalized color palette table from grid. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike from pygmt.alias import Alias, AliasSystem @@ -24,7 +26,6 @@ L="limit", R="region", T="series", - V="verbose", W="categorical", Ww="cyclic", ) @@ -36,6 +37,8 @@ def grd2cpt( no_bg: bool = False, log: bool = False, continuous: bool = False, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ): r""" @@ -87,6 +90,7 @@ def grd2cpt( - N = no_bg - Q = log - Z = continuous + - V = verbose Parameters ---------- @@ -205,7 +209,10 @@ def grd2cpt( N=Alias(no_bg, name="no_bg"), Q=Alias(log, name="log"), Z=Alias(continuous, name="continuous"), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: diff --git a/pygmt/src/grd2xyz.py b/pygmt/src/grd2xyz.py index 57cf1ccf152..67cad34e2b6 100644 --- a/pygmt/src/grd2xyz.py +++ b/pygmt/src/grd2xyz.py @@ -8,6 +8,7 @@ import pandas as pd import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTValueError from pygmt.helpers import ( @@ -25,7 +26,6 @@ @use_alias( C="cstyle", R="region", - V="verbose", W="weight", Z="convention", b="binary", @@ -40,6 +40,8 @@ def grd2xyz( grid: PathLike | xr.DataArray, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -51,6 +53,7 @@ def grd2xyz( Full GMT docs at :gmt-docs:`grd2xyz.html`. {aliases} + - V = verbose Parameters ---------- @@ -157,6 +160,11 @@ def grd2xyz( # Reverse the dims because it is rows, columns ordered. column_names = [str(grid.dims[1]), str(grid.dims[0]), str(grid.name)] + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, @@ -164,7 +172,7 @@ def grd2xyz( ): lib.call_module( module="grd2xyz", - args=build_arg_list(kwargs, infile=vingrd, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=vingrd, outfile=vouttbl), ) return lib.virtualfile_to_dataset( vfname=vouttbl, output_type=output_type, column_names=column_names diff --git a/pygmt/src/grdclip.py b/pygmt/src/grdclip.py index 4ba3cc82561..14a8dc89a4a 100644 --- a/pygmt/src/grdclip.py +++ b/pygmt/src/grdclip.py @@ -3,6 +3,7 @@ """ from collections.abc import Sequence +from typing import Literal import xarray as xr from pygmt._typing import PathLike @@ -23,7 +24,7 @@ # TODO(PyGMT>=0.19.0): Remove the deprecated "new" parameter. @fmt_docstring @deprecate_parameter("new", "replace", "v0.15.0", remove_version="v0.19.0") -@use_alias(R="region", V="verbose") +@use_alias(R="region") @kwargs_to_strings(R="sequence") def grdclip( grid: PathLike | xr.DataArray, @@ -32,6 +33,8 @@ def grdclip( below: Sequence[float] | None = None, between: Sequence[float] | Sequence[Sequence[float]] | None = None, replace: Sequence[float] | Sequence[Sequence[float]] | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: """ @@ -56,6 +59,7 @@ def grdclip( - Sb = below - Si = between - Sr = replace + - V = verbose Parameters ---------- @@ -120,7 +124,10 @@ def grdclip( Sb=Alias(below, name="below", sep="/", size=2), Si=Alias(between, name="between", sep="/", size=3, ndim=2), Sr=Alias(replace, name="replace", sep="/", size=2, ndim=2), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: with ( diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index fea7af3e88f..6cc4c9404e2 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -2,6 +2,8 @@ grdcontour - Make contour map using a grid. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike from pygmt.alias import AliasSystem @@ -29,7 +31,6 @@ Q="cut", R="region", S="resample", - V="verbose", W="pen", l="label", f="coltypes", @@ -41,6 +42,8 @@ def grdcontour( self, grid: PathLike | xr.DataArray, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -53,6 +56,7 @@ def grdcontour( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -160,6 +164,7 @@ def grdcontour( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/grdcut.py b/pygmt/src/grdcut.py index 45fc5203f69..d38d2aac8ab 100644 --- a/pygmt/src/grdcut.py +++ b/pygmt/src/grdcut.py @@ -25,7 +25,6 @@ R="region", N="extend", S="circ_subregion", - V="verbose", Z="z_subregion", f="coltypes", ) @@ -35,6 +34,8 @@ def grdcut( kind: Literal["grid", "image"] = "grid", outgrid: PathLike | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -53,6 +54,7 @@ def grdcut( {aliases} - J = projection + - V = verbose Parameters ---------- @@ -128,6 +130,7 @@ def grdcut( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/grdfill.py b/pygmt/src/grdfill.py index a2c04691e8b..b0962641071 100644 --- a/pygmt/src/grdfill.py +++ b/pygmt/src/grdfill.py @@ -3,6 +3,7 @@ """ import warnings +from typing import Literal import numpy as np import xarray as xr @@ -76,7 +77,7 @@ def _validate_params( # TODO(PyGMT>=0.19.0): Remove the deprecated 'no_data' parameter. # TODO(PyGMT>=0.19.0): Remove the deprecated 'mode' parameter. @deprecate_parameter("no_data", "hole", "v0.15.0", remove_version="v0.19.0") -@use_alias(N="hole", R="region", V="verbose", f="coltypes") +@use_alias(N="hole", R="region", f="coltypes") @kwargs_to_strings(R="sequence") def grdfill( grid: PathLike | xr.DataArray, @@ -87,6 +88,8 @@ def grdfill( splinefill: float | bool | None = None, inquire: bool = False, mode: str | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | np.ndarray | None: r""" @@ -106,6 +109,7 @@ def grdfill( - An = neighborfill - As = splinefill - L = inquire + - V = verbose Parameters ---------- @@ -183,7 +187,10 @@ def grdfill( An=Alias(neighborfill, name="neighborfill"), As=Alias(splinefill, name="splinefill"), L=Alias(inquire, name="inquire"), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: diff --git a/pygmt/src/grdfilter.py b/pygmt/src/grdfilter.py index 93653da737c..68d620f0a6e 100644 --- a/pygmt/src/grdfilter.py +++ b/pygmt/src/grdfilter.py @@ -2,8 +2,11 @@ grdfilter - Filter a grid in the space (or time) domain. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -16,14 +19,17 @@ N="nans", R="region", T="toggle", - V="verbose", f="coltypes", r="registration", x="cores", ) @kwargs_to_strings(I="sequence", R="sequence") def grdfilter( - grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, **kwargs + grid: PathLike | xr.DataArray, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Filter a grid in the space (or time) domain. @@ -41,6 +47,7 @@ def grdfilter( Full GMT docs at :gmt-docs:`grdfilter.html`. {aliases} + - V = verbose Parameters ---------- @@ -128,13 +135,18 @@ def grdfilter( >>> grid = pygmt.datasets.load_earth_relief() >>> smooth_field = pygmt.grdfilter(grid=grid, filter="g600", distance="4") """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="grdfilter", args=build_arg_list(kwargs, infile=vingrd) + module="grdfilter", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index f2a87a4dc8a..f0862ee276e 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -2,8 +2,11 @@ grdgradient - Compute directional gradients from a grid. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -26,13 +29,16 @@ Q="tiles", R="region", S="slope_file", - V="verbose", f="coltypes", n="interpolation", ) @kwargs_to_strings(A="sequence", E="sequence", R="sequence") def grdgradient( - grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, **kwargs + grid: PathLike | xr.DataArray, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Compute directional gradients from a grid. @@ -43,6 +49,7 @@ def grdgradient( Full GMT docs at :gmt-docs:`grdgradient.html`. {aliases} + - V = verbose Parameters ---------- @@ -170,13 +177,19 @@ def grdgradient( "azimuth, direction, or radiance." ) raise GMTInvalidInput(msg) + + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="grdgradient", args=build_arg_list(kwargs, infile=vingrd) + module="grdgradient", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/grdhisteq.py b/pygmt/src/grdhisteq.py index bcca0aa232f..77b86a15df5 100644 --- a/pygmt/src/grdhisteq.py +++ b/pygmt/src/grdhisteq.py @@ -8,6 +8,7 @@ import pandas as pd import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -59,12 +60,17 @@ class grdhisteq: # noqa: N801 R="region", N="gaussian", Q="quadratic", - V="verbose", h="header", ) @kwargs_to_strings(R="sequence") def equalize_grid( - grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, **kwargs + grid: PathLike | xr.DataArray, + outgrid: PathLike | None = None, + verbose: Literal[ + "quiet", "error", "warning", "timing", "info", "compat", "debug" + ] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Perform histogram equalization for a grid. @@ -78,6 +84,7 @@ def equalize_grid( Full GMT docs at :gmt-docs:`grdhisteq.html`. {aliases} + - V = verbose Parameters ---------- @@ -123,14 +130,19 @@ def equalize_grid( This method does a weighted histogram equalization for geographic grids to account for node area varying with latitude. """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="grdhisteq", args=build_arg_list(kwargs, infile=vingrd) + module="grdhisteq", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) @@ -141,7 +153,6 @@ def equalize_grid( R="region", N="gaussian", Q="quadratic", - V="verbose", h="header", ) @kwargs_to_strings(R="sequence") @@ -149,6 +160,10 @@ def compute_bins( grid: PathLike | xr.DataArray, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal[ + "quiet", "error", "warning", "timing", "info", "compat", "debug" + ] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -171,6 +186,7 @@ def compute_bins( Full GMT docs at :gmt-docs:`grdhisteq.html`. {aliases} + - V = verbose Parameters ---------- @@ -230,14 +246,19 @@ def compute_bins( msg = "'header' is only allowed with output_type='file'." raise GMTInvalidInput(msg) + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl, ): - kwargs["D"] = vouttbl # -D for output file name + aliasdict["D"] = vouttbl # -D for output file name lib.call_module( - module="grdhisteq", args=build_arg_list(kwargs, infile=vingrd) + module="grdhisteq", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_dataset( diff --git a/pygmt/src/grdimage.py b/pygmt/src/grdimage.py index 2285f29d11f..473d9ebb455 100644 --- a/pygmt/src/grdimage.py +++ b/pygmt/src/grdimage.py @@ -2,6 +2,8 @@ grdimage - Project and plot grids or images. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike from pygmt.alias import AliasSystem @@ -23,7 +25,6 @@ N="no_clip", Q="nan_transparent", R="region", - V="verbose", n="interpolation", f="coltypes", p="perspective", @@ -35,6 +36,8 @@ def grdimage( self, grid: PathLike | xr.DataArray, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -73,6 +76,7 @@ def grdimage( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -169,6 +173,7 @@ def grdimage( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/grdinfo.py b/pygmt/src/grdinfo.py index 97eb070bb2d..ec09317023e 100644 --- a/pygmt/src/grdinfo.py +++ b/pygmt/src/grdinfo.py @@ -2,8 +2,11 @@ grdinfo - Extract information from 2-D grids or 3-D cubes. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import ( GMTTempFile, @@ -24,11 +27,15 @@ M="minmax_pos", R="region", T="nearest_multiple", - V="verbose", f="coltypes", ) @kwargs_to_strings(D="sequence", I="sequence", R="sequence") -def grdinfo(grid: PathLike | xr.DataArray, **kwargs) -> str: +def grdinfo( + grid: PathLike | xr.DataArray, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +) -> str: r""" Extract information from 2-D grids or 3-D cubes. @@ -37,6 +44,7 @@ def grdinfo(grid: PathLike | xr.DataArray, **kwargs) -> str: Full GMT docs at :gmt-docs:`grdinfo.html`. {aliases} + - V = verbose Parameters ---------- @@ -112,12 +120,17 @@ def grdinfo(grid: PathLike | xr.DataArray, **kwargs) -> str: info : str A string with information about the grid. """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with GMTTempFile() as outfile: with Session() as lib: with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd: lib.call_module( module="grdinfo", - args=build_arg_list(kwargs, infile=vingrd, outfile=outfile.name), + args=build_arg_list(aliasdict, infile=vingrd, outfile=outfile.name), ) result = outfile.read() return result diff --git a/pygmt/src/grdlandmask.py b/pygmt/src/grdlandmask.py index 24bd4538a86..3ed97b3dba5 100644 --- a/pygmt/src/grdlandmask.py +++ b/pygmt/src/grdlandmask.py @@ -25,7 +25,6 @@ A="area_thresh", I="spacing", R="region", - V="verbose", r="registration", x="cores", ) @@ -37,6 +36,8 @@ def grdlandmask( resolution: Literal[ "auto", "full", "high", "intermediate", "low", "crude", None ] = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -54,6 +55,7 @@ def grdlandmask( - D = resolution - E = bordervalues - N = maskvalues + - V = verbose Parameters ---------- @@ -132,7 +134,10 @@ def grdlandmask( ), N=Alias(maskvalues, name="maskvalues", sep="/", size=(2, 5)), E=Alias(bordervalues, name="bordervalues", sep="/", size=4), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd: diff --git a/pygmt/src/grdproject.py b/pygmt/src/grdproject.py index 844efe68784..81456d9477d 100644 --- a/pygmt/src/grdproject.py +++ b/pygmt/src/grdproject.py @@ -2,6 +2,8 @@ grdproject - Forward and inverse map transformation of grids. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike from pygmt.alias import AliasSystem @@ -21,7 +23,6 @@ I="inverse", M="unit", R="region", - V="verbose", n="interpolation", r="registration", ) @@ -30,6 +31,8 @@ def grdproject( grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -54,6 +57,7 @@ def grdproject( {aliases} - J = projection + - V = verbose Parameters ---------- @@ -115,6 +119,7 @@ def grdproject( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index c5d6ae548aa..b355ba546d1 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -2,8 +2,11 @@ grdsample - Resample a grid onto a new lattice. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -15,7 +18,6 @@ I="spacing", R="region", T="translate", - V="verbose", f="coltypes", n="interpolation", r="registration", @@ -23,7 +25,11 @@ ) @kwargs_to_strings(I="sequence", R="sequence") def grdsample( - grid: PathLike | xr.DataArray, outgrid: PathLike | None = None, **kwargs + grid: PathLike | xr.DataArray, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Resample a grid onto a new lattice. @@ -44,6 +50,7 @@ def grdsample( Full GMT docs at :gmt-docs:`grdsample.html`. {aliases} + - V = verbose Parameters ---------- @@ -83,13 +90,18 @@ def grdsample( >>> # and set both x- and y-spacings to 0.5 arc-degrees >>> new_grid = pygmt.grdsample(grid=grid, translate=True, spacing=[0.5, 0.5]) """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="grdsample", args=build_arg_list(kwargs, infile=vingrd) + module="grdsample", args=build_arg_list(aliasdict, infile=vingrd) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/grdtrack.py b/pygmt/src/grdtrack.py index 23106a10217..dbd059f20ec 100644 --- a/pygmt/src/grdtrack.py +++ b/pygmt/src/grdtrack.py @@ -8,6 +8,7 @@ import pandas as pd import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -32,7 +33,6 @@ N="no_skip", S="stack", T="radius", - V="verbose", Z="z_only", a="aspatial", b="binary", @@ -55,6 +55,8 @@ def grdtrack( output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, newcolname=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -77,6 +79,7 @@ def grdtrack( Full GMT docs at :gmt-docs:`grdtrack.html`. {aliases} + - V = verbose Parameters ---------- @@ -309,6 +312,11 @@ def grdtrack( if output_type == "pandas" and isinstance(points, pd.DataFrame): column_names = [*points.columns.to_list(), newcolname] + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, @@ -317,10 +325,10 @@ def grdtrack( ) as vintbl, lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl, ): - kwargs["G"] = vingrd + aliasdict["G"] = vingrd lib.call_module( module="grdtrack", - args=build_arg_list(kwargs, infile=vintbl, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=vintbl, outfile=vouttbl), ) return lib.virtualfile_to_dataset( vfname=vouttbl, diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 293dc4cb3ca..4b95a4f46c0 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -2,6 +2,8 @@ grdview - Create 3-D perspective image or surface mesh from a grid. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike from pygmt.alias import AliasSystem @@ -25,7 +27,6 @@ Wm="meshpen", Wf="facadepen", I="shading", - V="verbose", f="coltypes", n="interpolation", p="perspective", @@ -36,6 +37,8 @@ def grdview( self, grid: PathLike | xr.DataArray, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -52,6 +55,7 @@ def grdview( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -151,6 +155,7 @@ def grdview( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/grdvolume.py b/pygmt/src/grdvolume.py index b8833016996..986b4d4c7a3 100644 --- a/pygmt/src/grdvolume.py +++ b/pygmt/src/grdvolume.py @@ -8,6 +8,7 @@ import pandas as pd import xarray as xr from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import ( build_arg_list, @@ -21,17 +22,14 @@ @fmt_docstring -@use_alias( - C="contour", - R="region", - S="unit", - V="verbose", -) +@use_alias(C="contour", R="region", S="unit") @kwargs_to_strings(C="sequence", R="sequence") def grdvolume( grid: PathLike | xr.DataArray, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -46,6 +44,7 @@ def grdvolume( Full GMT docs at :gmt-docs:`grdvolume.html`. {aliases} + - V = verbose Parameters ---------- @@ -104,6 +103,11 @@ def grdvolume( """ output_type = validate_output_table_type(output_type, outfile=outfile) + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, @@ -111,6 +115,6 @@ def grdvolume( ): lib.call_module( module="grdvolume", - args=build_arg_list(kwargs, infile=vingrd, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=vingrd, outfile=vouttbl), ) return lib.virtualfile_to_dataset(vfname=vouttbl, output_type=output_type) diff --git a/pygmt/src/histogram.py b/pygmt/src/histogram.py index 816c275b5f0..20487b9e58d 100644 --- a/pygmt/src/histogram.py +++ b/pygmt/src/histogram.py @@ -2,6 +2,8 @@ Histogram - Calculate and plot histograms. """ +from typing import Literal + from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -23,7 +25,6 @@ R="region", S="stairs", T="series", - V="verbose", W="pen", Z="histtype", b="binary", @@ -41,6 +42,8 @@ def histogram( self, data: PathLike | TableLike, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -51,6 +54,7 @@ def histogram( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -144,6 +148,7 @@ def histogram( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/image.py b/pygmt/src/image.py index c036839d3d1..65aa031b3d8 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -2,6 +2,8 @@ image - Plot raster or EPS images. """ +from typing import Literal + from pygmt._typing import PathLike from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -15,7 +17,6 @@ G="bitcolor", M="monochrome", R="region", - V="verbose", p="perspective", t="transparency", ) @@ -24,6 +25,8 @@ def image( self, imagefile: PathLike, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -37,6 +40,7 @@ def image( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -79,6 +83,7 @@ def image( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/info.py b/pygmt/src/info.py index 2a05f6df0ce..6c49bf42696 100644 --- a/pygmt/src/info.py +++ b/pygmt/src/info.py @@ -2,8 +2,11 @@ info - Get information about data tables. """ +from typing import Literal + import numpy as np from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import ( GMTTempFile, @@ -19,14 +22,18 @@ C="per_column", I="spacing", T="nearest_multiple", - V="verbose", a="aspatial", f="coltypes", i="incols", r="registration", ) @kwargs_to_strings(I="sequence", i="sequence_comma") -def info(data: PathLike | TableLike, **kwargs) -> np.ndarray | str: +def info( + data: PathLike | TableLike, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +) -> np.ndarray | str: r""" Get information about data tables. @@ -46,6 +53,7 @@ def info(data: PathLike | TableLike, **kwargs) -> np.ndarray | str: Full GMT docs at :gmt-docs:`gmtinfo.html`. {aliases} + - V = verbose Parameters ---------- @@ -81,12 +89,17 @@ def info(data: PathLike | TableLike, **kwargs) -> np.ndarray | str: - :class:`numpy.ndarray` if either of the above parameters are used. - str if none of the above parameters are used. """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with GMTTempFile() as tmpfile: with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: lib.call_module( module="info", - args=build_arg_list(kwargs, infile=vintbl, outfile=tmpfile.name), + args=build_arg_list(aliasdict, infile=vintbl, outfile=tmpfile.name), ) result = tmpfile.read() diff --git a/pygmt/src/inset.py b/pygmt/src/inset.py index 582b716bf78..ef9fe5aeca4 100644 --- a/pygmt/src/inset.py +++ b/pygmt/src/inset.py @@ -3,6 +3,7 @@ """ import contextlib +from typing import Literal from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -19,10 +20,15 @@ M="margin", N="no_clip", R="region", - V="verbose", ) @kwargs_to_strings(D="sequence", M="sequence", R="sequence") -def inset(self, projection=None, **kwargs): +def inset( + self, + projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +): r""" Manage figure inset setup and completion. @@ -34,6 +40,7 @@ def inset(self, projection=None, **kwargs): {aliases} - J = projection + - V = verbose Parameters ---------- @@ -139,6 +146,7 @@ def inset(self, projection=None, **kwargs): aliasdict = AliasSystem().add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/legend.py b/pygmt/src/legend.py index 4eb620e97cf..e5653601a61 100644 --- a/pygmt/src/legend.py +++ b/pygmt/src/legend.py @@ -3,6 +3,7 @@ """ import io +from typing import Literal from pygmt._typing import PathLike from pygmt.alias import AliasSystem @@ -23,7 +24,6 @@ R="region", D="position", F="box", - V="verbose", p="perspective", t="transparency", ) @@ -34,6 +34,8 @@ def legend( projection=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -50,6 +52,7 @@ def legend( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -102,6 +105,7 @@ def legend( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/logo.py b/pygmt/src/logo.py index 43321df874f..1e097dda9b4 100644 --- a/pygmt/src/logo.py +++ b/pygmt/src/logo.py @@ -2,6 +2,8 @@ logo - Plot the GMT logo. """ +from typing import Literal + from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -13,11 +15,17 @@ D="position", F="box", S="style", - V="verbose", t="transparency", ) @kwargs_to_strings(R="sequence", p="sequence") -def logo(self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs): +def logo( + self, + projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + panel: int | tuple[int, int] | bool = False, + **kwargs, +): r""" Plot the GMT logo. @@ -30,6 +38,7 @@ def logo(self, projection=None, panel: int | tuple[int, int] | bool = False, **k {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -59,6 +68,7 @@ def logo(self, projection=None, panel: int | tuple[int, int] | bool = False, **k aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/makecpt.py b/pygmt/src/makecpt.py index 259d8fdc63a..394cdaa9e97 100644 --- a/pygmt/src/makecpt.py +++ b/pygmt/src/makecpt.py @@ -2,6 +2,8 @@ makecpt - Make GMT color palette tables. """ +from typing import Literal + from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput @@ -17,7 +19,6 @@ H="output", I="reverse", T="series", - V="verbose", W="categorical", Ww="cyclic", ) @@ -28,6 +29,8 @@ def makecpt( no_bg: bool = False, log: bool = False, continuous: bool = False, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ): r""" @@ -75,6 +78,7 @@ def makecpt( - N = no_bg - Q = log - Z = continuous + - V = verbose Parameters ---------- @@ -176,7 +180,10 @@ def makecpt( N=Alias(no_bg, name="no_bg"), Q=Alias(log, name="log"), Z=Alias(continuous, name="continuous"), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: lib.call_module( diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 3b6c9efd1af..b2beebc8a8b 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -127,7 +127,6 @@ def _auto_offset(spec) -> bool: N="no_clip", R="region", T="nodal", - V="verbose", W="pen", p="perspective", t="transparency", @@ -146,6 +145,8 @@ def meca( # noqa: PLR0913 plot_latitude: float | Sequence[float] | None = None, event_name: str | Sequence[str] | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -203,6 +204,7 @@ def meca( # noqa: PLR0913 {aliases} - J = projection - S = scale/convention/component + - V = verbose - c = panel Parameters @@ -368,6 +370,7 @@ def meca( # noqa: PLR0913 aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index 1a83a82c3b5..48c6610e775 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -2,8 +2,11 @@ nearneighbor - Grid table data using a "Nearest neighbor" algorithm. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -17,7 +20,6 @@ N="sectors", R="region", S="search_radius", - V="verbose", a="aspatial", b="binary", d="nodata", @@ -36,6 +38,8 @@ def nearneighbor( y=None, z=None, outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -75,6 +79,7 @@ def nearneighbor( Full GMT docs at :gmt-docs:`nearneighbor.html`. {aliases} + - V = verbose Parameters ---------- @@ -144,6 +149,11 @@ def nearneighbor( ... search_radius="10m", ... ) """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in( @@ -151,8 +161,8 @@ def nearneighbor( ) as vintbl, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="nearneighbor", args=build_arg_list(kwargs, infile=vintbl) + module="nearneighbor", args=build_arg_list(aliasdict, infile=vintbl) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index d71a0482acc..b4a04653570 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -33,7 +33,6 @@ N="no_clip", R="region", S="style", - V="verbose", W="pen", Z="zvalue", a="aspatial", @@ -50,7 +49,7 @@ w="wrap", ) @kwargs_to_strings(R="sequence", i="sequence_comma", p="sequence") -def plot( # noqa: PLR0912 +def plot( # noqa: PLR0912, PLR0913 self, data: PathLike | TableLike | None = None, x=None, @@ -60,6 +59,8 @@ def plot( # noqa: PLR0912 direction=None, straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001 projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -88,6 +89,7 @@ def plot( # noqa: PLR0912 {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -286,6 +288,7 @@ def plot( # noqa: PLR0912 aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index b90704561cb..50f27c497a7 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -34,7 +34,6 @@ Q="no_sort", R="region", S="style", - V="verbose", W="pen", Z="zvalue", a="aspatial", @@ -62,6 +61,8 @@ def plot3d( # noqa: PLR0912, PLR0913 direction=None, straight_line: bool | Literal["x", "y"] = False, # noqa: ARG001 projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -90,6 +91,7 @@ def plot3d( # noqa: PLR0912, PLR0913 {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -265,6 +267,7 @@ def plot3d( # noqa: PLR0912, PLR0913 aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 73317598328..8fc5018313c 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -7,6 +7,7 @@ import numpy as np import pandas as pd from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -30,7 +31,6 @@ Q="unit", S="sort", T="pole", - V="verbose", W="width", Z="ellipse", f="coltypes", @@ -43,6 +43,8 @@ def project( z=None, output_type: Literal["pandas", "numpy", "file"] = "pandas", outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -110,6 +112,7 @@ def project( Full GMT docs at :gmt-docs:`project.html`. {aliases} + - V = verbose Parameters ---------- @@ -238,6 +241,11 @@ def project( if output_type == "pandas" and kwargs.get("G") is not None: column_names = list("rsp") + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in( @@ -253,7 +261,7 @@ def project( ): lib.call_module( module="project", - args=build_arg_list(kwargs, infile=vintbl, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=vintbl, outfile=vouttbl), ) return lib.virtualfile_to_dataset( vfname=vouttbl, diff --git a/pygmt/src/psconvert.py b/pygmt/src/psconvert.py index cd562c10887..73e6cc84faf 100644 --- a/pygmt/src/psconvert.py +++ b/pygmt/src/psconvert.py @@ -4,6 +4,7 @@ from collections.abc import Sequence from pathlib import Path +from typing import Literal from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session @@ -12,13 +13,15 @@ @fmt_docstring -@use_alias(A="crop", I="resize", N="bb_style", T="fmt", Q="anti_aliasing", V="verbose") +@use_alias(A="crop", I="resize", N="bb_style", T="fmt", Q="anti_aliasing") def psconvert( self, prefix: str | None = None, dpi: int | None = None, gs_option: str | Sequence[str] | None = None, gs_path: str | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ): r""" @@ -38,6 +41,7 @@ def psconvert( - E = dpi - F = prefix - G = gs_path + - V = verbose Parameters ---------- @@ -133,7 +137,10 @@ def psconvert( E=Alias(dpi, name="dpi"), F=Alias(prefix, name="prefix"), G=Alias(gs_path, name="gs_path"), - ).merge(kwargs) + ).add_common( + V=verbose, + ) + aliasdict.merge(kwargs) with Session() as lib: lib.call_module(module="psconvert", args=build_arg_list(aliasdict)) diff --git a/pygmt/src/rose.py b/pygmt/src/rose.py index baf8af78b1e..c87e3dced5f 100644 --- a/pygmt/src/rose.py +++ b/pygmt/src/rose.py @@ -2,6 +2,8 @@ rose - Plot a polar histogram (rose, sector, windrose diagrams). """ +from typing import Literal + from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -25,7 +27,6 @@ R="region", S="norm", T="orientation", - V="verbose", W="pen", Z="scale", b="binary", @@ -43,6 +44,8 @@ def rose( data: PathLike | TableLike | None = None, length=None, azimuth=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -62,6 +65,7 @@ def rose( Full GMT docs at :gmt-docs:`rose.html`. {aliases} + - V = verbose - c = panel Parameters @@ -203,6 +207,7 @@ def rose( self._activate_figure() aliasdict = AliasSystem().add_common( + V=verbose, c=panel, ) aliasdict.merge(kwargs) @@ -211,4 +216,6 @@ def rose( with lib.virtualfile_in( check_kind="vector", data=data, x=length, y=azimuth ) as vintbl: - lib.call_module(module="rose", args=build_arg_list(kwargs, infile=vintbl)) + lib.call_module( + module="rose", args=build_arg_list(aliasdict, infile=vintbl) + ) diff --git a/pygmt/src/select.py b/pygmt/src/select.py index 770ce98cec8..d894d8dd771 100644 --- a/pygmt/src/select.py +++ b/pygmt/src/select.py @@ -30,7 +30,6 @@ L="dist2line", N="mask", R="region", - V="verbose", Z="z_subregion", b="binary", d="nodata", @@ -52,6 +51,8 @@ def select( "auto", "full", "high", "intermediate", "low", "crude", None ] = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | np.ndarray | None: r""" @@ -78,6 +79,7 @@ def select( {aliases} - D = resolution - J = projection + - V = verbose Parameters ---------- @@ -231,6 +233,7 @@ def select( ), ).add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index 74071724439..4d7811c5ec9 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -18,7 +18,6 @@ B="frame", G="fill", R="region", - V="verbose", W="pen", p="perspective", t="transparency", @@ -29,6 +28,8 @@ def solar( terminator: Literal["astronomical", "civil", "day_night", "nautical"] = "day_night", terminator_datetime=None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -43,6 +44,7 @@ def solar( {aliases} - J = projection - T = terminator, **+d**: terminator_datetime + - V = verbose - c = panel Parameters @@ -126,6 +128,7 @@ def solar( ], ).add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/sph2grd.py b/pygmt/src/sph2grd.py index a764bd231fc..8db59093a37 100644 --- a/pygmt/src/sph2grd.py +++ b/pygmt/src/sph2grd.py @@ -2,8 +2,11 @@ sph2grd - Compute grid from spherical harmonic coefficients. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -14,7 +17,6 @@ @use_alias( I="spacing", R="region", - V="verbose", b="binary", h="header", i="incols", @@ -23,7 +25,11 @@ ) @kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma") def sph2grd( - data: PathLike | TableLike, outgrid: PathLike | None = None, **kwargs + data: PathLike | TableLike, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Compute grid from spherical harmonic coefficients. @@ -35,6 +41,7 @@ def sph2grd( Full GMT docs at :gmt-docs:`sph2grd.html`. {aliases} + - V = verbose Parameters ---------- @@ -68,13 +75,18 @@ def sph2grd( >>> # set the grid spacing to 1 arc-degree, and the region to global ("g") >>> new_grid = pygmt.sph2grd(data="@EGM96_to_36.txt", spacing=1, region="g") """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="vector", data=data) as vintbl, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="sph2grd", args=build_arg_list(kwargs, infile=vintbl) + module="sph2grd", args=build_arg_list(aliasdict, infile=vintbl) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index bec132b3ed8..243968e3249 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -3,8 +3,11 @@ sphere. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem 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 +25,6 @@ N="node_table", Q="voronoi", R="region", - V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") def sphdistance( @@ -30,6 +32,8 @@ def sphdistance( x=None, y=None, outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -43,6 +47,7 @@ def sphdistance( Full GMT docs at :gmt-docs:`sphdistance.html`. {aliases} + - V = verbose Parameters ---------- @@ -117,13 +122,19 @@ def sphdistance( if kwargs.get("I") is None or kwargs.get("R") is None: msg = "Both 'region' and 'spacing' must be specified." raise GMTInvalidInput(msg) + + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="vector", data=data, x=x, y=y) as vintbl, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="sphdistance", args=build_arg_list(kwargs, infile=vintbl) + module="sphdistance", args=build_arg_list(aliasdict, infile=vintbl) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index 0b6a3430dc9..3aad5e760ae 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -2,8 +2,11 @@ sphinterpolate - Spherical gridding in tension of data on a sphere. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -11,14 +14,14 @@ @fmt_docstring -@use_alias( - I="spacing", - R="region", - V="verbose", -) +@use_alias(I="spacing", R="region") @kwargs_to_strings(I="sequence", R="sequence") def sphinterpolate( - data: PathLike | TableLike, outgrid: PathLike | None = None, **kwargs + data: PathLike | TableLike, + outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, ) -> xr.DataArray | None: r""" Spherical gridding in tension of data on a sphere. @@ -32,6 +35,7 @@ def sphinterpolate( Full GMT docs at :gmt-docs:`sphinterpolate.html`. {aliases} + - V = verbose Parameters ---------- @@ -62,13 +66,18 @@ def sphinterpolate( >>> # to produce a grid with a 1 arc-degree spacing >>> grid = pygmt.sphinterpolate(data=mars_shape, spacing=1, region="g") """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in(check_kind="vector", data=data) as vintbl, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="sphinterpolate", args=build_arg_list(kwargs, infile=vintbl) + module="sphinterpolate", args=build_arg_list(aliasdict, infile=vintbl) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index 4c03737acbf..9829c52a6b2 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -3,6 +3,7 @@ """ import contextlib +from typing import Literal from pygmt.alias import AliasSystem from pygmt.clib import Session @@ -28,10 +29,17 @@ SC="sharex", SR="sharey", T="title", - V="verbose", ) @kwargs_to_strings(Ff="sequence", Fs="sequence", M="sequence", R="sequence") -def subplot(self, nrows=1, ncols=1, projection=None, **kwargs): +def subplot( + self, + nrows=1, + ncols=1, + projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +): r""" Manage figure subplot configuration and selection. @@ -45,6 +53,7 @@ def subplot(self, nrows=1, ncols=1, projection=None, **kwargs): {aliases} - J = projection + - V = verbose Parameters ---------- @@ -162,6 +171,7 @@ def subplot(self, nrows=1, ncols=1, projection=None, **kwargs): aliasdict = AliasSystem().add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) @@ -186,9 +196,15 @@ def subplot(self, nrows=1, ncols=1, projection=None, **kwargs): @fmt_docstring @contextlib.contextmanager -@use_alias(A="fixedlabel", C="clearance", V="verbose") +@use_alias(A="fixedlabel", C="clearance") @kwargs_to_strings(panel="sequence_comma") -def set_panel(self, panel=None, **kwargs): +def set_panel( + self, + panel=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +): r""" Set the current subplot panel to plot on. @@ -201,6 +217,7 @@ def set_panel(self, panel=None, **kwargs): ``projection="X"`` will fill the subplot by using unequal scales]. {aliases} + - V = verbose Parameters ---------- @@ -238,8 +255,13 @@ def set_panel(self, panel=None, **kwargs): """ self._activate_figure() + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: lib.call_module( - module="subplot", args=["set", str(panel), *build_arg_list(kwargs)] + module="subplot", args=["set", str(panel), *build_arg_list(aliasdict)] ) yield diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 2c9684a6676..cc351e9d875 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -2,8 +2,11 @@ surface - Grid table data using adjustable tension continuous curvature splines. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -19,7 +22,6 @@ M="maxradius", R="region", T="tension", - V="verbose", a="aspatial", b="binary", d="nodata", @@ -37,6 +39,8 @@ def surface( y=None, z=None, outgrid: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -72,6 +76,7 @@ def surface( Full GMT docs at :gmt-docs:`surface.html`. {aliases} + - V = verbose Parameters ---------- @@ -158,6 +163,11 @@ def surface( >>> # Perform gridding of topography data >>> grid = pygmt.surface(data=topography, spacing=1, region=[0, 4, 0, 8]) """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with ( lib.virtualfile_in( @@ -165,8 +175,8 @@ def surface( ) as vintbl, lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd, ): - kwargs["G"] = voutgrd + aliasdict["G"] = voutgrd lib.call_module( - module="surface", args=build_arg_list(kwargs, infile=vintbl) + module="surface", args=build_arg_list(aliasdict, infile=vintbl) ) return lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid) diff --git a/pygmt/src/ternary.py b/pygmt/src/ternary.py index 3dfdf130e93..25467df78ec 100644 --- a/pygmt/src/ternary.py +++ b/pygmt/src/ternary.py @@ -2,6 +2,8 @@ ternary - Plot data on ternary diagrams. """ +from typing import Literal + import pandas as pd from packaging.version import Version from pygmt._typing import PathLike, TableLike @@ -18,7 +20,6 @@ JX="width", R="region", S="style", - V="verbose", W="pen", p="perspective", t="transparency", @@ -30,6 +31,8 @@ def ternary( alabel: str | None = None, blabel: str | None = None, clabel: str | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -48,6 +51,7 @@ def ternary( {aliases} - L = alabel/blabel/clabel + - V = verbose - c = panel Parameters @@ -93,6 +97,7 @@ def ternary( aliasdict = AliasSystem( L=Alias(labels, name="alabel/blabel/clabel", sep="/", size=3), ).add_common( + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 688f822b823..cea6b0f2fbd 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -3,6 +3,7 @@ """ from collections.abc import Sequence +from typing import Literal import numpy as np from pygmt._typing import AnchorCode, PathLike, StringArrayTypes, TableLike @@ -29,7 +30,6 @@ D="offset", G="fill", N="no_clip", - V="verbose", W="pen", a="aspatial", e="find", @@ -52,6 +52,8 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 font=None, justify: bool | None | AnchorCode | Sequence[AnchorCode] = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -74,6 +76,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 {aliases} - F = **+a**: angle, **+c**: position, **+j**: justify, **+f**: font - J = projection + - V = verbose - c = panel Parameters @@ -267,6 +270,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index 88a7e14d266..69fdefdba95 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -25,12 +25,11 @@ N="no_clip", Q="nan_transparent", # R="region", - V="verbose", p="perspective", t="transparency", ) @kwargs_to_strings(p="sequence") # R="sequence", -def tilemap( +def tilemap( # noqa: PLR0913 self, region: list, zoom: int | Literal["auto"] = "auto", @@ -40,6 +39,8 @@ def tilemap( max_retries: int = 2, zoom_adjust: int | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -58,6 +59,7 @@ def tilemap( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -130,6 +132,7 @@ def tilemap( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index 1bb9712e113..0cd23ab4089 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -2,6 +2,8 @@ velo - Plot velocity vectors, crosses, anisotropy bars, and wedges. """ +from typing import Literal + import numpy as np import pandas as pd from pygmt._typing import PathLike, TableLike @@ -30,7 +32,6 @@ N="no_clip", R="region", S="spec", - V="verbose", W="pen", Z="zvalue", d="nodata", @@ -45,6 +46,8 @@ def velo( self, data: PathLike | TableLike | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -64,6 +67,7 @@ def velo( {aliases} - J = projection + - V = verbose - c = panel Parameters @@ -265,6 +269,7 @@ def velo( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/which.py b/pygmt/src/which.py index f2567bf2c39..b60952f77b3 100644 --- a/pygmt/src/which.py +++ b/pygmt/src/which.py @@ -3,15 +3,22 @@ """ from collections.abc import Sequence +from typing import Literal from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, is_nonstr_iter, use_alias @fmt_docstring -@use_alias(G="download", V="verbose") -def which(fname: PathLike | Sequence[PathLike], **kwargs) -> str | list[str]: +@use_alias(G="download") +def which( + fname: PathLike | Sequence[PathLike], + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +) -> str | list[str]: r""" Find full path to specified files. @@ -30,6 +37,7 @@ def which(fname: PathLike | Sequence[PathLike], **kwargs) -> str | list[str]: Full GMT docs at :gmt-docs:`gmtwhich.html`. {aliases} + - V = verbose Parameters ---------- @@ -60,11 +68,16 @@ def which(fname: PathLike | Sequence[PathLike], **kwargs) -> str | list[str]: FileNotFoundError If the file is not found. """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with lib.virtualfile_out(kind="dataset") as vouttbl: lib.call_module( module="which", - args=build_arg_list(kwargs, infile=fname, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=fname, outfile=vouttbl), ) paths = lib.virtualfile_to_dataset(vfname=vouttbl, output_type="strings") diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index f97da2c4c9f..25b43cb4b08 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -2,6 +2,8 @@ wiggle - Plot z=f(x,y) anomalies along tracks. """ +from typing import Literal + from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session @@ -41,7 +43,6 @@ def _parse_fills(fillpositive, fillnegative): D="position", R="region", T="track", - V="verbose", W="pen", Z="scale", b="binary", @@ -65,6 +66,8 @@ def wiggle( fillpositive=None, fillnegative=None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, panel: int | tuple[int, int] | bool = False, **kwargs, ): @@ -81,6 +84,7 @@ def wiggle( {aliases} - G = **+p**: fillpositive, **+n**: fillnegative - J = projection + - V = verbose - c = panel Parameters @@ -135,6 +139,7 @@ def wiggle( G=Alias(_fills, name="fillpositive/fillnegative"), ).add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) diff --git a/pygmt/src/x2sys_cross.py b/pygmt/src/x2sys_cross.py index 3c9d701e2ce..83cc77a8f3d 100644 --- a/pygmt/src/x2sys_cross.py +++ b/pygmt/src/x2sys_cross.py @@ -5,10 +5,11 @@ import contextlib import os from pathlib import Path -from typing import Any +from typing import Any, Literal import pandas as pd from pygmt._typing import PathLike +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.exceptions import GMTTypeError from pygmt.helpers import ( @@ -66,7 +67,6 @@ def tempfile_from_dftrack(track, suffix): S="speed", T="tag", Q="coe", - V="verbose", W="numpoints", Z="trackvalues", ) @@ -74,6 +74,8 @@ def tempfile_from_dftrack(track, suffix): def x2sys_cross( tracks=None, outfile: PathLike | None = None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> pd.DataFrame | None: r""" @@ -90,6 +92,7 @@ def x2sys_cross( Full GMT docs at :gmt-docs:`supplements/x2sys/x2sys_cross.html`. {aliases} + - V = verbose Parameters ---------- @@ -215,13 +218,18 @@ def x2sys_cross( case _: raise GMTTypeError(type(track)) + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: with lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl: with contextlib.ExitStack() as stack: fnames = [stack.enter_context(c) for c in file_contexts] lib.call_module( module="x2sys_cross", - args=build_arg_list(kwargs, infile=fnames, outfile=vouttbl), + args=build_arg_list(aliasdict, infile=fnames, outfile=vouttbl), ) result = lib.virtualfile_to_dataset( vfname=vouttbl, output_type=output_type, header=2 diff --git a/pygmt/src/x2sys_init.py b/pygmt/src/x2sys_init.py index 23d0478d31e..ff9711eb479 100644 --- a/pygmt/src/x2sys_init.py +++ b/pygmt/src/x2sys_init.py @@ -2,6 +2,9 @@ x2sys_init - Initialize a new x2sys track database. """ +from typing import Literal + +from pygmt.alias import AliasSystem from pygmt.clib import Session from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -15,12 +18,16 @@ I="spacing", N="units", R="region", - V="verbose", W="gap", j="distcalc", ) @kwargs_to_strings(I="sequence", R="sequence") -def x2sys_init(tag, **kwargs): +def x2sys_init( + tag, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, + **kwargs, +): r""" Initialize a new x2sys track database. @@ -37,6 +44,7 @@ def x2sys_init(tag, **kwargs): Full GMT docs at :gmt-docs:`supplements/x2sys/x2sys_init.html`. {aliases} + - V = verbose Parameters ---------- @@ -110,5 +118,10 @@ def x2sys_init(tag, **kwargs): {distcalc} """ + aliasdict = AliasSystem().add_common( + V=verbose, + ) + aliasdict.merge(kwargs) + with Session() as lib: - lib.call_module(module="x2sys_init", args=build_arg_list(kwargs, infile=tag)) + lib.call_module(module="x2sys_init", args=build_arg_list(aliasdict, infile=tag)) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 7cdd273d1d2..3103a8f6f5b 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -2,6 +2,8 @@ xyz2grd - Convert data table to a grid. """ +from typing import Literal + import xarray as xr from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem @@ -17,7 +19,6 @@ A="duplicate", I="spacing", R="region", - V="verbose", Z="convention", b="binary", d="nodata", @@ -36,6 +37,8 @@ def xyz2grd( z=None, outgrid: PathLike | None = None, projection=None, + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] + | bool = False, **kwargs, ) -> xr.DataArray | None: r""" @@ -51,6 +54,7 @@ def xyz2grd( {aliases} - J = projection + - V = verbose Parameters ---------- @@ -156,6 +160,7 @@ def xyz2grd( aliasdict = AliasSystem().add_common( J=projection, + V=verbose, ) aliasdict.merge(kwargs) diff --git a/pygmt/tests/test_alias_system.py b/pygmt/tests/test_alias_system.py index 3e951c6e4d7..3b288b93cfa 100644 --- a/pygmt/tests/test_alias_system.py +++ b/pygmt/tests/test_alias_system.py @@ -15,6 +15,7 @@ def func( label=None, text=None, offset=None, + verbose=None, panel=False, **kwargs, ): @@ -31,6 +32,7 @@ def func( ], ).add_common( J=projection, + V=verbose, c=panel, ) aliasdict.merge(kwargs) @@ -101,6 +103,21 @@ def test_alias_system_multiple_aliases_short_form(): func(text="efg", U="efg") +def test_alias_system_common_parameter_verbose(): + """ + Test that the alias system works with common parameters. + """ + # Test the verbose parameter. + assert func(verbose="quiet") == ["-Vq"] + assert func(verbose="error") == ["-Ve"] + assert func(verbose="warning") == ["-Vw"] + assert func(verbose="timing") == ["-Vt"] + assert func(verbose="info") == ["-Vi"] + assert func(verbose="compat") == ["-Vc"] + assert func(verbose=True) == ["-V"] + assert func(verbose="debug") == ["-Vd"] + + def test_alias_system_common_parameter_panel(): """ Test that the alias system works with the panel parameter. diff --git a/pygmt/tests/test_config.py b/pygmt/tests/test_config.py index 1468d7d7ae7..b946abeaea9 100644 --- a/pygmt/tests/test_config.py +++ b/pygmt/tests/test_config.py @@ -136,10 +136,10 @@ def test_config_map_grid_cross_size(): region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1], projection="X6c/2c", frame=["pa1Hg", "sa45mg45m", "NWse"], - verbose="e", + verbose="error", ) fig.shift_origin(yshift=-3) - fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e") + fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error") return fig @@ -155,10 +155,10 @@ def test_config_map_grid_pen(): region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1], projection="X6c/2c", frame=["pa1Hg", "sa45mg45m", "NWse"], - verbose="e", + verbose="error", ) fig.shift_origin(yshift=-3) - fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e") + fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error") return fig @@ -174,10 +174,10 @@ def test_config_map_tick_length(): region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1], projection="X6c/2c", frame=["pa1Hg", "sa45mg45m", "NWse"], - verbose="e", + verbose="error", ) fig.shift_origin(yshift=-3) - fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e") + fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error") return fig @@ -193,8 +193,8 @@ def test_config_map_tick_pen(): region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1], projection="X6c/2c", frame=["pa1Hg", "sa45mg45m", "NWse"], - verbose="e", + verbose="error", ) fig.shift_origin(yshift=-3) - fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="e") + fig.basemap(frame=["pa1Hg", "sa45mg45m", "nwSE"], verbose="error") return fig diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index b065137aa87..a468a1e4c2b 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -86,7 +86,7 @@ def test_surface_input_file(region, spacing, expected_grid): data="@Table_5_11_mean.xyz", spacing=spacing, region=region, - verbose="e", # Suppress warnings for IEEE 754 rounding + verbose="error", # Suppress warnings for IEEE 754 rounding ) check_values(output, expected_grid) @@ -100,7 +100,7 @@ def test_surface_input_data_array(data, region, spacing, expected_grid): data=data, spacing=spacing, region=region, - verbose="e", # Suppress warnings for IEEE 754 rounding + verbose="error", # Suppress warnings for IEEE 754 rounding ) check_values(output, expected_grid) @@ -116,7 +116,7 @@ def test_surface_input_xyz(data, region, spacing, expected_grid): z=data.z, spacing=spacing, region=region, - verbose="e", # Suppress warnings for IEEE 754 rounding + verbose="error", # Suppress warnings for IEEE 754 rounding ) check_values(output, expected_grid) @@ -141,7 +141,7 @@ def test_surface_with_outgrid_param(data, region, spacing, expected_grid): spacing=spacing, region=region, outgrid=tmpfile.name, - verbose="e", # Suppress warnings for IEEE 754 rounding + verbose="error", # Suppress warnings for IEEE 754 rounding ) assert output is None # check that output is None since outgrid is set assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists diff --git a/pygmt/xarray/backend.py b/pygmt/xarray/backend.py index 37500932b57..2f980d87caa 100644 --- a/pygmt/xarray/backend.py +++ b/pygmt/xarray/backend.py @@ -146,7 +146,7 @@ def open_dataset( # type: ignore[override] vfname=voutfile, kind=raster_kind ) # Add "source" encoding - source: str | list = which(fname=filename_or_obj, verbose="q") + source: str | list = which(fname=filename_or_obj, verbose="quiet") raster.encoding["source"] = ( sorted(source)[0] if isinstance(source, list) else source )