|
2 | 2 | timestamp - Plot the GMT timestamp logo.
|
3 | 3 | """
|
4 | 4 |
|
5 |
| -from __future__ import annotations |
6 |
| - |
7 | 5 | import warnings
|
8 |
| -from typing import TYPE_CHECKING |
| 6 | +from collections.abc import Sequence |
9 | 7 |
|
10 | 8 | from packaging.version import Version
|
| 9 | +from pygmt.alias import Alias, AliasSystem |
11 | 10 | from pygmt.clib import Session, __gmt_version__
|
12 |
| -from pygmt.helpers import build_arg_list, kwargs_to_strings |
13 |
| - |
14 |
| -if TYPE_CHECKING: |
15 |
| - from collections.abc import Sequence |
16 |
| - |
| 11 | +from pygmt.helpers import build_arg_list |
17 | 12 |
|
18 | 13 | __doctest_skip__ = ["timestamp"]
|
19 | 14 |
|
20 | 15 |
|
21 |
| -@kwargs_to_strings(offset="sequence") |
| 16 | +# ruff: noqa: ARG001 |
22 | 17 | def timestamp(
|
23 | 18 | self,
|
24 | 19 | text: str | None = None,
|
@@ -81,35 +76,39 @@ def timestamp(
|
81 | 76 | >>> fig.timestamp(label="Powered by PyGMT")
|
82 | 77 | >>> fig.show()
|
83 | 78 | """
|
84 |
| - self._preprocess() |
| 79 | + alias = AliasSystem( |
| 80 | + U=[ |
| 81 | + Alias("label"), |
| 82 | + Alias("justify", prefix="+j"), |
| 83 | + Alias("offset", prefix="+o", separator="/"), |
| 84 | + Alias("text", prefix="+t"), |
| 85 | + ] |
| 86 | + ) |
85 | 87 |
|
86 |
| - # Build the options passed to the "plot" module |
87 |
| - kwdict: dict = {"T": True, "U": ""} |
88 |
| - if label is not None: |
89 |
| - kwdict["U"] += f"{label}" |
90 |
| - kwdict["U"] += f"+j{justify}" |
| 88 | + self._preprocess() |
91 | 89 |
|
92 |
| - if Version(__gmt_version__) <= Version("6.4.0") and "/" not in str(offset): |
93 |
| - # Giving a single offset doesn't work in GMT <= 6.4.0. |
| 90 | + # Workarounds for bugs/missing features for GMT<=6.4.0 |
| 91 | + if Version(__gmt_version__) <= Version("6.4.0"): |
| 92 | + # Giving a single offset doesn't work. |
94 | 93 | # See https://github.com/GenericMappingTools/gmt/issues/7107.
|
95 |
| - offset = f"{offset}/{offset}" |
96 |
| - kwdict["U"] += f"+o{offset}" |
97 |
| - |
98 |
| - # The +t modifier was added in GMT 6.5.0. |
99 |
| - # See https://github.com/GenericMappingTools/gmt/pull/7127. |
100 |
| - if text is not None: |
101 |
| - if len(str(text)) > 64: |
102 |
| - msg = ( |
103 |
| - "Argument of 'text' must be no longer than 64 characters. " |
104 |
| - "The given text string will be truncated to 64 characters." |
105 |
| - ) |
106 |
| - warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) |
107 |
| - if Version(__gmt_version__) <= Version("6.4.0"): |
108 |
| - # workaround for GMT<=6.4.0 by overriding the 'timefmt' parameter |
| 94 | + if "/" not in str(offset): |
| 95 | + offset = (offset, offset) |
| 96 | + # The +t modifier was added in GMT 6.5.0. |
| 97 | + # See https://github.com/GenericMappingTools/gmt/pull/7127. |
| 98 | + if text is not None: |
| 99 | + # Overriding the 'timefmt' parameter and set 'text' to None |
109 | 100 | timefmt = text[:64]
|
110 |
| - else: |
111 |
| - kwdict["U"] += f"+t{text}" |
| 101 | + text = None |
| 102 | + |
| 103 | + if text is not None and len(text) > 64: |
| 104 | + msg = ( |
| 105 | + "Argument of 'text' must be no longer than 64 characters. " |
| 106 | + "The given text string will be truncated to 64 characters." |
| 107 | + ) |
| 108 | + warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) |
| 109 | + text = text[:64] |
112 | 110 |
|
| 111 | + kwdict: dict = {"T": True, "U": True} | alias.kwdict |
113 | 112 | with Session() as lib:
|
114 | 113 | lib.call_module(
|
115 | 114 | module="plot",
|
|
0 commit comments