Skip to content

Commit 613b623

Browse files
authored
Migrate the parameter 'verbose' to the new alias system and let it support descriptive arguments (#4039)
1 parent 9a77ff2 commit 613b623

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+633
-160
lines changed

doc/techref/common_parameters.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
``verbose``
2323
Select verbosity level, which modulates the messages written to stderr.
2424
25-
Choose among 7 levels of verbosity [Default is ``"w"``]:
25+
Choose among 7 levels of verbosity [Default is ``"warning"``]:
2626
27-
- ``"q"``: Quiet, not even fatal error messages are produced
28-
- ``"e"``: Error messages only
29-
- ``"w"``: Warnings [Default]
30-
- ``"t"``: Timings (report runtimes for time-intensive algorithms)
31-
- ``"i"``: Informational messages (same as ``verbose=True``)
32-
- ``"c"``: Compatibility warnings
33-
- ``"d"``: Debugging messages
27+
- ``"quiet"``: Quiet, not even fatal error messages are produced
28+
- ``"error"``: Error messages only
29+
- ``"warning"``: Warnings [Default]
30+
- ``"timing"``: Timings (report runtimes for time-intensive algorithms)
31+
- ``"info"``: Informational messages (same as ``verbose=True``)
32+
- ``"compat"``: Compatibility warnings
33+
- ``"debug"``: Debugging messages
3434
```

pygmt/alias.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ class AliasSystem(UserDict):
217217
>>> from pygmt.helpers import build_arg_list
218218
>>>
219219
>>> def func(
220-
... par0, par1=None, par2=None, frame=False, repeat=None, panel=None, **kwargs
220+
... par0,
221+
... par1=None,
222+
... par2=None,
223+
... frame=False,
224+
... repeat=None,
225+
... panel=None,
226+
... verbose=None,
227+
... **kwargs,
221228
... ):
222229
... aliasdict = AliasSystem(
223230
... A=[
@@ -227,6 +234,7 @@ class AliasSystem(UserDict):
227234
... B=Alias(frame, name="frame"),
228235
... D=Alias(repeat, name="repeat"),
229236
... ).add_common(
237+
... V=verbose,
230238
... c=panel,
231239
... )
232240
... aliasdict.merge(kwargs)
@@ -238,9 +246,10 @@ class AliasSystem(UserDict):
238246
... frame=True,
239247
... repeat=[1, 2, 3],
240248
... panel=(1, 2),
249+
... verbose="debug",
241250
... J="X10c/10c",
242251
... )
243-
['-Amytext+o12/12', '-B', '-D1', '-D2', '-D3', '-JX10c/10c', '-c1,2']
252+
['-Amytext+o12/12', '-B', '-D1', '-D2', '-D3', '-JX10c/10c', '-Vd', '-c1,2']
244253
"""
245254

246255
def __init__(self, **kwargs):
@@ -276,6 +285,20 @@ def add_common(self, **kwargs):
276285
"""
277286
for key, value in kwargs.items():
278287
match key:
288+
case "V":
289+
alias = Alias(
290+
value,
291+
name="verbose",
292+
mapping={
293+
"quiet": "q",
294+
"error": "e",
295+
"warning": "w",
296+
"timing": "t",
297+
"info": "i",
298+
"compat": "c",
299+
"debug": "d",
300+
},
301+
)
279302
case "J":
280303
alias = Alias(value, name="projection")
281304
case "c":

pygmt/src/basemap.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
basemap - Plot base maps and frames.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.alias import AliasSystem
68
from pygmt.clib import Session
79
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -17,14 +19,18 @@
1719
F="box",
1820
Td="rose",
1921
Tm="compass",
20-
V="verbose",
2122
f="coltypes",
2223
p="perspective",
2324
t="transparency",
2425
)
2526
@kwargs_to_strings(R="sequence", p="sequence")
2627
def basemap(
27-
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
28+
self,
29+
projection=None,
30+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
31+
| bool = False,
32+
panel: int | tuple[int, int] | bool = False,
33+
**kwargs,
2834
):
2935
r"""
3036
Plot base maps and frames.
@@ -41,6 +47,7 @@ def basemap(
4147
4248
{aliases}
4349
- J = projection
50+
- V = verbose
4451
- c = panel
4552
4653
Parameters
@@ -89,6 +96,7 @@ def basemap(
8996

9097
aliasdict = AliasSystem().add_common(
9198
J=projection,
99+
V=verbose,
92100
c=panel,
93101
)
94102
aliasdict.merge(kwargs)

pygmt/src/binstats.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
N="normalize",
1919
R="region",
2020
S="search_radius",
21-
V="verbose",
2221
W="weight",
2322
a="aspatial",
2423
b="binary",
@@ -49,6 +48,8 @@ def binstats(
4948
"sum",
5049
] = "number",
5150
quantile_value: float = 50,
51+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
52+
| bool = False,
5253
**kwargs,
5354
) -> xr.DataArray | None:
5455
r"""
@@ -66,6 +67,7 @@ def binstats(
6667
6768
{aliases}
6869
- C = statistic
70+
- V = verbose
6971
7072
Parameters
7173
----------
@@ -151,7 +153,10 @@ def binstats(
151153
"sum": "z",
152154
},
153155
),
154-
).merge(kwargs)
156+
).add_common(
157+
V=verbose,
158+
)
159+
aliasdict.merge(kwargs)
155160
if statistic == "quantile":
156161
aliasdict["C"] += f"{quantile_value}"
157162

pygmt/src/blockm.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pandas as pd
99
from pygmt._typing import PathLike, TableLike
10+
from pygmt.alias import AliasSystem
1011
from pygmt.clib import Session
1112
from pygmt.helpers import (
1213
build_arg_list,
@@ -74,7 +75,6 @@ def _blockm(
7475
I="spacing",
7576
R="region",
7677
S="summary",
77-
V="verbose",
7878
a="aspatial",
7979
b="binary",
8080
d="nodata",
@@ -94,6 +94,8 @@ def blockmean(
9494
z=None,
9595
output_type: Literal["pandas", "numpy", "file"] = "pandas",
9696
outfile: PathLike | None = None,
97+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
98+
| bool = False,
9799
**kwargs,
98100
) -> pd.DataFrame | np.ndarray | None:
99101
r"""
@@ -111,6 +113,7 @@ def blockmean(
111113
Full GMT docs at :gmt-docs:`blockmean.html`.
112114
113115
{aliases}
116+
- V = verbose
114117
115118
Parameters
116119
----------
@@ -162,6 +165,11 @@ def blockmean(
162165
>>> # Calculate block mean values within 5 by 5 arc-minute bins
163166
>>> data_bmean = pygmt.blockmean(data=data, region=[245, 255, 20, 30], spacing="5m")
164167
"""
168+
aliasdict = AliasSystem().add_common(
169+
V=verbose,
170+
)
171+
aliasdict.merge(kwargs)
172+
165173
return _blockm(
166174
block_method="blockmean",
167175
data=data,
@@ -170,15 +178,14 @@ def blockmean(
170178
z=z,
171179
output_type=output_type,
172180
outfile=outfile,
173-
**kwargs,
181+
**aliasdict,
174182
)
175183

176184

177185
@fmt_docstring
178186
@use_alias(
179187
I="spacing",
180188
R="region",
181-
V="verbose",
182189
a="aspatial",
183190
b="binary",
184191
d="nodata",
@@ -198,6 +205,8 @@ def blockmedian(
198205
z=None,
199206
output_type: Literal["pandas", "numpy", "file"] = "pandas",
200207
outfile: PathLike | None = None,
208+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
209+
| bool = False,
201210
**kwargs,
202211
) -> pd.DataFrame | np.ndarray | None:
203212
r"""
@@ -215,6 +224,7 @@ def blockmedian(
215224
Full GMT docs at :gmt-docs:`blockmedian.html`.
216225
217226
{aliases}
227+
- V = verbose
218228
219229
Parameters
220230
----------
@@ -260,6 +270,11 @@ def blockmedian(
260270
... data=data, region=[245, 255, 20, 30], spacing="5m"
261271
... )
262272
"""
273+
aliasdict = AliasSystem().add_common(
274+
V=verbose,
275+
)
276+
aliasdict.merge(kwargs)
277+
263278
return _blockm(
264279
block_method="blockmedian",
265280
data=data,
@@ -268,15 +283,14 @@ def blockmedian(
268283
z=z,
269284
output_type=output_type,
270285
outfile=outfile,
271-
**kwargs,
286+
**aliasdict,
272287
)
273288

274289

275290
@fmt_docstring
276291
@use_alias(
277292
I="spacing",
278293
R="region",
279-
V="verbose",
280294
a="aspatial",
281295
b="binary",
282296
d="nodata",
@@ -296,6 +310,8 @@ def blockmode(
296310
z=None,
297311
output_type: Literal["pandas", "numpy", "file"] = "pandas",
298312
outfile: PathLike | None = None,
313+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
314+
| bool = False,
299315
**kwargs,
300316
) -> pd.DataFrame | np.ndarray | None:
301317
r"""
@@ -313,6 +329,7 @@ def blockmode(
313329
Full GMT docs at :gmt-docs:`blockmode.html`.
314330
315331
{aliases}
332+
- V = verbose
316333
317334
Parameters
318335
----------
@@ -356,6 +373,11 @@ def blockmode(
356373
>>> # Calculate block mode values within 5 by 5 arc-minute bins
357374
>>> data_bmode = pygmt.blockmode(data=data, region=[245, 255, 20, 30], spacing="5m")
358375
"""
376+
aliasdict = AliasSystem().add_common(
377+
V=verbose,
378+
)
379+
aliasdict.merge(kwargs)
380+
359381
return _blockm(
360382
block_method="blockmode",
361383
data=data,
@@ -364,5 +386,5 @@ def blockmode(
364386
z=z,
365387
output_type=output_type,
366388
outfile=outfile,
367-
**kwargs,
389+
**aliasdict,
368390
)

pygmt/src/coast.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
N="borders",
3232
R="region",
3333
S="water",
34-
V="verbose",
3534
W="shorelines",
3635
p="perspective",
3736
t="transparency",
@@ -43,6 +42,8 @@ def coast(
4342
resolution: Literal[
4443
"auto", "full", "high", "intermediate", "low", "crude", None
4544
] = None,
45+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
46+
| bool = False,
4647
panel: int | tuple[int, int] | bool = False,
4748
**kwargs,
4849
):
@@ -68,6 +69,7 @@ def coast(
6869
{aliases}
6970
- D = resolution
7071
- J = projection
72+
- V = verbose
7173
- c = panel
7274
7375
Parameters
@@ -229,6 +231,7 @@ def coast(
229231
),
230232
).add_common(
231233
J=projection,
234+
V=verbose,
232235
c=panel,
233236
)
234237
aliasdict.merge(kwargs)

pygmt/src/colorbar.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
colorbar - Plot gray scale or color scale bar.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.alias import AliasSystem
68
from pygmt.clib import Session
79
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -20,15 +22,19 @@
2022
L="equalsize",
2123
Q="log",
2224
R="region",
23-
V="verbose",
2425
W="scale",
2526
Z="zfile",
2627
p="perspective",
2728
t="transparency",
2829
)
2930
@kwargs_to_strings(R="sequence", G="sequence", I="sequence", p="sequence")
3031
def colorbar(
31-
self, projection=None, panel: int | tuple[int, int] | bool = False, **kwargs
32+
self,
33+
projection=None,
34+
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
35+
| bool = False,
36+
panel: int | tuple[int, int] | bool = False,
37+
**kwargs,
3238
):
3339
r"""
3440
Plot gray scale or color scale bar.
@@ -45,6 +51,7 @@ def colorbar(
4551
4652
{aliases}
4753
- J = projection
54+
- V = verbose
4855
- c = panel
4956
5057
Parameters
@@ -149,6 +156,7 @@ def colorbar(
149156

150157
aliasdict = AliasSystem().add_common(
151158
J=projection,
159+
V=verbose,
152160
c=panel,
153161
)
154162
aliasdict.merge(kwargs)

0 commit comments

Comments
 (0)