Skip to content

Commit 372763a

Browse files
authored
Figure.solar: Use the new alias system for parameters 'terminator'/'terminator_datetime' (#4037)
1 parent 2021de7 commit 372763a

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

pygmt/src/solar.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pandas as pd
88
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
10-
from pygmt.exceptions import GMTInvalidInput, GMTValueError
10+
from pygmt.exceptions import GMTValueError
1111
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
1212

1313
__doctest_skip__ = ["solar"]
@@ -18,7 +18,6 @@
1818
B="frame",
1919
G="fill",
2020
R="region",
21-
T="terminator/terminator_datetime-",
2221
V="verbose",
2322
W="pen",
2423
c="panel",
@@ -43,6 +42,7 @@ def solar(
4342
4443
{aliases}
4544
- J=projection
45+
- T=terminator, **+d**: terminator_datetime
4646
4747
Parameters
4848
----------
@@ -99,28 +99,31 @@ def solar(
9999
>>> fig.show()
100100
"""
101101
self._activate_figure()
102-
if kwargs.get("T") is not None:
103-
msg = "Use 'terminator' and 'terminator_datetime' instead of 'T'."
104-
raise GMTInvalidInput(msg)
105102

106-
valid_terminators = ["day_night", "civil", "nautical", "astronomical"]
107-
if terminator not in valid_terminators and terminator not in "dcna":
108-
raise GMTValueError(
109-
terminator, description="solar terminator type", choices=valid_terminators
110-
)
111-
kwargs["T"] = terminator[0]
103+
datetime_string = None
112104
if terminator_datetime:
113105
try:
114106
datetime_string = pd.to_datetime(terminator_datetime).strftime(
115107
"%Y-%m-%dT%H:%M:%S.%f"
116108
)
117109
except ValueError as verr:
118-
msg = "Unrecognized datetime format."
119-
raise GMTInvalidInput(msg) from verr
120-
kwargs["T"] += f"+d{datetime_string}"
110+
raise GMTValueError(terminator_datetime, description="datetime") from verr
121111

122112
aliasdict = AliasSystem(
123113
J=Alias(projection, name="projection"),
114+
T=[
115+
Alias(
116+
terminator,
117+
name="terminator",
118+
mapping={
119+
"day_night": "d",
120+
"civil": "c",
121+
"nautical": "n",
122+
"astronomical": "a",
123+
},
124+
),
125+
Alias(datetime_string, name="terminator_datetime", prefix="+d"),
126+
],
124127
).merge(kwargs)
125128

126129
with Session() as lib:

pygmt/tests/test_solar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_invalid_datetime():
9696
Test if solar fails when it receives an invalid datetime string.
9797
"""
9898
fig = Figure()
99-
with pytest.raises(GMTInvalidInput):
99+
with pytest.raises(GMTValueError):
100100
fig.solar(
101101
region="d",
102102
projection="W0/15c",

0 commit comments

Comments
 (0)