Skip to content

Commit 4219ebe

Browse files
authored
pygmt.project: Migrate the 'center'/'endpoint'/'pole'/'width'/'length' parameters to the new alias system (#4172)
1 parent 24f4dc3 commit 4219ebe

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

pygmt/src/project.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
project - Project data onto lines or great circles, or generate tracks.
33
"""
44

5+
from collections.abc import Sequence
56
from typing import Literal
67

78
import numpy as np
89
import pandas as pd
910
from pygmt._typing import PathLike, TableLike
10-
from pygmt.alias import AliasSystem
11+
from pygmt.alias import Alias, AliasSystem
1112
from pygmt.clib import Session
1213
from pygmt.exceptions import GMTInvalidInput
1314
from pygmt.helpers import (
1415
build_arg_list,
1516
fmt_docstring,
16-
kwargs_to_strings,
1717
use_alias,
1818
validate_output_table_type,
1919
)
@@ -22,27 +22,26 @@
2222
@fmt_docstring
2323
@use_alias(
2424
A="azimuth",
25-
C="center",
26-
E="endpoint",
2725
F="convention",
2826
G="generate",
29-
L="length",
3027
N="flat_earth",
3128
Q="unit",
3229
S="sort",
33-
T="pole",
34-
W="width",
3530
Z="ellipse",
3631
f="coltypes",
3732
)
38-
@kwargs_to_strings(E="sequence", L="sequence", T="sequence", W="sequence", C="sequence")
39-
def project(
33+
def project( # noqa: PLR0913
4034
data: PathLike | TableLike | None = None,
4135
x=None,
4236
y=None,
4337
z=None,
4438
output_type: Literal["pandas", "numpy", "file"] = "pandas",
4539
outfile: PathLike | None = None,
40+
center: Sequence[float | str] | None = None,
41+
endpoint: Sequence[float | str] | None = None,
42+
width: Sequence[float | str] | None = None,
43+
length: Sequence[float | str] | Literal["limit"] | None = None,
44+
pole: Sequence[float | str] | None = None,
4645
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4746
| bool = False,
4847
**kwargs,
@@ -112,6 +111,11 @@ def project(
112111
Full GMT docs at :gmt-docs:`project.html`.
113112
114113
{aliases}
114+
- C = center
115+
- E = endpoint
116+
- L = length
117+
- T = pole
118+
- W = width
115119
- V = verbose
116120
117121
Parameters
@@ -123,19 +127,17 @@ def project(
123127
{output_type}
124128
{outfile}
125129
126-
center : str or list
127-
*cx*/*cy*.
128-
Set the origin of the projection, in Definition 1 or 2. If
129-
Definition 3 is used, then *cx/cy* are the coordinates of a
130-
point through which the oblique zero meridian (:math:`p = 0`) should
131-
pass. The *cx/cy* is not required to be 90 degrees from the pole.
132-
130+
center
131+
Set the origin of the projection, in the form of (*cx*, *cy*), in Definitions 1
132+
or 2. If Definition 3 is used, then (*cx*, *cy*) are the coordinates of a point
133+
through which the oblique zero meridian (:math:`p = 0`) should pass.
134+
(*cx*, *cy*) is not required to be 90 degrees from the pole set by ``pole``.
133135
azimuth : float or str
134136
Define the azimuth of the projection (Definition 1).
135137
136-
endpoint : str or list
137-
*bx*/*by*.
138-
Define the end point of the projection path (Definition 2).
138+
endpoint
139+
(*bx*, *by*).
140+
Set the end point of the projection path (Definition 2).
139141
140142
convention : str
141143
Specify the desired output using any combination of **xyzpqrs**, in
@@ -162,14 +164,12 @@ def project(
162164
the pole as part of the segment header [Default is no header].
163165
**Note**: No input is read and the value of ``data``, ``x``, ``y``,
164166
and ``z`` is ignored if ``generate`` is used.
165-
166-
length : str or list
167-
[**w**\|\ *l_min*/*l_max*].
168-
Project only those data whose *p* coordinate is
169-
within :math:`l_{{min}} < p < l_{{max}}`. If ``endpoint`` has been set,
170-
then you may alternatively use **w** to stay within the distance from
171-
``center`` to ``endpoint``.
172-
167+
length
168+
(*lmin*, *lmax*) or ``"limit"``.
169+
Project only those data whose *p* coordinate is within
170+
:math:`l_{{min}} < p < l_{{max}}`. If ``endpoint`` has been set, then you may
171+
alternatively set it to ``"limit"`` to stay within the distance from ``center``
172+
to ``endpoint``.
173173
flat_earth : bool
174174
Make a Cartesian coordinate transformation in the plane.
175175
[Default is ``False``; plane created with spherical trigonometry.]
@@ -182,18 +182,13 @@ def project(
182182
sort : bool
183183
Sort the output into increasing :math:`p` order. Useful when projecting
184184
random data into a sequential profile.
185-
186-
pole : str or list
187-
*px*/*py*.
188-
Set the position of the rotation pole of the projection.
189-
(Definition 3).
190-
191-
{verbose}
192-
193-
width : str or list
194-
*w_min*/*w_max*.
195-
Project only those data whose :math:`q` coordinate is
196-
within :math:`w_{{min}} < q < w_{{max}}`.
185+
pole
186+
(*px*, *py*).
187+
Set the position of the rotation pole of the projection. (Definition 3).
188+
width
189+
(*w_min*, *w_max*).
190+
Specify width controls for the projected points. Project only those points whose
191+
q coordinate is within :math:`w_{{min}} < q < w_{{max}}`.
197192
198193
ellipse : str
199194
*major*/*minor*/*azimuth* [**+e**\|\ **n**].
@@ -212,7 +207,7 @@ def project(
212207
For the Cartesian ellipse (which requires ``flat_earth``), the
213208
*direction* is counter-clockwise from the horizontal instead of an
214209
*azimuth*.
215-
210+
{verbose}
216211
{coltypes}
217212
218213
Returns
@@ -225,8 +220,8 @@ def project(
225220
- :class:`pandas.DataFrame` or :class:`numpy.ndarray` if ``outfile`` is not set
226221
(depends on ``output_type``)
227222
"""
228-
if kwargs.get("C") is None:
229-
msg = "The 'center' parameter must be specified."
223+
if kwargs.get("C", center) is None:
224+
msg = "Parameter 'center' must be specified."
230225
raise GMTInvalidInput(msg)
231226
if kwargs.get("G") is None and data is None:
232227
msg = "The 'data' parameter must be specified unless 'generate' is used."
@@ -241,7 +236,13 @@ def project(
241236
if output_type == "pandas" and kwargs.get("G") is not None:
242237
column_names = list("rsp")
243238

244-
aliasdict = AliasSystem().add_common(
239+
aliasdict = AliasSystem(
240+
C=Alias(center, name="center", sep="/", size=2),
241+
E=Alias(endpoint, name="endpoint", sep="/", size=2),
242+
L=Alias(length, name="length", sep="/", size=2, mapping={"limit": "w"}),
243+
T=Alias(pole, name="pole", sep="/", size=2),
244+
W=Alias(width, name="width", sep="/", size=2),
245+
).add_common(
245246
V=verbose,
246247
)
247248
aliasdict.merge(kwargs)

0 commit comments

Comments
 (0)