From 283d375e931facc273dfdec17c4a0067d96bf822 Mon Sep 17 00:00:00 2001
From: Jesse Mapel <jam826@nau.edu>
Date: Tue, 22 Oct 2019 14:25:14 -0700
Subject: [PATCH] Updated HRSC start sample and line rate table (#305)

* Updated HRSC start sample and line rate table

* Ticked version number

* Added docs

* Extra s

* Explained how missing lines are found
---
 CMakeLists.txt                    |  2 +-
 ale/drivers/mex_drivers.py        | 37 ++++++++++++++++++++-----------
 setup.py                          |  2 +-
 tests/pytests/test_mex_drivers.py | 28 +++++++++--------------
 4 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4eaa5ac..8508317 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@
 # Specify the required version of CMake.
 # cmake 3.10 required for ctest/gtest integration
 cmake_minimum_required(VERSION 3.10)
-project(ale VERSION 0.6.2 DESCRIPTION "Abstraction Library for Ephemerides ")
+project(ale VERSION 0.6.3 DESCRIPTION "Abstraction Library for Ephemerides ")
 
 # include what we need
 include(GNUInstallDirs)
diff --git a/ale/drivers/mex_drivers.py b/ale/drivers/mex_drivers.py
index e83bf82..d1c4106 100644
--- a/ale/drivers/mex_drivers.py
+++ b/ale/drivers/mex_drivers.py
@@ -295,16 +295,6 @@ class MexHrscPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, RadialDistor
         """
         return 0.0
 
-    @property
-    def detector_start_sample(self):
-        """
-        Returns
-        -------
-        : int
-          Detector line corresponding to the first image sample
-        """
-        return self.label["SAMPLE_FIRST_PIXEL"]
-
 
     @property
     def detector_center_sample(self):
@@ -331,13 +321,34 @@ class MexHrscPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, RadialDistor
         For HRSC, the ephemeris times and exposure durations are
         stored in the image data.
 
+        In the image, every line has an entry. This method goes through
+        and removes conescutive lines with the same exposure duration.
+        There are also potentially missing lines in the image which this
+        method accounts for.
+
         Returns
         -------
         : list
           Line scan rates
         """
-        times = [time - self.center_ephemeris_time for time in self.binary_ephemeris_times]
-        return (self.binary_lines, times, self.binary_exposure_durations)
+        relative_times = [time - self.center_ephemeris_time for time in self.binary_ephemeris_times]
+        start_lines = [self.binary_lines[0]]
+        start_times = [relative_times[0]]
+        exposure_durations = [self.binary_exposure_durations[0]]
+        for line, start_time, exposure_duration in zip(self.binary_lines, relative_times, self.binary_exposure_durations):
+            # Check for lines missing from the PDS image
+            #
+            # If more exposures fit into the time since the last entry than
+            # there are lines since the last entry, then there are missing lines.
+            #
+            # If line are missing, add an extra entry for the line immediately
+            # following them.
+            skipped_lines = int( (start_time - start_times[-1]) / exposure_durations[-1] - (line - start_lines[-1]) + 0.5 ) # add 0.5 to round up
+            if exposure_duration != exposure_durations[-1] or skipped_lines > 0:
+                start_lines.append(line)
+                start_times.append(start_time)
+                exposure_durations.append(exposure_duration)
+        return (start_lines, start_times, exposure_durations)
 
 
     @property
@@ -511,7 +522,7 @@ class MexHrscIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, RadialD
         @property
         def times_table(self):
             """
-            Returns EphermisTime, ExposureTime, and LinesStart informtation which was stored as 
+            Returns EphermisTime, ExposureTime, and LinesStart informtation which was stored as
             binary information in the ISIS cube.
 
             Returns
diff --git a/setup.py b/setup.py
index cde239d..6173bca 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ import sys
 from setuptools import setup, find_packages
 
 NAME = "Ale"
-VERSION = "0.6.2"
+VERSION = "0.6.3"
 
 # To install the library, run the following
 #
diff --git a/tests/pytests/test_mex_drivers.py b/tests/pytests/test_mex_drivers.py
index 283bc5b..5d2c5e8 100644
--- a/tests/pytests/test_mex_drivers.py
+++ b/tests/pytests/test_mex_drivers.py
@@ -154,7 +154,7 @@ def usgscsm_compare_dict():
                 "sample": 2592.0
               },
               "starting_detector_line": 1,
-              "starting_detector_sample": 80,
+              "starting_detector_sample": 0,
               "focal2pixel_lines": [
                 -7113.11359717265,
                 0.062856784318668,
@@ -191,11 +191,6 @@ def usgscsm_compare_dict():
                   -94.88182842731476,
                   0.012800790786743165
                 ],
-                [
-                  1.5,
-                  -94.8690276145935,
-                  0.012800790786743165
-                ],
                 [
                   15086.5,
                   101.82391116023064,
@@ -487,8 +482,8 @@ def test_kernels():
         os.remove(kern)
 
 # Eventually all label/formatter combinations should be tested. For now, isis3/usgscsm and
-# pds3/isis will fail. 
-@pytest.mark.parametrize("label,formatter", [('isis3','isis'), ('pds3', 'usgscsm'), 
+# pds3/isis will fail.
+@pytest.mark.parametrize("label,formatter", [('isis3','isis'), ('pds3', 'usgscsm'),
                                               pytest.param('isis3','usgscsm', marks=pytest.mark.xfail),
                                               pytest.param('pds3','isis', marks=pytest.mark.xfail),])
 def test_mex_load(test_kernels, formatter, usgscsm_compare_dict, label):
@@ -581,9 +576,6 @@ class test_mex_pds3_naif(unittest.TestCase):
     def test_detector_start_line(self):
         assert self.driver.detector_start_line == 1
 
-    def test_detector_start_sample(self):
-        assert self.driver.detector_start_sample == 80
-
     def test_detector_center_line(self):
         assert self.driver.detector_center_line == 0.0
 
@@ -620,13 +612,13 @@ class test_mex_pds3_naif(unittest.TestCase):
                    new_callable=PropertyMock) as binary_lines, \
             patch('ale.drivers.mex_drivers.MexHrscPds3NaifSpiceDriver.ephemeris_start_time',
                    new_callable=PropertyMock) as ephemeris_start_time:
-            binary_ephemeris_times.return_value = [255744599.02748165, 255744599.04028246]
-            binary_exposure_durations.return_value = [0.012800790786743165, 0.012800790786743165]
-            binary_lines.return_value = [0.5, 1.5]
-            ephemeris_start_time.return_value = 255744592.07217148
-            assert self.driver.line_scan_rate == ([0.5, 1.5],
-                                                  [3.464854270219803, 3.4776550829410553],
-                                                  [0.012800790786743165, 0.012800790786743165])
+            binary_ephemeris_times.return_value =    [0, 1, 2, 3, 5, 7, 9]
+            binary_exposure_durations.return_value = [1, 1, 1, 2, 2, 2, 2]
+            binary_lines.return_value = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5]
+            ephemeris_start_time.return_value = 0
+            assert self.driver.line_scan_rate == ([0.5, 3.5],
+                                                  [-5.5, -2.5],
+                                                  [1, 2])
 
     def test_sensor_model_version(self):
         assert self.driver.sensor_model_version == 1
-- 
GitLab