Passing xarray.DataArray to grdfilter gives incorrect results
See original GitHub issueDescription of the problem
Here is the result from GMT CLI. From the output, we can know the min and max of the filtered grid, -6147.49072266 and 5164.06005859.
$ gmt grdfilter @earth_relief_01d_p -Fg600 -D4 -Goutput.nc
$ gmt grdinfo -C output.nc
output.nc -180 180 -90 90 -6147.49072266 5164.06005859 1 1 360 180 1 1
This is how we do the same thing in Python:
from pygmt import grdfilter
from pygmt.datasets import load_earth_relief
# passing a grid file
result1 = grdfilter("@earth_relief_01d_p", filter="g600", distance="4")
print("result1:", result1.data.min(), result1.data.max())
# passing a xarray.DataArray
grid = load_earth_relief(resolution="01d", registration="pixel")
result2 = grdfilter(grid=grid, filter="g600", distance="4")
print("result2:", result2.data.min(), result2.data.max())
The output is:
result1: -6147.4907 5164.06
result2: -6147.4727 5164.1157
Obviously, passing xarray.DataArray to grdfilter gives incorrect results.
It’s still unclear to me if this is a PyGMT bug or an upstream GMT bug.
Note: the tests in test_grdfilter.py
is testing the “wrong” results. We need to update the tests after figuring out the reason.
Issue Analytics
- State:
- Created 3 years ago
- Comments:29 (29 by maintainers)
Top Results From Across the Web
PyGMT version is not dynamic in develop mode? #912 - GitHub
All reactions. Sorry, something went wrong. ... Passing xarray.DataArray to grdfilter gives incorrect results #859.
Read more >Averaging multiple xarray DataArrays results in no data, errors ...
I am trying to average multiple Xarray DataArrays but the result I get is wrong. The data are not aligned along the time...
Read more >Grdtrack results inconsistent when same data read with Xarray ...
Hello, I'm getting slightly different results when using pygmt.grdtrack on the same dataset, depending on whether I read the dataset ...
Read more >Computation - Xarray
DataArray (x: 5)> array([False, False, True, True, False]) Dimensions ... Aggregation results are assigned the coordinate at the end of each window by ......
Read more >pygmt.grdfilter
xarray.DataArray if outgrid is not set. None if outgrid is set (grid output will be stored in file set by outgrid ).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry, I wrote it backwards but meant what you wrote above (!). I can look at grdfilter and see if there are places where we change any input grid value (thus requiring GMT_IN) or if it ought to work with reference (not changing any values).
No, PyGMT is using
GMT_IN|GMT_IS_REFERENCE
, and it fails. If I change it toGMT_IN
, it works.The min and max values are not obtained from the grdinfo call. So any NaN values in data can cause: