7
7
from typing import TYPE_CHECKING
8
8
9
9
from packaging .version import Version
10
+ from pygmt .alias import Alias , convert_aliases
10
11
from pygmt .clib import Session , __gmt_version__
11
- from pygmt .helpers import build_arg_string , kwargs_to_strings
12
+ from pygmt .helpers import build_arg_string , is_nonstr_iter
12
13
13
14
if TYPE_CHECKING :
14
15
from collections .abc import Sequence
17
18
__doctest_skip__ = ["timestamp" ]
18
19
19
20
20
- @kwargs_to_strings (offset = "sequence" )
21
21
def timestamp (
22
22
self ,
23
23
text : str | None = None ,
@@ -82,17 +82,22 @@ def timestamp(
82
82
"""
83
83
self ._preprocess ()
84
84
85
- # Build the options passed to the "plot" module
86
- kwdict : dict = {"T" : True , "U" : "" }
87
- if label is not None :
88
- kwdict ["U" ] += f"{ label } "
89
- kwdict ["U" ] += f"+j{ justification } "
90
-
91
- if Version (__gmt_version__ ) <= Version ("6.4.0" ) and "/" not in str (offset ):
92
- # Giving a single offset doesn't work in GMT <= 6.4.0.
93
- # See https://github.com/GenericMappingTools/gmt/issues/7107.
94
- offset = f"{ offset } /{ offset } "
95
- kwdict ["U" ] += f"+o{ offset } "
85
+ # Aliases from PyGMT parameters to GMT options
86
+ _aliases = [
87
+ Alias ("label" , "U" , "" , "" ),
88
+ Alias ("justification" , "U" , "+j" , "" ),
89
+ Alias ("offset" , "U" , "+o" , "/" ),
90
+ Alias ("text" , "U" , "+t" , "" ),
91
+ ]
92
+
93
+ # Giving a single offset doesn't work in GMT <= 6.4.0.
94
+ # See https://github.com/GenericMappingTools/gmt/issues/7107.
95
+ if (
96
+ Version (__gmt_version__ ) <= Version ("6.4.0" )
97
+ and not is_nonstr_iter (offset )
98
+ and "/" not in str (offset )
99
+ ):
100
+ offset = (offset , offset )
96
101
97
102
# The +t modifier was added in GMT 6.5.0.
98
103
# See https://github.com/GenericMappingTools/gmt/pull/7127.
@@ -106,13 +111,16 @@ def timestamp(
106
111
if Version (__gmt_version__ ) <= Version ("6.4.0" ):
107
112
# workaround for GMT<=6.4.0 by overriding the 'timefmt' parameter
108
113
timefmt = text [:64 ]
109
- else :
110
- kwdict ["U" ] += f"+t{ text } "
114
+ text = None # reset 'text' to None
115
+
116
+ # Build the options passed to the "plot" module
117
+ options = convert_aliases ()
118
+ options ["T" ] = True
111
119
112
120
with Session () as lib :
113
121
lib .call_module (
114
122
module = "plot" ,
115
123
args = build_arg_string (
116
- kwdict , confdict = {"FONT_LOGO" : font , "FORMAT_TIME_STAMP" : timefmt }
124
+ options , confdict = {"FONT_LOGO" : font , "FORMAT_TIME_STAMP" : timefmt }
117
125
),
118
126
)
0 commit comments