Unverified Commit cf11ad78 authored by Christine Kim's avatar Christine Kim Committed by GitHub
Browse files

Replace affine6p transformation with numpy solution (#579)

* Replace affine6p transformation with numpy solution

* Remove affine6p dependency

* Update changelog and remove pip from conda-recipe
parent b9a28e69
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,10 @@ release.
### Fixed
### Fixed
- Fixed LRO MiniRF drivers naif keywords focal to pixel and pixel to focal translations to be correct. [#569](https://github.com/DOI-USGS/ale/pull/569)
- Fixed LRO MiniRF drivers naif keywords focal to pixel and pixel to focal translations to be correct. [#569](https://github.com/DOI-USGS/ale/pull/569)


### Changed
- Removed the affine6p library and replaced affine6p's affine transformation with a numpy solution [#579](https://github.com/DOI-USGS/ale/pull/579) 


## [0.9.1] - 2023-06-05
## [0.9.1] - 2023-06-05


### Changed
### Changed
+13 −6
Original line number Original line Diff line number Diff line
import spiceypy as spice
import spiceypy as spice
import numpy as np
import numpy as np
import affine6p
from ale.base.data_naif import NaifSpice
from ale.base.data_naif import NaifSpice
from ale.base.label_isis import IsisLabel
from ale.base.label_isis import IsisLabel
from ale.base.type_sensor import Framer
from ale.base.type_sensor import Framer
@@ -156,17 +155,25 @@ class LoHighCameraIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, LoDisto
          p_fidYCoords = self.label['IsisCube']['Instrument']['FiducialYCoordinates'].value
          p_fidYCoords = self.label['IsisCube']['Instrument']['FiducialYCoordinates'].value


          # Create Affine Transformation
          # Create Affine Transformation
          
          p_src = [p_fidSamples, p_fidLines]
          p_src = [p_fidSamples, p_fidLines]
          p_dst = [p_fidXCoords, p_fidYCoords]
          p_dst = [p_fidXCoords, p_fidYCoords]


          # format the fiducial coordinatens as [ [x, y], [x, y]...]
          # Format the fiducial coordinates as [ [x, y], [x, y]...]
          p_src = np.rot90(np.array([p_fidSamples, p_fidLines]))
          p_src = np.rot90(np.array([p_fidSamples, p_fidLines]))
          p_dst = np.rot90(np.array([p_fidXCoords, p_fidYCoords]))
          p_dst = np.rot90(np.array([p_fidXCoords, p_fidYCoords]))


          # find a best match for the transformation based on source and destination coordinates
          # Pad data with ones so that the transformation allows translations 
          tr_mat = affine6p.estimate(p_src, p_dst).get_matrix()
          pad = lambda x: np.hstack([x, np.ones((x.shape[0], 1))])
          X = pad(p_src)
          Y = pad(p_dst)

          # Solve the least squares problem X * A = Y to find our transformation matrix A
          A, res, rank, s = np.linalg.lstsq(X, Y)

          # Transpose matrix and convert to list
          tr_mat = np.transpose(A).tolist()


          # Compute inverse of transformation matrix
          tr_mat_inv = np.linalg.inv(tr_mat)
          tr_mat_inv = np.linalg.inv(tr_mat)


          # X and Y, Inverse S and L components of transformation
          # X and Y, Inverse S and L components of transformation
@@ -175,7 +182,7 @@ class LoHighCameraIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, LoDisto
          itranss = tr_mat_inv[0]
          itranss = tr_mat_inv[0]
          itransl = tr_mat_inv[1]
          itransl = tr_mat_inv[1]


          # move the last item to the front to get the ordering standard in ISIS
          # Move the last item to the front to get the ordering standard in ISIS
          transx.insert(0, transx.pop())
          transx.insert(0, transx.pop())
          transy.insert(0, transy.pop())
          transy.insert(0, transy.pop())
          itranss = np.roll(itranss, 1).tolist()
          itranss = np.roll(itranss, 1).tolist()
+0 −3
Original line number Original line Diff line number Diff line
@@ -22,6 +22,3 @@ dependencies:
  - pytest-cov
  - pytest-cov
  - networkx
  - networkx
  - breathe
  - breathe
  - pip
  - pip:
    - affine6p
+0 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ requirements:
    - cmake>=3.15
    - cmake>=3.15
    - eigen
    - eigen
  host:
  host:
    - pip
    - python
    - python
    - nlohmann_json
    - nlohmann_json
  run:
  run:
+17 −2
Original line number Original line Diff line number Diff line
@@ -98,7 +98,6 @@ class test_high_isis3_naif(unittest.TestCase):
            namfrm.assert_called_with("LO3_HIGH_RESOLUTION_CAMERA")
            namfrm.assert_called_with("LO3_HIGH_RESOLUTION_CAMERA")


    def test_naif_keywords(self):
    def test_naif_keywords(self):

        with patch('ale.drivers.lo_drivers.LoHighCameraIsisLabelNaifSpiceDriver.ikid', new_callable=PropertyMock) as ikid, \
        with patch('ale.drivers.lo_drivers.LoHighCameraIsisLabelNaifSpiceDriver.ikid', new_callable=PropertyMock) as ikid, \
            patch('ale.base.data_naif.spice.bodvrd', return_value=[1737.4, 1737.4, 1737.4]) as bodvrd:
            patch('ale.base.data_naif.spice.bodvrd', return_value=[1737.4, 1737.4, 1737.4]) as bodvrd:


@@ -114,6 +113,22 @@ class test_high_isis3_naif(unittest.TestCase):
                "INS-533001_ITRANSL" : [4541.692430539061, -0.05845617762411283, 143.95514969883214]
                "INS-533001_ITRANSL" : [4541.692430539061, -0.05845617762411283, 143.95514969883214]
            }
            }
            
            
            assert self.driver.naif_keywords == naif_keywords
            assert self.driver.naif_keywords["BODY_CODE"] == naif_keywords["BODY_CODE"]
            assert self.driver.naif_keywords["BODY301_RADII"] == naif_keywords["BODY301_RADII"]
            assert self.driver.naif_keywords["BODY_FRAME_CODE"] == naif_keywords["BODY_FRAME_CODE"]

            np.testing.assert_almost_equal(np.asarray(self.driver.naif_keywords["INS-533001_TRANSX"]), 
                                           np.asarray(naif_keywords["INS-533001_TRANSX"]), 
                                           decimal=10)
            np.testing.assert_almost_equal(np.asarray(self.driver.naif_keywords["INS-533001_TRANSY"]), 
                                           np.asarray(naif_keywords["INS-533001_TRANSY"]), 
                                           decimal=10)
            np.testing.assert_almost_equal(np.asarray(self.driver.naif_keywords["INS-533001_ITRANSS"]), 
                                           np.asarray(naif_keywords["INS-533001_ITRANSS"]), 
                                           decimal=10)
            np.testing.assert_almost_equal(np.asarray(self.driver.naif_keywords["INS-533001_ITRANSL"]), 
                                           np.asarray(naif_keywords["INS-533001_ITRANSL"]), 
                                           decimal=10)

            bodvrd.assert_called_with('Moon', 'RADII', 3)
            bodvrd.assert_called_with('Moon', 'RADII', 3)