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

Fixes scale/offset error. #206

Merged
merged 5 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ release.
-->

## [Unreleased]
### Added
- Hard coded support for `csminit`ed cubes that have serial numbers that differ from `spiceinit`ed cubes.
- Added support for scale and offset for GeoDataset objects.

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

## [1.5.5]()
### Fixed
Expand Down
1 change: 1 addition & 0 deletions plio/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
gdal = importlib.import_module('osgeo.gdal')
osr = importlib.import_module('osgeo.osr')
ogr = importlib.import_module('osgeo.ogr')
gdal.UseExceptions()
except:
gdal = osr = ogr = None

Expand Down
4 changes: 2 additions & 2 deletions plio/io/io_gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def read_array(self, band=1, pixels=None, dtype=None):
dtype = getattr(np, dtype)

if not pixels:
array = (band.ReadAsArray().astype(dtype) + offset) * scale
array = band.ReadAsArray().astype(dtype) * scale + offset
#if self.north_up == False:
# array = np.flipud(array)
else:
Expand All @@ -538,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) + offset) * scale
array = band.ReadAsArray(xstart, ystart, xcount, ycount).astype(dtype) * scale + offset

return array

Expand Down
38 changes: 22 additions & 16 deletions plio/io/isis_serial_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,28 @@ def get_isis_translation(label):
if not isinstance(label, PVLModule):
label = pvl.load(label)

# Grab the spacecraft name and run it through the ISIS lookup
spacecraft_name = find_in_dict(label, 'SpacecraftName')
for row in plio.data_session.query(StringToMission).filter(StringToMission.key==spacecraft_name):
spacecraft_name = row.value.lower()
# Try and pull an instrument identifier
try:
instrumentid = find_in_dict(label, 'InstrumentId').capitalize()
except:
instrumentid = None

translation = None
# Grab the translation PVL object using the lookup
for row in plio.data_session.query(Translations).filter(Translations.mission==spacecraft_name,
Translations.instrument==instrumentid):
# Convert the JSON back to a PVL object
translation = PVLModule(row.translation)
if find_in_dict(label, 'CsmInfo'):
# This cube has been CSM inited, have to load the CSM translation table
translation = {"Keyword1": {"InputKey": "CSMPlatformID", "InputGroup": "IsisCube,CsmInfo", "InputPosition": ["IsisCube", "CsmInfo"], "OutputName": "Keyword1", "OutputPosition": ["Group", "SerialNumberKeywords"], "Translation": ["*", "*"]}, "Keyword2": {"InputKey": "CSMInstrumentId", "InputGroup": "IsisCube,CsmInfo", "InputPosition": ["IsisCube", "CsmInfo"], "OutputName": "Keyword2", "OutputPosition": ["Group", "SerialNumberKeywords"], "Translation": ["*", "*"]}, "Keyword3": {"InputKey": "ReferenceTime", "InputGroup": "IsisCube,CsmInfo", "InputPosition": ["IsisCube", "CsmInfo"], "OutputName": "Keyword3", "OutputPosition": ["Group", "SerialNumberKeywords"], "Translation": ["*", "*"]}}
else:
# Grab the spacecraft name and run it through the ISIS lookup
spacecraft_name = find_in_dict(label, 'SpacecraftName')
for row in plio.data_session.query(StringToMission).filter(StringToMission.key==spacecraft_name):
spacecraft_name = row.value.lower()

# Try and pull an instrument identifier
try:
instrumentid = find_in_dict(label, 'InstrumentId').capitalize()
except:
instrumentid = None

translation = None
# Grab the translation PVL object using the lookup
for row in plio.data_session.query(Translations).filter(Translations.mission==spacecraft_name,
Translations.instrument==instrumentid):
# Convert the JSON back to a PVL object
translation = PVLModule(row.translation)

return translation


Expand Down
Loading