77from typing import TYPE_CHECKING
88
99from packaging .version import Version
10+ from pygmt .alias import Alias , convert_aliases
1011from 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
1213
1314if TYPE_CHECKING :
1415 from collections .abc import Sequence
1718__doctest_skip__ = ["timestamp" ]
1819
1920
20- @kwargs_to_strings (offset = "sequence" )
2121def timestamp (
2222 self ,
2323 text : str | None = None ,
@@ -82,17 +82,22 @@ def timestamp(
8282 """
8383 self ._preprocess ()
8484
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 )
96101
97102 # The +t modifier was added in GMT 6.5.0.
98103 # See https://github.com/GenericMappingTools/gmt/pull/7127.
@@ -106,13 +111,16 @@ def timestamp(
106111 if Version (__gmt_version__ ) <= Version ("6.4.0" ):
107112 # workaround for GMT<=6.4.0 by overriding the 'timefmt' parameter
108113 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
111119
112120 with Session () as lib :
113121 lib .call_module (
114122 module = "plot" ,
115123 args = build_arg_string (
116- kwdict , confdict = {"FONT_LOGO" : font , "FORMAT_TIME_STAMP" : timefmt }
124+ options , confdict = {"FONT_LOGO" : font , "FORMAT_TIME_STAMP" : timefmt }
117125 ),
118126 )
0 commit comments