-
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
xyz2grd crashes python with large grids #3086
Comments
I can confirm the issue. It's likely an upstream GMT bug in memory management. Here is a working version: import numpy as np
import pygmt
nlat = 180 * 64
nlon = 360 * 64
array = np.empty((nlat, nlon))
spacing = 1/64
x = np.arange(0, 360, spacing)
y = np.arange(-90, 90, spacing)
xx, yy = np.meshgrid(x, y)
grid = pygmt.xyz2grd(x=xx.flatten(), y=yy.flatten(), z=array.flatten(), spacing=spacing, region=[0, 360, -90, 90], registration='p')
print(grid) |
For info, I was able to read the original binary .img fine with GMT. I'm thus not sure if it's possible to reproduce this problem with GMT given that the input I used with the pygmt version was a numpy array. |
Actually, the above example doesn't work. If you replace np.empty() with np.ones(), you will see that there are lots of nans in the grid that is created:
which gives as output
The same thing occurs with np.zeros() and real data. In fact, the nans also occur with np.empty() |
I think it's most likely because the grid should be gridline-registration instead of pixel-registration.
the output is:
the last row is still NaN, because lat=90 or -90 is missing data. |
The grid is supposed to be pixel registered. What I am trying to do is read a large pixel registered image into pygmt, and then convert it to gridline using grdconvert. This works fine using the GMT command line tools, but doesn't work using pygmt. |
Hm. I am not sure, but sofar I understood |
I think you're right. xyz2grd should not accept a 2-d matrix like the one in the original post. |
Also see a related feature request at #2852. |
The documentation states that you can use 2d arrays. If this is incorrect, could we update the documentation? |
it's a little misleading. The 2-d array should has three columns for x, y and z. |
Maybe we can add a check, so that an error or warning is raised when a 2D array with >3 columns is passed in to the Lines 149 to 157 in dd8e0cd
|
Description of the problem
I am trying to create a grd file using pygmt's xyz2grd with a numpy array. The numpy array is large (64 pixels per degree corresponding to 11520 x 23040). Running the xyz2grd command kills the python kernel and gives the following result
I have the same problem on macOS and on Fedora linux (though on fedora, I don't think a error is reported, it just crashes).
Minimal Complete Verifiable Example
Full error message
System information
The text was updated successfully, but these errors were encountered: