Skip to content

Commit 0041492

Browse files
willschlitzermichaelgrundseismanweiji14
authored
Add inline example for xyz2grd (#1719)
Example turning an xyz table into a grid. * add I to sequence in kwargs_to_strings, add region for xyz2grd docstring inline example * fix use of GMT alias in PyGMT docstring Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Wei Ji <[email protected]>
1 parent 94681bd commit 0041492

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pygmt/src/xyz2grd.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
)
1313
from pygmt.io import load_dataarray
1414

15+
__doctest_skip__ = ["xyz2grd"]
16+
1517

1618
@fmt_docstring
1719
@use_alias(
@@ -109,7 +111,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
109111
- **f** 4-byte floating point single precision
110112
- **d** 8-byte floating point double precision
111113
112-
Default format is scanline orientation of ASCII numbers: **-ZTLa**.
114+
[Default format is scanline orientation of ASCII numbers: **La**].
113115
The difference between **A** and **a** is that the latter can decode
114116
both *date*\ **T**\ *clock* and *ddd:mm:ss[.xx]* formats but expects
115117
each input record to have a single value, while the former can handle
@@ -132,6 +134,19 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
132134
- :class:`xarray.DataArray`: if ``outgrid`` is not set
133135
- None if ``outgrid`` is set (grid output will be stored in file set by
134136
``outgrid``)
137+
138+
Example
139+
-------
140+
>>> import numpy as np
141+
>>> import pygmt
142+
>>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3,
143+
>>> # and a y-range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5.
144+
>>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5])
145+
>>> z = x**2 + y**2
146+
>>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten()
147+
>>> grid = pygmt.xyz2grd(
148+
... x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13]
149+
... )
135150
"""
136151
if "I" not in kwargs or "R" not in kwargs:
137152
raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")

0 commit comments

Comments
 (0)