Conversation
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
pygmt/src/xyz2grd.py
Outdated
| >>> # Create a new grid from the xyz input, set the x-range to 245-255 and | ||
| >>> # the y-range to 20-30, and the spacing to 5 degrees | ||
| >>> new_grid = pygmt.xyz2grd( | ||
| ... data=sample_bathymetry, spacing=5, region=[245, 255, 20, 30] |
There was a problem hiding this comment.
As I understand it, xyz2grd doesn't do interpolations, so for densely sampled data like the bathymetry data, calling xyz2grd with a coarse spacing (spacing=5) produces a grid that cannot reflect the original data. Thus, I think this is not a good example for xyz2grd which may mislead users.
There was a problem hiding this comment.
What would you recommend instead?
There was a problem hiding this comment.
Perhaps passing a 2D numpy array is a more useful example, for example:
import numpy as np
import pygmt
# prepare input arrays
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))There was a problem hiding this comment.
I'm not a geoscientist, so I'm not sure how realistic this example is. But this seems confusing, because it uses numpy functions outside of simple math operations. Would be be easier to just pass a numpy array of data?
There was a problem hiding this comment.
The equivalent 2d numpy array would be like this:
array([[ 0. , 10.5 , 110.25],
[ 1. , 10.5 , 111.25],
[ 2. , 10.5 , 114.25],
[ 3. , 10.5 , 119.25],
[ 0. , 11. , 121. ],
[ 1. , 11. , 122. ],
[ 2. , 11. , 125. ],
[ 3. , 11. , 130. ],
[ 0. , 11.5 , 132.25],
[ 1. , 11.5 , 133.25],
[ 2. , 11.5 , 136.25],
[ 3. , 11.5 , 141.25],
[ 0. , 12. , 144. ],
[ 1. , 12. , 145. ],
[ 2. , 12. , 148. ],
[ 3. , 12. , 153. ],
[ 0. , 12.5 , 156.25],
[ 1. , 12.5 , 157.25],
[ 2. , 12.5 , 160.25],
[ 3. , 12.5 , 165.25]])
People usually know the X range and Y range of the grid, but may don't know how to prepare a 2D numpy array for PyGMT.
Here is a similar example in matplotlib: https://matplotlib.org/stable/plot_types/arrays/pcolormesh.html.
The main difference is that, we have to call the array.flatten() method before passing to xyz2grd.
|
/format |
|
The doctest example fails with the following error message: There are two problems here:
|
Addressed in #1804. |
…ing inline example
weiji14
left a comment
There was a problem hiding this comment.
@willschlitzer, for the sake of Pi-Day, I can only approve either this xyz2grd PR or the grdvolume PR at #1299 for v0.6.0 (see #1808 (comment)). So which will it be?
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Doesn't matter to me |
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 <23025878+michaelgrund@users.noreply.github.com> Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
This PR adds an inline code example to the docstring for
xyz2grd.Addresses #1686
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version