Skip to content

Commit

Permalink
Fixes scale and offset missing GeoDataset (#205)
Browse files Browse the repository at this point in the history
* Fixes scale and offset missing GeoDataset

* Fixes CHANGELOG entry.
  • Loading branch information
jlaura committed Apr 2, 2024
1 parent 28ce2cf commit f0b0bba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ release.
-->

## [Unreleased]
### Fixed
- Fixed a bug where scale and offset were not being read or applied to GeoDataset objects.

## [1.5.5]()
### Fixed
Expand Down
10 changes: 7 additions & 3 deletions plio/io/io_gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,18 @@ def read_array(self, band=1, pixels=None, dtype=None):
"""
band = self.dataset.GetRasterBand(band)

offset = band.GetOffset()
offset = 0 if offset is None else offset
scale = band.GetScale()
scale = 1 if scale is None else scale

if dtype is None:
dtype = GDAL2NP_CONVERSION[band.DataType]

dtype = getattr(np, dtype)

if not pixels:
array = band.ReadAsArray().astype(dtype)
array = (band.ReadAsArray().astype(dtype) + offset) * scale
#if self.north_up == False:
# array = np.flipud(array)
else:
Expand All @@ -534,7 +538,7 @@ def read_array(self, band=1, pixels=None, dtype=None):

if ystart + ycount > ymax:
ycount = ymax - ystart
array = band.ReadAsArray(xstart, ystart, xcount, ycount).astype(dtype)
array = (band.ReadAsArray(xstart, ystart, xcount, ycount).astype(dtype) + offset) * scale

return array

Expand Down

0 comments on commit f0b0bba

Please sign in to comment.