From f0b0bba777311785253a61a1402f4b0fa0ab7957 Mon Sep 17 00:00:00 2001
From: Jay Laura <jlaura@usgs.gov>
Date: Tue, 2 Apr 2024 13:18:10 -0700
Subject: [PATCH] Fixes scale and offset missing GeoDataset (#205)

* Fixes scale and offset missing GeoDataset

* Fixes CHANGELOG entry.
---
 CHANGELOG.md       |  2 ++
 plio/io/io_gdal.py | 10 +++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 654bdaf..48847eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/plio/io/io_gdal.py b/plio/io/io_gdal.py
index 749fa40..f67ca5b 100644
--- a/plio/io/io_gdal.py
+++ b/plio/io/io_gdal.py
@@ -506,14 +506,18 @@ class GeoDataset(object):
 
         """
         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:
@@ -534,7 +538,7 @@ class GeoDataset(object):
 
             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
 
-- 
GitLab