Skip to content

Commit a4a1f15

Browse files
authored
pygmt.grdgradient: Migrate the 'azimuth'/'radiance' parameters to the new alias system (#4218)
1 parent b0ac552 commit a4a1f15

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

pygmt/src/grdgradient.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,28 @@
77

88
import xarray as xr
99
from pygmt._typing import PathLike
10-
from pygmt.alias import AliasSystem
10+
from pygmt.alias import Alias, AliasSystem
1111
from pygmt.clib import Session
1212
from pygmt.exceptions import GMTInvalidInput
13-
from pygmt.helpers import (
14-
args_in_kwargs,
15-
build_arg_list,
16-
fmt_docstring,
17-
kwargs_to_strings,
18-
use_alias,
19-
)
13+
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
2014

2115
__doctest_skip__ = ["grdgradient"]
2216

2317

2418
@fmt_docstring
2519
@use_alias(
26-
A="azimuth",
2720
D="direction",
28-
E="radiance",
2921
N="normalize",
3022
Q="tiles",
3123
S="slope_file",
3224
f="coltypes",
3325
n="interpolation",
3426
)
35-
@kwargs_to_strings(A="sequence", E="sequence")
3627
def grdgradient(
3728
grid: PathLike | xr.DataArray,
3829
outgrid: PathLike | None = None,
30+
azimuth: float | Sequence[float] | None = None,
31+
radiance: Sequence[float] | str | None = None,
3932
region: Sequence[float | str] | str | None = None,
4033
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
4134
| bool = False,
@@ -50,15 +43,17 @@ def grdgradient(
5043
Full GMT docs at :gmt-docs:`grdgradient.html`.
5144
5245
{aliases}
46+
- A = azimuth
47+
- E = radiance
5348
- R = region
5449
- V = verbose
5550
5651
Parameters
5752
----------
5853
{grid}
5954
{outgrid}
60-
azimuth : float, str, or list
61-
*azim*\ [/*azim2*].
55+
azimuth
56+
*azim* or (*azim*, *azim2*).
6257
Azimuthal direction for a directional derivative; *azim* is the
6358
angle in the x,y plane measured in degrees positive clockwise from
6459
north (the positive y-direction) toward east (the positive x-direction). The
@@ -87,9 +82,9 @@ def grdgradient(
8782
- **o**: Report orientations (0-180) rather than directions (0-360).
8883
- **n**: Add 90 degrees to all angles (e.g., to give local strikes of
8984
the surface).
90-
radiance : str or list
91-
[**m**\|\ **s**\|\ **p**]\ *azim/elev*\ [**+a**\ *ambient*][**+d**\
92-
*diffuse*][**+p**\ *specular*][**+s**\ *shine*].
85+
radiance
86+
(*azim*, *elev*) or [**m**\|\ **s**\|\ **p**]\ *azim/elev*\ [**+a**\ *ambient*]
87+
[**+d**\ *diffuse*][**+p**\ *specular*][**+s**\ *shine*].
9388
Compute Lambertian radiance appropriate to use with
9489
:meth:`pygmt.Figure.grdimage` and :meth:`pygmt.Figure.grdview`. The
9590
Lambertian Reflection assumes an ideal surface that reflects all the
@@ -172,14 +167,21 @@ def grdgradient(
172167
if kwargs.get("Q") is not None and kwargs.get("N") is None:
173168
msg = "Must specify normalize if tiles is specified."
174169
raise GMTInvalidInput(msg)
175-
if not args_in_kwargs(args=["A", "D", "E"], kwargs=kwargs):
170+
if (
171+
kwargs.get("A", azimuth) is None
172+
and kwargs.get("D") is None
173+
and kwargs.get("E", radiance) is None
174+
):
176175
msg = (
177176
"At least one of the following parameters must be specified: "
178177
"azimuth, direction, or radiance."
179178
)
180179
raise GMTInvalidInput(msg)
181180

182-
aliasdict = AliasSystem().add_common(
181+
aliasdict = AliasSystem(
182+
A=Alias(azimuth, name="azimuth", sep="/", size=2),
183+
E=Alias(radiance, name="radiance", sep="/", size=2),
184+
).add_common(
183185
R=region,
184186
V=verbose,
185187
)

0 commit comments

Comments
 (0)