Skip to content
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

Fix geoid and gravity anomaly layers' nodata value in overviews #712

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

trey-stafford
Copy link
Contributor

The given nodata value is not set correctly in the overviews. Use -9999 instead, which does get set correctly.

In [2]: from osgeo import gdal

In [3]: ds = gdal.Open('/share/appdata/qgreenland/working-storage/wip-layers/geoid/04-command-build_overviews/ggeoid16.tif')

In [4]: band = ds.GetRasterBand(1);

In [5]: band
Out[5]: <osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x7f0dcf56c0c0> >

In [8]: band.GetOverview(2)
Out[8]: <osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x7f0dcea1a310> >

In [9]: band.GetOverview(2).ReadAsArray()
Out[9]:
array([[1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       ...,
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38]])

In [20]: band.GetOverview(2).ReadAsArray().dtype
Out[20]: dtype('float64')

In [21]: band.ReadAsArray().dtype
Out[21]: dtype('float64')

In [22]: band.GetOverview(2).ReadAsArray()[0, 0]
Out[22]: 1.701410009187828e+38

In [23]: band.ReadAsArray()[0, 0]
Out[23]: 1.70141e+38

In [24]: overview_nodata = band.GetOverview(2).ReadAsArray()[0, 0]

In [25]: data_nodata = band.ReadAsArray()[0, 0]

In [26]: overview_nodata == data_nodata
Out[26]: False

In [27]: overview_nodata < data_nodata
Out[27]: False

In [28]: overview_nodata > data_nodata
Out[28]: True

In [29]: overview_nodata
Out[29]: 1.701410009187828e+38

In [30]: int(overview_nodata)
Out[30]: 170141000918782798866653488190622531584

In [31]: int(data_nodata)
Out[31]: 170141000000000007096036300471486382080

Description

REPLACE ME WITH A PULL REQUEST DESCRIPTION.

Checklist

If an item on this list is done or not needed, simply check it with [x].

  • Config lockfile updated (inv config.export > qgreenland/config/cfg-lock.json)
  • Version bumped if needed (bumpversion (major|minor|patch|prerelease|build)
  • CHANGELOG.md updated
  • Documentation updated if needed
  • New unit tests if needed

The given nodata value is not set correctly in the overviews. Use -9999 instead,
which does get set correctly.

```
In [2]: from osgeo import gdal

In [3]: ds = gdal.Open('/share/appdata/qgreenland/working-storage/wip-layers/geoid/04-command-build_overviews/ggeoid16.tif')

In [4]: band = ds.GetRasterBand(1);

In [5]: band
Out[5]: <osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x7f0dcf56c0c0> >

In [8]: band.GetOverview(2)
Out[8]: <osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x7f0dcea1a310> >

In [9]: band.GetOverview(2).ReadAsArray()
Out[9]:
array([[1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       ...,
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38],
       [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ...,
        1.70141001e+38, 1.70141001e+38, 1.70141001e+38]])

In [20]: band.GetOverview(2).ReadAsArray().dtype
Out[20]: dtype('float64')

In [21]: band.ReadAsArray().dtype
Out[21]: dtype('float64')

In [22]: band.GetOverview(2).ReadAsArray()[0, 0]
Out[22]: 1.701410009187828e+38

In [23]: band.ReadAsArray()[0, 0]
Out[23]: 1.70141e+38

In [24]: overview_nodata = band.GetOverview(2).ReadAsArray()[0, 0]

In [25]: data_nodata = band.ReadAsArray()[0, 0]

In [26]: overview_nodata == data_nodata
Out[26]: False

In [27]: overview_nodata < data_nodata
Out[27]: False

In [28]: overview_nodata > data_nodata
Out[28]: True

In [29]: overview_nodata
Out[29]: 1.701410009187828e+38

In [30]: int(overview_nodata)
Out[30]: 170141000918782798866653488190622531584

In [31]: int(data_nodata)
Out[31]: 170141000000000007096036300471486382080
```
@trey-stafford trey-stafford marked this pull request as ready for review August 8, 2023 16:39
@MattF-NSIDC
Copy link
Member

We think this may be a GDAL bug!

OSGeo/gdal#8187

@trey-stafford trey-stafford merged commit 0def693 into main Aug 8, 2023
1 check passed
@trey-stafford trey-stafford deleted the fix-nodata-overviews-gravity-geoid-layers branch August 8, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants