From 85945b3caafc6c8b188402c5a9a016896f9d9d2d Mon Sep 17 00:00:00 2001
From: Tyler Thatcher <tdt62@nau.edu>
Date: Tue, 20 Aug 2019 17:07:13 -0700
Subject: [PATCH] Makes controlnetwork consistent (#131)

* Fixing to_isis / from_isis process

* Removed merge conflict

* Fixed tests
---
 plio/io/io_controlnetwork.py            | 13 +++++++------
 plio/io/tests/test_io_controlnetwork.py |  4 ++--
 setup.py                                |  2 +-
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/plio/io/io_controlnetwork.py b/plio/io/io_controlnetwork.py
index 5e03f93..54697b5 100644
--- a/plio/io/io_controlnetwork.py
+++ b/plio/io/io_controlnetwork.py
@@ -248,7 +248,7 @@ class IsisStore(object):
         # TODO: Rewrite using apply syntax for performance
         point_sizes = []
         point_messages = []
-        for i, g in df.groupby('point_id'):
+        for i, g in df.groupby('id'):
 
             # Get the point specification from the protobuf
             point_spec = cnf.ControlPointFileEntryV0002()
@@ -258,11 +258,12 @@ class IsisStore(object):
             # set with the correct type
             #point_spec.id = _set_pid(i)
             point_spec.id = _set_pid(i)
+            point_spec.type = g.iloc[0].pointType
             for attr, attrtype in self.point_attrs:
                 if attr in g.columns:
                     # As per protobuf docs for assigning to a repeated field.
-                    if attr == 'aprioriCovar':
-                        arr = g.iloc[0]['aprioriCovar']
+                    if attr == 'aprioriCovar' or attr == 'adjustedCovar':
+                        arr = g.iloc[0][attr]
                         if isinstance(arr, np.ndarray):
                             arr = arr.ravel().tolist()
 
@@ -282,9 +283,9 @@ class IsisStore(object):
                         setattr(measure_spec, attr, attrtype(m[attr]))
                 measure_spec.serialnumber = m.serialnumber
                 # ISIS pixels are centered on (0.5, 0.5). NDArrays are (0,0) based.
-                measure_spec.sample = m.x + 0.5 
-                measure_spec.line = m.y + 0.5
-                measure_spec.type = m.measure_type
+                measure_spec.sample = m['sample'] + 0.5
+                measure_spec.line = m['line'] + 0.5
+                measure_spec.type = m.measureType
                 measure_iterable.append(measure_spec)
                 self.nmeasures += 1
 
diff --git a/plio/io/tests/test_io_controlnetwork.py b/plio/io/tests/test_io_controlnetwork.py
index c93663e..9d13793 100644
--- a/plio/io/tests/test_io_controlnetwork.py
+++ b/plio/io/tests/test_io_controlnetwork.py
@@ -39,7 +39,7 @@ class TestWriteIsisControlNetwork(unittest.TestCase):
         serial_times = {295: '1971-07-31T01:24:11.754',
                         296: '1971-07-31T01:24:36.970'}
         cls.serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())}
-        columns = ['point_id', 'type', 'serialnumber', 'measuretype', 'x', 'y', 'image_index']
+        columns = ['id', 'pointType', 'serialnumber', 'measureType', 'sample', 'line', 'image_index']
 
         data = []
         for i in range(cls.npts):
@@ -60,7 +60,7 @@ class TestWriteIsisControlNetwork(unittest.TestCase):
         serial_times = {295: '1971-07-31T01:24:11.754',
                         296: '1971-07-31T01:24:36.970'}
         serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())}
-        columns = ['point_id', 'type', 'serialnumber', 'measuretype', 'x', 'y', 'image_index']
+        columns = ['id', 'pointType', 'serialnumber', 'measureType', 'sample', 'line', 'image_index']
 
         data = []
         for i in range(self.npts):
diff --git a/setup.py b/setup.py
index de3006e..85ed9c8 100644
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@ with open('README.md', 'r') as f:
 def setup_package():
     setup(
         name = "plio",
-        version = '1.2.1',
+        version = '1.2.2',
         author = "Jay Laura",
         author_email = "jlaura@usgs.gov",
         description = ("I/O API to support planetary data formats."),
-- 
GitLab