question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing xarray.DataArray to grdfilter gives incorrect results

See original GitHub issue

Description 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:closed
  • Created 3 years ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
PaulWesselcommented, Apr 6, 2021

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).

0reactions
seismancommented, Apr 6, 2021

No, PyGMT is using GMT_IN|GMT_IS_REFERENCE, and it fails. If I change it to GMT_IN, it works.

The min and max values are not obtained from the grdinfo call. So any NaN values in data can cause:

>>> print(result.data.max(), result.data.min())
nan nan
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found