Skip to content

Commit af1fb75

Browse files
committed
Reorder functions
1 parent aaeb5f4 commit af1fb75

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

pygmt/src/_common.py

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -44,64 +44,6 @@ def _data_geometry_is_point(data: Any, kind: str) -> bool:
4444
return False
4545

4646

47-
def _parse_coastline_resolution(
48-
resolution: Literal["auto", "full", "high", "intermediate", "low", "crude", None],
49-
allow_auto: bool = False,
50-
) -> str | None:
51-
"""
52-
Parse the resolution parameter for coastline-related functions.
53-
54-
Parameters
55-
----------
56-
resolution
57-
The resolution of the coastline dataset to use. The available resolutions from
58-
highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``, ``"low"``,
59-
and ``"crude"``, which drops by 80% between levels.
60-
allow_auto
61-
Whether to allow the ``"auto"`` resolution.
62-
63-
Returns
64-
-------
65-
The parsed single-letter resolution or ``None``.
66-
67-
Raises
68-
------
69-
GMTInvalidInput
70-
If the resolution is invalid.
71-
72-
Examples
73-
--------
74-
>>> _parse_coastline_resolution("full")
75-
'f'
76-
>>> _parse_coastline_resolution("f")
77-
'f'
78-
>>> _parse_coastline_resolution("auto", allow_auto=True)
79-
'a'
80-
>>> _parse_coastline_resolution(None)
81-
>>> _parse_coastline_resolution("invalid")
82-
Traceback (most recent call last):
83-
...
84-
pygmt.exceptions.GMTInvalidInput: Invalid resolution: 'invalid'. Valid values ...
85-
>>> _parse_coastline_resolution("auto")
86-
Traceback (most recent call last):
87-
...
88-
pygmt.exceptions.GMTInvalidInput: Invalid resolution: 'auto'. Valid values ...
89-
"""
90-
if resolution is None:
91-
return None
92-
93-
valid_resolutions = {"full", "high", "intermediate", "low", "crude"}
94-
if allow_auto:
95-
valid_resolutions.add("auto")
96-
if resolution not in {*valid_resolutions, *[res[0] for res in valid_resolutions]}:
97-
msg = (
98-
f"Invalid resolution: '{resolution}'. "
99-
f"Valid values are {', '.join(valid_resolutions)}."
100-
)
101-
raise GMTInvalidInput(msg)
102-
return resolution[0]
103-
104-
10547
class _FocalMechanismConventionCode(StrEnum):
10648
"""
10749
Enum to handle focal mechanism convention codes.
@@ -309,3 +251,61 @@ def from_params(
309251
f"{', '.join(params)}."
310252
)
311253
raise GMTInvalidInput(msg)
254+
255+
256+
def _parse_coastline_resolution(
257+
resolution: Literal["auto", "full", "high", "intermediate", "low", "crude", None],
258+
allow_auto: bool = False,
259+
) -> str | None:
260+
"""
261+
Parse the resolution parameter for coastline-related functions.
262+
263+
Parameters
264+
----------
265+
resolution
266+
The resolution of the coastline dataset to use. The available resolutions from
267+
highest to lowest are: ``"full"``, ``"high"``, ``"intermediate"``, ``"low"``,
268+
and ``"crude"``, which drops by 80% between levels.
269+
allow_auto
270+
Whether to allow the ``"auto"`` resolution.
271+
272+
Returns
273+
-------
274+
The parsed single-letter resolution or ``None``.
275+
276+
Raises
277+
------
278+
GMTInvalidInput
279+
If the resolution is invalid.
280+
281+
Examples
282+
--------
283+
>>> _parse_coastline_resolution("full")
284+
'f'
285+
>>> _parse_coastline_resolution("f")
286+
'f'
287+
>>> _parse_coastline_resolution("auto", allow_auto=True)
288+
'a'
289+
>>> _parse_coastline_resolution(None)
290+
>>> _parse_coastline_resolution("invalid")
291+
Traceback (most recent call last):
292+
...
293+
pygmt.exceptions.GMTInvalidInput: Invalid resolution: 'invalid'. Valid values ...
294+
>>> _parse_coastline_resolution("auto")
295+
Traceback (most recent call last):
296+
...
297+
pygmt.exceptions.GMTInvalidInput: Invalid resolution: 'auto'. Valid values ...
298+
"""
299+
if resolution is None:
300+
return None
301+
302+
valid_resolutions = {"full", "high", "intermediate", "low", "crude"}
303+
if allow_auto:
304+
valid_resolutions.add("auto")
305+
if resolution not in {*valid_resolutions, *[res[0] for res in valid_resolutions]}:
306+
msg = (
307+
f"Invalid resolution: '{resolution}'. "
308+
f"Valid values are {', '.join(valid_resolutions)}."
309+
)
310+
raise GMTInvalidInput(msg)
311+
return resolution[0]

0 commit comments

Comments
 (0)