Unverified Commit e1588231 authored by Jay Laura's avatar Jay Laura Committed by GitHub
Browse files

Fixes scale/offset error. (#206)

* Fixes scale/offset error.

* Adds ISIS CSM support

* Reverts millisecond formatting

* Adds missing CHANGELOG.

* Adds exception handling
parent f0b0bba7
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -34,8 +34,12 @@ release.
-->
-->


## [Unreleased]
## [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
- 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]()
## [1.5.5]()
### Fixed
### Fixed
+1 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@ try:
    gdal = importlib.import_module('osgeo.gdal')
    gdal = importlib.import_module('osgeo.gdal')
    osr = importlib.import_module('osgeo.osr')
    osr = importlib.import_module('osgeo.osr')
    ogr = importlib.import_module('osgeo.ogr')
    ogr = importlib.import_module('osgeo.ogr')
    gdal.UseExceptions()
except:
except:
    gdal = osr = ogr = None
    gdal = osr = ogr = None


+2 −2
Original line number Original line Diff line number Diff line
@@ -517,7 +517,7 @@ class GeoDataset(object):
        dtype = getattr(np, dtype)
        dtype = getattr(np, dtype)


        if not pixels:
        if not pixels:
            array = (band.ReadAsArray().astype(dtype) + offset) * scale
            array = band.ReadAsArray().astype(dtype) * scale + offset
            #if self.north_up == False:
            #if self.north_up == False:
            #    array = np.flipud(array)
            #    array = np.flipud(array)
        else:
        else:
@@ -538,7 +538,7 @@ class GeoDataset(object):


            if ystart + ycount > ymax:
            if ystart + ycount > ymax:
                ycount = ymax - ystart
                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
        return array


+22 −16
Original line number Original line Diff line number Diff line
@@ -36,10 +36,15 @@ def get_isis_translation(label):
    if not isinstance(label, PVLModule):
    if not isinstance(label, PVLModule):
        label = pvl.load(label)
        label = pvl.load(label)


    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
        # Grab the spacecraft name and run it through the ISIS lookup
        spacecraft_name = find_in_dict(label, 'SpacecraftName')
        spacecraft_name = find_in_dict(label, 'SpacecraftName')
        for row in plio.data_session.query(StringToMission).filter(StringToMission.key==spacecraft_name):
        for row in plio.data_session.query(StringToMission).filter(StringToMission.key==spacecraft_name):
            spacecraft_name = row.value.lower()
            spacecraft_name = row.value.lower()
        
        # Try and pull an instrument identifier
        # Try and pull an instrument identifier
        try:
        try:
            instrumentid = find_in_dict(label, 'InstrumentId').capitalize()
            instrumentid = find_in_dict(label, 'InstrumentId').capitalize()
@@ -52,6 +57,7 @@ def get_isis_translation(label):
                                                                Translations.instrument==instrumentid):
                                                                Translations.instrument==instrumentid):
            # Convert the JSON back to a PVL object
            # Convert the JSON back to a PVL object
            translation = PVLModule(row.translation)
            translation = PVLModule(row.translation)

    return translation
    return translation