Skip to content

Add inline example for xyz2grd #1719

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

Merged
merged 14 commits into from
Mar 14, 2022
Merged
Changes from 12 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
17 changes: 16 additions & 1 deletion pygmt/src/xyz2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
)
from pygmt.io import load_dataarray

__doctest_skip__ = ["xyz2grd"]


@fmt_docstring
@use_alias(
Expand Down Expand Up @@ -109,7 +111,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
- **f** 4-byte floating point single precision
- **d** 8-byte floating point double precision

Default format is scanline orientation of ASCII numbers: **-ZTLa**.
[Default format is scanline orientation of ASCII numbers: **La**].
The difference between **A** and **a** is that the latter can decode
both *date*\ **T**\ *clock* and *ddd:mm:ss[.xx]* formats but expects
each input record to have a single value, while the former can handle
Expand All @@ -132,6 +134,19 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
- :class:`xarray.DataArray`: if ``outgrid`` is not set
- None if ``outgrid`` is set (grid output will be stored in file set by
``outgrid``)

Example
-------
>>> import numpy as np
>>> import pygmt
>>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3,
>>> # and a range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5.
>>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5])
>>> z = x**2 + y**2
>>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten()
>>> grid = pygmt.xyz2grd(
... x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13]
... )
"""
if "I" not in kwargs or "R" not in kwargs:
raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")
Expand Down