Unverified Commit d397cd05 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Projection Addition Fixes (#528)

* Attached the projection to isd if it is a non-empty dtring

* Fixed projected image tests

* Added all change log entries up to current ALE

* Added changelog entry for current PR

* Removed leftover debug prints
parent 0acc3233
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -35,3 +35,14 @@ release.


## [Unreleased]
## [Unreleased]


### Fixed
- Kaguya IsisLabelIsisSpice now calculates the right exposure_duration and focal2pixel_lines [#487](https://github.com/DOI-USGS/ale/pull/487)
- Logging from generate_isd now correctly limits logging information [#487](https://github.com/DOI-USGS/ale/pull/487)

### Changed
- Projection information is only written to the ISD if a projection is present instead of writing an empty projection [#528](https://github.com/DOI-USGS/ale/pull/528/)

### Added
- Projection information (through GDAL) will be attached to the ISD if a projected product is processed through ALE [#524](https://github.com/DOI-USGS/ale/pull/524)
- Kaguya IsisLabelNaifSpice driver, tests, and test data [#487](https://github.com/DOI-USGS/ale/pull/487)
- Hayabusa Amica IsisLabelNaifSpice driver, tests and test data [#521](https://github.com/DOI-USGS/ale/pull/521)
 No newline at end of file
+9 −8
Original line number Original line Diff line number Diff line
@@ -336,25 +336,26 @@ class Driver():
                self._projection = ""
                self._projection = ""
                return self._projection
                return self._projection


            geodata = None
            if isinstance(self._file, pvl.PVLModule):
            if isinstance(self._file, pvl.PVLModule):
                # save it to a temp folder
                # save it to a temp folder
                with tempfile.NamedTemporaryFile() as tmp:
                with tempfile.NamedTemporaryFile() as tmp:
                    tmp.write(pvl.dumps(self._file)) 
                    tmp.write(pvl.dumps(self._file)) 


                    geodata = gdal.Open(tempfile.name)
                    geodata = gdal.Open(tempfile.name)
                    self._projection = geodata.GetSpatialRef()
            else: 
            else: 
                # should be a path
                # should be a path
                if not os.path.exists(self._file): 
                if not os.path.exists(self._file): 
                    self._projection = "" 
                    self._projection = "" 
                else: 
                else: 
                    geodata = gdal.Open(self._file)
                    geodata = gdal.Open(self._file)
                    self._projection = geodata.GetSpatialRef()
   
   
            # is None if not projected

            if self._projection: 
            # Try to get the projection, if we are unsuccessful set it
                self._projection = self._projection.ExportToProj4()
            # to empty
            else: 
            try:
              self._projection = geodata.GetSpatialRef().ExportToProj4()
            except:
              self._projection = "" 
              self._projection = "" 
        return self._projection
        return self._projection
    
    
+3 −2
Original line number Original line Diff line number Diff line
@@ -196,6 +196,7 @@ def to_isd(driver):


    meta_data['sun_position'] = sun_position
    meta_data['sun_position'] = sun_position


    if (driver.projection != ""):
        meta_data["projection"] = driver.projection
        meta_data["projection"] = driver.projection
        meta_data["geotransform"] = driver.geotransform
        meta_data["geotransform"] = driver.geotransform


+3 −2
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ def to_usgscsm(driver):
        'unit' : 'm'
        'unit' : 'm'
    }
    }


    if (driver.projection != ""):
        isd_data["projection"] = driver.projection
        isd_data["projection"] = driver.projection
        isd_data["geotransform"] = driver.geotransform
        isd_data["geotransform"] = driver.geotransform


+17 −1
Original line number Original line Diff line number Diff line
@@ -9,6 +9,8 @@ from ale.transformation import FrameChain
from ale.base.data_naif import NaifSpice
from ale.base.data_naif import NaifSpice
from ale.rotation import ConstantRotation, TimeDependentRotation
from ale.rotation import ConstantRotation, TimeDependentRotation


from conftest import get_image_label

class DummyNaifSpiceDriver(Driver, NaifSpice):
class DummyNaifSpiceDriver(Driver, NaifSpice):
    """
    """
    Test Driver implementation with dummy values
    Test Driver implementation with dummy values
@@ -169,7 +171,6 @@ class DummyLineScannerDriver(LineScanner, DummyNaifSpiceDriver):
    def exposure_duration(self):
    def exposure_duration(self):
        return .01
        return .01



@pytest.fixture
@pytest.fixture
def driver():
def driver():
    return DummyFramerDriver('')
    return DummyFramerDriver('')
@@ -348,3 +349,18 @@ def test_naif_keywords(driver):
        'keyword_1' : 0,
        'keyword_1' : 0,
        'keyword_2' : 'test'
        'keyword_2' : 'test'
    }
    }

def test_no_projection(test_frame_driver):
    isd = formatter.to_isd(test_frame_driver)
    # isn't using real projection so it should be None
    assert isd.get("projection", None) == None

def test_isis_projection():
    isd = formatter.to_isd(DummyLineScannerDriver(get_image_label('B10_013341_1010_XN_79S172W', "isis3")))
    assert isd.get("projection", None) == "+proj=sinu +lon_0=148.36859083039 +x_0=0 +y_0=0 +R=3396190 +units=m +no_defs"

def test_isis_geotransform():
    isd = formatter.to_isd(DummyLineScannerDriver(get_image_label('B10_013341_1010_XN_79S172W', "isis3")))
    expected = (-219771.1526456, 1455.4380969907, 0.0, 5175537.8728989, 0.0, -1455.4380969907)
    for value, truth in zip(isd.get("geotransform", None), expected):
        pytest.approx(value, truth)
Loading