Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing aliases to pygmt.grdgradient #1515

Merged
merged 20 commits into from
Oct 28, 2021
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pygmt/src/grdgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
D="direction",
E="radiance",
G="outgrid",
N="normalize",
Q="norm_control",
maxrjones marked this conversation as resolved.
Show resolved Hide resolved
R="region",
S="slope_file",
V="verbose",
n="interpolation",
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down Expand Up @@ -89,6 +92,40 @@ def grdgradient(grid, **kwargs):
algorithm; in this case the *azim* and *elev* are hardwired to 315
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
and 45 degrees. This means that even if you provide other values
they will be ignored.)
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
normalize : str or bool
[**e**\|\ **t**][*amp*][**+a**\ *ambient*][**+s**\ *sigma*]
[**+o**\ *offset*].
The actual gradients *g* are offset and scaled to produce normalized
gradients *gn* with a
maximum output magnitude of *amp*. If *amp* is not given, default
*amp* = 1. If *offset* is not given, it is set to the average of
*g*. **True** yields *gn* = *amp* \* (*g* - *offset*)/max(abs(\ *g* -
*offset*)). **e** normalizes using a cumulative Laplace
distribution yielding *gn* = *amp* \* (1.0 -
exp(sqrt(2) \* (*g* - *offset*)/ *sigma*)), where
*sigma* is estimated using the L1 norm of (*g* - *offset*) if it is
not given. **t** normalizes using a cumulative Cauchy distribution
yielding *gn* = (2 \* *amp* / PI) \* atan( (*g* - *offset*)/
*sigma*) where *sigma* is estimated using the L2 norm of (*g* -
*offset*) if it is not given. To use *offset* and/or *sigma* from a
previous calculation, leave out the argument to the modifier(s) and
see `norm_control` for usage. As a final option, you may add
**+a**\ *ambient* to add *ambient* to all nodes after gradient
calculations are completed.
maxrjones marked this conversation as resolved.
Show resolved Hide resolved
norm_control : str
**c**\|\ **r**\|\ **R**
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
Controls how normalization via `normalize` is carried out. When
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
multiple grids should be normalized the same way (i.e., with the same
*offset* and/or *sigma*),
we must pass these values via `normalize`. However, this is
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
inconvenient if we compute these values from a grid. Use **c** to
save the results of *offset* and *sigma* to a statistics file; if
grid output is not needed for this run then do not specify `outgrid`.
For subsequent runs, just use **r** to read these values. Using
**R** will read then delete the statistics file.
maxrjones marked this conversation as resolved.
Show resolved Hide resolved
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
slope_file : str
Name of output grid file with scalar magnitudes of gradient vectors.
Requires `direction` but makes `outgrid` optional.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
{R}
{V}
{n}
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -103,6 +140,10 @@ def grdgradient(grid, **kwargs):
``outgrid``)
"""
with GMTTempFile(suffix=".nc") as tmpfile:
if "Q" in kwargs and "N" not in kwargs:
raise GMTInvalidInput(
"""Must specify normalize if norm_control is specified."""
)
if not args_in_kwargs(args=["A", "D", "E"], kwargs=kwargs):
raise GMTInvalidInput(
"""At least one of the following parameters must be specified:
Expand Down