From 1e74facdcfeaa6cd8c6db804704482ecd4d6f439 Mon Sep 17 00:00:00 2001
From: Austin Sanders <arsanders@ugs.gov>
Date: Mon, 28 Sep 2020 16:08:53 -0700
Subject: [PATCH] Updated for PVL 1.0

---
 plio/io/io_controlnetwork.py    | 28 ++++++++++++++--------------
 plio/io/io_spectral_profiler.py |  4 ++--
 plio/io/io_tes.py               |  2 +-
 plio/io/isis_serial_number.py   | 12 ++++++++++--
 plio/utils/utils.py             |  6 +++---
 5 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/plio/io/io_controlnetwork.py b/plio/io/io_controlnetwork.py
index 1dc4d22..a10652e 100644
--- a/plio/io/io_controlnetwork.py
+++ b/plio/io/io_controlnetwork.py
@@ -42,19 +42,19 @@ class MeasureMessageType(IntEnum):
     MaximumPixelZScore = 4
     PixelShift = 5
     WholePixelCorrelation = 6
-    SubPixelCorrelation = 7 
+    SubPixelCorrelation = 7
 
 class MeasureLog():
-    
+
     def __init__(self, messagetype, value):
         """
         A protobuf compliant measure log object.
-        
+
         Parameters
         ----------
         messagetype : int or str
                       Either the integer or string representation from the MeasureMessageType enum
-                      
+
         value : int or float
                 The value to be stored in the message log
         """
@@ -64,19 +64,19 @@ class MeasureLog():
         else:
             # by name
             self.messagetype = MeasureMessageType[messagetype]
-        
+
         if not isinstance(value, (float, int)):
             raise TypeError(f'{value} is not a numeric type')
         self.value = value
-        
+
     def __repr__(self):
         return f'{self.messagetype.name}: {self.value}'
-        
+
     def to_protobuf(self, version=2):
         """
         Return protobuf compliant measure log object representation
         of this class.
-        
+
         Returns
         -------
         log_message : obj
@@ -148,7 +148,7 @@ def to_isis(obj, path, mode='wb', version=2,
                                          buffer_header_size, points_bytes,
                                          creation_date, modified_date)
 
-        store.write(header)
+        store.write(header.encode('utf-8'))
 
 class IsisStore(object):
     """
@@ -283,7 +283,7 @@ class IsisStore(object):
 
         # Munge the MeasureLogData into Python objs
         df['measureLog'] = df['measureLog'].apply(lambda x: [MeasureLog.from_protobuf(i) for i in x])
-        
+
         df.header = pvl_header
         return df
 
@@ -292,8 +292,8 @@ class IsisStore(object):
         """
         Parameters
         ----------
-        data : str
-               to be written to the file
+        data : bytes
+               Encoded header to be written to the file
         offset : int
                  The byte offset into the output binary
         """
@@ -461,7 +461,7 @@ class IsisStore(object):
            An ISIS compliant PVL header object
         """
 
-        encoder = pvl.encoder.IsisCubeLabelEncoder
+        encoder = pvl.encoder.ISISEncoder(end_delimiter=False)
 
         header_bytes = buffer_header_size
         points_start_byte = HEADERSTARTBYTE + buffer_header_size
@@ -489,4 +489,4 @@ class IsisStore(object):
                  )
         ])
 
-        return pvl.dumps(header, cls=encoder)
+        return pvl.dumps(header, encoder=encoder)
diff --git a/plio/io/io_spectral_profiler.py b/plio/io/io_spectral_profiler.py
index e2892aa..b10a14a 100755
--- a/plio/io/io_spectral_profiler.py
+++ b/plio/io/io_spectral_profiler.py
@@ -100,12 +100,12 @@ class Spectral_Profiler(object):
                          "^SP_SPECTRUM_REF1", "^SP_SPECTRUM_QA", "^L2D_RESULT_ARRAY",
                          "^SP_SPECTRUM_RAD"]:
                     continue
-                if isinstance(v, pvl._collections.Units):
+                if isinstance(v, pvl.collections.Quantity):
                     k = "{}_{}".format(k, v.units)
                     v = v.value
                 keys.append(k)
                 vals.append(v)
-            
+
             vals = [vals] * len(self.ancillary_data)
             new_anc = pd.DataFrame(vals, index=self.ancillary_data.index, columns=keys)
             self.ancillary_data = self.ancillary_data.join(new_anc, how='inner')
diff --git a/plio/io/io_tes.py b/plio/io/io_tes.py
index d084dd7..5889006 100644
--- a/plio/io/io_tes.py
+++ b/plio/io/io_tes.py
@@ -239,7 +239,7 @@ class Tes(object):
             with open(var_file, "rb") as var:
                 buffer = var.read()
                 def process_rad(index):
-                    if index is -1:
+                    if index == -1:
                         return None
 
                     length = np.frombuffer(buffer[index:index+2], dtype='>u2')[0]
diff --git a/plio/io/isis_serial_number.py b/plio/io/isis_serial_number.py
index 21edbad..2b7f0a0 100644
--- a/plio/io/isis_serial_number.py
+++ b/plio/io/isis_serial_number.py
@@ -7,6 +7,7 @@ import plio
 from plio.data import get_data
 from plio.io.io_db import Translations, StringToMission, setup_db_session
 from plio.utils.utils import find_in_dict, find_nested_in_dict
+from datetime import datetime
 
 
 def get_isis_translation(label):
@@ -70,7 +71,7 @@ def generate_serial_number(label):
        The ISIS compatible serial number
     """
     if not isinstance(label, PVLModule):
-        label = pvl.load(label, cls=SerialNumberDecoder)
+        label = pvl.load(label, decoder=SerialNumberDecoder())
     # Get the translation information
     translation = get_isis_translation(label)
 
@@ -96,9 +97,16 @@ def generate_serial_number(label):
                 serial_entry = search_translation[serial_entry]
             elif '*' in search_translation.keys() and search_translation['*'] != '*':
                 serial_entry = search_translation['*']
+            try:
+                serial_entry = serial_entry.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]
+            except:
+                pass
             serial_number.append(serial_entry)
         except:
             pass
+
+
+    print(serial_number)
     return '/'.join(serial_number)
 
 
@@ -108,7 +116,7 @@ class SerialNumberDecoder(pvl.decoder.PVLDecoder):
     serial number. Inherits from the PVLDecoder in planetarypy's pvl module.
     """
 
-    def cast_unquoated_string(self, value):
+    def cast_unquoted_string(self, value):
         """
         Overrides the parent class's method so that any un-quoted string type value found in the
         parsed pvl will just return the original value. This is needed so that keyword values
diff --git a/plio/utils/utils.py b/plio/utils/utils.py
index 64eba37..3b5286f 100644
--- a/plio/utils/utils.py
+++ b/plio/utils/utils.py
@@ -28,7 +28,7 @@ def is_number(s):
         return True
     except ValueError:
         return False
-    
+
 def convert_string_to_float(s):
     """
     Attempt to convert a string to a float.
@@ -44,7 +44,7 @@ def convert_string_to_float(s):
       If successful, the converted value, else the argument is passed back
       out.
     """
-    
+
     try:
         return float(s)
     except TypeError:
@@ -240,7 +240,7 @@ def split_all_ext(path):
     """
     base, ext = os.path.splitext(path)
 
-    while len(ext) is not 0:
+    while len(ext) != 0:
         base, ext = os.path.splitext(base)
 
     return base
-- 
GitLab