Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7e4ee2f
Migrate the parameter 'verbose' to the new alias system
seisman Jul 31, 2025
1da83f1
AliasSystem: Add the add_common method for common parameters
seisman Aug 8, 2025
08f83af
Figure.basemap: Migrate the 'verbose' parameter to the new .add_commo…
seisman Aug 8, 2025
0b24680
Fix a typo [skip ci]
seisman Aug 8, 2025
482a132
Fix value to key
seisman Aug 8, 2025
e3b531e
Merge branch 'main' into AliasSystem/verbose
seisman Aug 10, 2025
c87a9d6
Reformat the docstring
seisman Aug 10, 2025
d5b095d
Merge branch 'main' into AliasSystem/verbose
seisman Aug 10, 2025
07097e3
Migrate verbose in coast
seisman Aug 10, 2025
f688d7e
Merge branch 'main' into AliasSystem/verbose
seisman Aug 18, 2025
1858135
Merge branch 'main' into AliasSystem/verbose
seisman Aug 19, 2025
6ca8aa7
Remove V from coast aliases
seisman Aug 19, 2025
cccf373
Update more modules
seisman Aug 19, 2025
d945817
Merge branch 'main' into AliasSystem/verbose
seisman Aug 20, 2025
c843379
Merge branch 'main' into AliasSystem/verbose
seisman Aug 22, 2025
86b629b
Add a test for the verbose parameter
seisman Aug 22, 2025
c25df2a
Fix test name
seisman Aug 22, 2025
e89fe7e
Rename information->info and compatibility->compat
seisman Aug 22, 2025
ad81056
Update docs
seisman Aug 22, 2025
1998522
Minor fixes
seisman Aug 22, 2025
3ab0c22
Merge branch 'main' into AliasSystem/verbose
seisman Aug 23, 2025
261ed7f
Fix a typo
seisman Aug 23, 2025
f94f235
Use long names for verbose in tests
seisman Aug 23, 2025
4ea8967
Fix a typo
seisman Aug 23, 2025
6474049
Add the mssing alias to grdgradient
seisman Aug 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions doc/techref/common_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- ``"quite"``: Quiet, not even fatal error messages are produced
- ``"error"``: Error messages only
- ``"warning"``: Warnings [Default]
- ``"timing"``: Timings (report runtimes for time-intensive algorithms)
- ``"information"``: Informational messages (same as ``verbose=True``)
- ``"compatibility"``: Compatibility warnings
- ``"debug"``: Debugging messages
```
43 changes: 40 additions & 3 deletions pygmt/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -227,7 +234,8 @@ class AliasSystem(UserDict):
... B=Alias(frame, name="frame"),
... D=Alias(repeat, name="repeat"),
... c=Alias(panel, name="panel", sep=","),
... ).merge(kwargs)
... ).add_common(V=verbose)
... aliasdict.merge(kwargs)
... return build_arg_list(aliasdict)
>>> func(
... "infile",
Expand All @@ -236,9 +244,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):
Expand Down Expand Up @@ -268,6 +277,34 @@ def __init__(self, **kwargs):
kwdict[option] = aliases._value
super().__init__(kwdict)

def add_common(self, **kwargs):
"""
Add common parameters to the alias dictionary.
"""
for key, value in kwargs.items():
match key:
case "V":
name = "verbose"
alias = Alias(
value,
name=name,
mapping={
"quiet": "q",
"error": "e",
"warning": "w",
"timing": "t",
"information": "i",
"compatibility": "c",
"debug": "d",
},
)
case _:
raise GMTValueError(value, description="common parameter")

self.aliasdict[key] = alias
self[key] = alias._value
return self

def merge(self, kwargs: Mapping[str, Any]):
"""
Update the dictionary with additional keyword arguments.
Expand Down
26 changes: 23 additions & 3 deletions pygmt/src/basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
basemap - Plot base maps and frames.
"""

from typing import Literal

from pygmt.alias import Alias, AliasSystem
from pygmt.clib import Session
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
Expand All @@ -17,14 +19,27 @@
F="box",
Td="rose",
Tm="compass",
V="verbose",
c="panel",
f="coltypes",
p="perspective",
t="transparency",
)
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
def basemap(self, projection=None, **kwargs):
def basemap(
self,
projection=None,
verbose: Literal[
"quiet",
"error",
"warning",
"timing",
"information",
"compatibility",
"debug",
]
| bool = False,
**kwargs,
):
r"""
Plot base maps and frames.

Expand All @@ -40,6 +55,7 @@ def basemap(self, projection=None, **kwargs):

{aliases}
- J=projection
- V=verbose

Parameters
----------
Expand Down Expand Up @@ -86,6 +102,10 @@ def basemap(self, projection=None, **kwargs):
self._activate_figure()
aliasdict = AliasSystem(
J=Alias(projection, name="projection"),
).merge(kwargs)
).add_common(
V=verbose,
)
aliasdict.merge(kwargs)

with Session() as lib:
lib.call_module(module="basemap", args=build_arg_list(aliasdict))
Loading