-
Notifications
You must be signed in to change notification settings - Fork 224
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 inline example for xyz2grd #1719
Conversation
Co-authored-by: Michael Grund <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you recommend instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 <[email protected]>
Doesn't matter to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this one then
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]>
This PR adds an inline code example to the docstring for
xyz2grd
.Addresses #1686
Reminders
make format
andmake check
to 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