OpenGeoVis / PVGeo

🌍 Python package of VTK-based algorithms to analyze geoscientific data and models
https://pvgeo.org
BSD 3-Clause "New" or "Revised" License
213 stars 42 forks source link

EsriGridReader returns wrong data if a grid file has NODATA_VALUE #68

Closed leminhson closed 3 years ago

leminhson commented 4 years ago

Describe the bug The structured grid received from EsriGridReader is correct if all pixels have normal values. But if there are some NODATA_VALUE in a data grid file, EsriGridReader will returns wrong a structured grid.

To Reproduce Here is a simple code to reproduce the error: simple code

Data file: Download data files and soure code: Error_NODATA.zip vd0.asc ; data for the top layer vd1.asc : data for the bottom layer without NODATA_VALUE vd2.asc : data for the bottom layer with three pixel of NODATA_VALUE

Screenshots If a data file does not have NODATA_VALUE, the bottom layer is correct. Correct bottom layer: correct layers

But if there are some NODATAVALUE in a data file, the first point in a structure grid of the bottom layer becomes 'nan'_ although this pixel has a value actually. Error bottom layer: error layers

Where is the bug ??? After checking the source of EsriGridReader, I found that the command data[nans] = np.nan at line 496 of the function _get_rawdata assigns 'nan' for points[0] automatically. Actually, we have only three 'nan' values at points[12], points[17] and points[22]. But why points[0] also changes to 'nan' ? Error_nan

Desktop (please complete the following information):

banesullivan commented 3 years ago

Thanks for providing a detailed example, @leminhson! I'll try to tackle this as soon as I can

banesullivan commented 3 years ago

This turned out to be a rather simple fix. The argwhere was evaluating on a 2D array that had been flattened to one column so it included that column's zero index. Simply flattening the array fixed it.

leminhson commented 3 years ago

@banesullivan : Thank you for your prompt fixing

banesullivan commented 3 years ago

It may be a little while before I push out a release to PyPI (have to fix a bit of broken CI), but the changes (see #69) will be on master soon