Commit d9c45fa7 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by acpaquette
Browse files

Control Point type propagation (#114)

* added thermal alert notebook

* updated to_isis to proagate point type

* cpoint type proagation

* updated tests

* removed thermal playground

* removed capstone code
parent 4c5cf94a
Loading
Loading
Loading
Loading
+9 −83
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ DEFAULTUSERNAME = 'None'
def write_filelist(lst, path="fromlist.lis"):
    """
    Writes a filelist to a file so it can be used in ISIS3.

    Parameters
    ----------
    lst : list
@@ -47,70 +46,18 @@ def from_isis(path, remove_empty=True):

    return df

def to_isis(path, obj, serials, mode='wb', version=2,
def to_isis(obj, path, mode='wb', version=2,
            headerstartbyte=HEADERSTARTBYTE,
            networkid='None', targetname='None',
            description='None', username=DEFAULTUSERNAME,
            creation_date=None, modified_date=None,
            pointid_prefix=None, pointid_suffix=None):
    """

    Write an AutoCNET Candidate graph object to an ISIS3 compatible control
    network.

    Parameters
    ----------
    path : str
           Input path where the file is to be written

    network : dict
              A dict of lists keyed with a

    mode : {'a', 'w', 'r', 'r+'}

        ``'r'``
            Read-only; no data can be modified.
        ``'w'``
            Write; a new file is created (an existing file with the same
            name would be deleted).
        ``'a'``
            Append; an existing file is opened for reading and writing,
            and if the file does not exist it is created.
        ``'r+'``
            It is similar to ``'a'``, but the file must already exist.

    version : int
          The current ISIS version to write, defaults to 2

    headerstartbyte : int
                      The seek offset that the protocol buffer header starts at

    networkid : str
                The name of the network

    targetname : str
                 The name of the target, e.g. Moon

    description : str
                  A description for the network.

    username : str
               The name of the user / application that created the control network

    pointid_prefix : str
                     Prefix to be added to the pointid.  If the prefix is 'foo_', pointids
                     will be in the form 'foo_1, foo_2, ..., foo_n'

    pointid_suffix : str
                     Suffix to tbe added to the point id.  If the suffix is '_bar', pointids
                     will be in the form '1_bar, 2_bar, ..., n_bar'.
    """
    with IsisStore(path, mode) as store:
        if not creation_date:
            creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        if not modified_date:
            modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        point_messages, point_sizes = store.create_points(obj, serials, pointid_prefix, pointid_suffix)
        point_messages, point_sizes = store.create_points(obj, pointid_prefix, pointid_suffix)
        points_bytes = sum(point_sizes)
        buffer_header, buffer_header_size = store.create_buffer_header(networkid,
                                                                       targetname,
@@ -136,7 +83,6 @@ def to_isis(path, obj, serials, mode='wb', version=2,
class IsisStore(object):
    """
    Class to manage IO of an ISIS control network (version 2).

    Attributes
    ----------
    pointid : int
@@ -152,8 +98,8 @@ class IsisStore(object):
              5: int,
              8: bool,
              9: str,
              11: None,
              14: None}
              11: list,
              14: int}
        self.header_attrs = [(i.name, bt[i.type]) for i in cnf._CONTROLNETFILEHEADERV0002.fields]
        self.point_attrs = [(i.name, bt[i.type]) for i in cnf._CONTROLPOINTFILEENTRYV0002.fields]
        self.measure_attrs = [(i.name, bt[i.type]) for i in cnf._CONTROLPOINTFILEENTRYV0002_MEASURE.fields]
@@ -247,29 +193,25 @@ class IsisStore(object):
        ----------
        data : str
               to be written to the file

        offset : int
                 The byte offset into the output binary
        """
        self._handle.seek(offset)
        self._handle.write(data)

    def create_points(self, df, serials, pointid_prefix, pointid_suffix):
    def create_points(self, df, pointid_prefix, pointid_suffix):
        """
        Step through a control network (C) and return protocol buffer point objects

        Parameters
        ----------
        df : DataFrame
              with the appropriate attributes: point_id, point_type, serial,
              measure_type, x, y required.
              The entries in the list must support grouping by the point_id attribute.

        Returns
        -------
        point_messages : list
                         of serialized points buffers

        point_sizes : list
                      of integer point sizes
        """
@@ -302,7 +244,7 @@ class IsisStore(object):
                        point_spec.aprioriCovar.extend(arr)
                    else:
                        setattr(point_spec, attr, attrtype(g.iloc[0][attr]))
            point_spec.type = 2  # Hardcoded to free this is bad
            # point_spec.type = 2  # Hardcoded to free this is bad

            # The reference index should always be the image with the lowest index
            point_spec.referenceIndex = 0
@@ -314,10 +256,10 @@ class IsisStore(object):
                for attr, attrtype in self.measure_attrs:
                    if attr in g.columns:
                        setattr(measure_spec, attr, attrtype(m[attr]))
                measure_spec.serialnumber = serials[m.image_index]
                measure_spec.serialnumber = m.serialnumber
                measure_spec.sample = m.x
                measure_spec.line = m.y
                measure_spec.type = 2
                measure_spec.type = m.measure_type
                measure_iterable.append(measure_spec)
                self.nmeasures += 1

@@ -336,29 +278,22 @@ class IsisStore(object):
        """
        Create the Google Protocol Buffer header using the
        protobuf spec.

        Parameters
        ----------
        networkid : str
                    The user defined identifier of this control network

        targetname : str
                 The name of the target, e.g. Moon

        description : str
                  A description for the network.

        username : str
               The name of the user / application that created the control network

        point_sizes : list
                      of the point sizes for each point message

        Returns
        -------
        header_message : str
                  The serialized message to write

        header_message_size : int
                              The size of the serialized header, in bytes
        """
@@ -382,38 +317,28 @@ class IsisStore(object):
                          creation_date, modified_date):
        """
        Create the PVL header object

        Parameters
        ----------
        version : int
              The current ISIS version to write, defaults to 2

        headerstartbyte : int
                          The seek offset that the protocol buffer header starts at

        networkid : str
                    The name of the network

        targetname : str
                     The name of the target, e.g. Moon

        description : str
                      A description for the network.

        username : str
                   The name of the user / application that created the control network

        buffer_header_size : int
                             Total size of the header in bytes

        points_bytes : int
                       The total number of bytes all points require

        Returns
        -------
         : object
           An ISIS compliant PVL header object

        """

        encoder = pvl.encoder.IsisCubeLabelEncoder
@@ -445,3 +370,4 @@ class IsisStore(object):
        ])

        return pvl.dumps(header, cls=encoder)
+4 −6
Original line number Diff line number Diff line
@@ -33,9 +33,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', 'point_type', 'serialnumber', 'measure_type', 'x', 'y', 'image_index']


        columns = ['point_id', 'type', 'serialnumber', 'measure_type', 'x', 'y', 'image_index']

        data = []
        for i in range(cls.npts):
@@ -46,7 +44,7 @@ class TestWriteIsisControlNetwork(unittest.TestCase):

        cls.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        cls.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        io_controlnetwork.to_isis('test.net', df, cls.serials, mode='wb', targetname='Moon')
        io_controlnetwork.to_isis(df, 'test.net', mode='wb', targetname='Moon')

        cls.header_message_size = 78
        cls.point_start_byte = 65614 # 66949
@@ -56,7 +54,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', 'point_type', 'serialnumber', 'measure_type', 'x', 'y', 'image_index']
        columns = ['point_id', 'type', 'serialnumber', 'measure_type', 'x', 'y', 'image_index']

        data = []
        for i in range(self.npts):
@@ -67,7 +65,7 @@ class TestWriteIsisControlNetwork(unittest.TestCase):

        self.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        self.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        io_controlnetwork.to_isis('test.net', df, serials, mode='wb', targetname='Moon')
        io_controlnetwork.to_isis(df, 'test.net', mode='wb', targetname='Moon')

        self.header_message_size = 78
        self.point_start_byte = 65614 # 66949