|
1 | 1 | """ |
2 | 2 | solar - Plot day-night terminators and twilight. |
3 | 3 | """ |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +from typing import Literal |
| 7 | + |
4 | 8 | import pandas as pd |
5 | 9 | from pygmt.clib import Session |
6 | 10 | from pygmt.exceptions import GMTInvalidInput |
|
22 | 26 | t="transparency", |
23 | 27 | ) |
24 | 28 | @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") |
25 | | -def solar(self, terminator="d", terminator_datetime=None, **kwargs): |
| 29 | +def solar( |
| 30 | + self, |
| 31 | + terminator: Literal["astronomical", "civil", "day_night", "nautical"] = "day_night", |
| 32 | + terminator_datetime=None, |
| 33 | + **kwargs, |
| 34 | +): |
26 | 35 | r""" |
27 | 36 | Plot day-light terminators or twilights. |
28 | 37 |
|
29 | | - This function plots the day-night terminator. Alternatively, it can plot |
30 | | - the terminators for civil twilight, nautical twilight, or astronomical |
31 | | - twilight. |
| 38 | + This function plots the day-night terminator. Alternatively, it can plot the |
| 39 | + terminators for civil twilight, nautical twilight, or astronomical twilight. |
32 | 40 |
|
33 | 41 | Full option list at :gmt-docs:`solar.html` |
34 | 42 |
|
35 | 43 | {aliases} |
36 | 44 |
|
37 | 45 | Parameters |
38 | 46 | ---------- |
39 | | - terminator : str |
40 | | - Set the type of terminator displayed. Valid arguments are |
41 | | - ``"day_night"``, ``"civil"``, ``"nautical"``, and ``"astronomical"``, |
42 | | - which can be set with either the full name or the first letter of the |
43 | | - name [Default is ``"day_night"``]. |
| 47 | + terminator |
| 48 | + Set the type of terminator displayed, which can be set with either the full name |
| 49 | + or the first letter of the name. Available options are: |
44 | 50 |
|
45 | | - Refer to https://en.wikipedia.org/wiki/Twilight for the definitions of |
46 | | - different types of twilight. |
| 51 | + - ``"astronomical"``: Astronomical twilight |
| 52 | + - ``"civil"``: Civil twilight |
| 53 | + - ``"day_night"``: Day/night terminator |
| 54 | + - ``"nautical"``: Nautical twilight |
| 55 | +
|
| 56 | + Refer to https://en.wikipedia.org/wiki/Twilight for the definitions of different |
| 57 | + types of twilight. |
47 | 58 | terminator_datetime : str or datetime object |
48 | | - Set the UTC date and time of the displayed terminator |
49 | | - [Default is the current UTC date and time]. It can be |
50 | | - passed as a string or Python datetime object. |
| 59 | + Set the UTC date and time of the displayed terminator [Default is the current |
| 60 | + UTC date and time]. It can be passed as a string or Python datetime object. |
51 | 61 | {region} |
52 | 62 | {projection} |
53 | 63 | {frame} |
@@ -86,25 +96,16 @@ def solar(self, terminator="d", terminator_datetime=None, **kwargs): |
86 | 96 | >>> # show the plot |
87 | 97 | >>> fig.show() |
88 | 98 | """ |
89 | | - |
90 | 99 | kwargs = self._preprocess(**kwargs) |
91 | 100 | if kwargs.get("T") is not None: |
| 101 | + msg = "Use 'terminator' and 'terminator_datetime' instead of 'T'." |
| 102 | + raise GMTInvalidInput(msg) |
| 103 | + |
| 104 | + valid_terminators = ["day_night", "civil", "nautical", "astronomical"] |
| 105 | + if terminator not in valid_terminators and terminator not in "dcna": |
92 | 106 | raise GMTInvalidInput( |
93 | | - "Use 'terminator' and 'terminator_datetime' instead of 'T'." |
94 | | - ) |
95 | | - if terminator not in [ |
96 | | - "day_night", |
97 | | - "civil", |
98 | | - "nautical", |
99 | | - "astronomical", |
100 | | - "d", |
101 | | - "c", |
102 | | - "n", |
103 | | - "a", |
104 | | - ]: |
105 | | - raise GMTInvalidInput( |
106 | | - f"Unrecognized solar terminator type '{terminator}'. Valid values " |
107 | | - "are 'day_night', 'civil', 'nautical', and 'astronomical'." |
| 107 | + f"Unrecognized solar terminator type '{terminator}'. " |
| 108 | + f"Valid values are {valid_terminators}." |
108 | 109 | ) |
109 | 110 | kwargs["T"] = terminator[0] |
110 | 111 | if terminator_datetime: |
|
0 commit comments