Beispiel #1
0
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        if kwargs is None:
            kwargs = OrderedDict()

        pm_key = cls._child_xml_ns_key.get('ProcessingModules', ns_key)
        kwargs['ProcessingModules'] = find_children(node, 'ProcessingModule', xml_ns, pm_key)
        return super(ProductProcessingType, cls).from_node(node, xml_ns, ns_key=ns_key, kwargs=kwargs)
Beispiel #2
0
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     if kwargs is None:
         kwargs = OrderedDict()
     kwargs['SubRegions'] = find_children(node, 'SubRegion', xml_ns, ns_key)
     return super(GeographicCoverageType, cls).from_node(node,
                                                         xml_ns,
                                                         ns_key=ns_key,
                                                         kwargs=kwargs)
Beispiel #3
0
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     if kwargs is None:
         kwargs = OrderedDict()
     gi_key = cls._child_xml_ns_key.get('GeoInfo', ns_key)
     kwargs['GeoInfo'] = find_children(node, 'GeoInfo', xml_ns, gi_key)
     return super(GeoInfoType, cls).from_node(node,
                                              xml_ns,
                                              ns_key=ns_key,
                                              kwargs=kwargs)
Beispiel #4
0
 def _deserialize_multipolygon(cls, node, xml_ns, tag='MultiPolygon'):
     mp_node = find_first_child(node, tag, xml_ns, 'sfa')
     if mp_node is None:
         return None
     p_nodes = find_children(mp_node, 'Element', xml_ns, 'sfa')
     return [
         cls._extract_polygon(p_node, xml_ns, tag='Ring')
         for p_node in p_nodes
     ]
Beispiel #5
0
 def _deserialize_multilinestring(cls, node, xml_ns, tag='MultiLineString'):
     mls_node = find_first_child(node, tag, xml_ns, 'sfa')
     if mls_node is None:
         return None
     ls_nodes = find_children(mls_node, 'Element', xml_ns, 'sfa')
     return [
         cls._extract_line(ls_node, xml_ns, tag='Vertex')
         for ls_node in ls_nodes
     ]
Beispiel #6
0
    def __set__(self, instance, value):
        def set_value(new_val):
            if len(new_val) < self.minimum_length:
                msg = 'Attribute {} of class {} is a double array of size {},\n\t' \
                      'and must have size at least {}.'.format(
                        self.name, instance.__class__.__name__, value.size, self.minimum_length)
                if self.strict:
                    raise ValueError(msg)
                else:
                    logger.error(msg)
            if len(new_val) > self.maximum_length:
                msg = 'Attribute {} of class {} is a double array of size {},\n\t' \
                      'and must have size no larger than {}.'.format(
                        self.name, instance.__class__.__name__, value.size, self.maximum_length)
                if self.strict:
                    raise ValueError(msg)
                else:
                    logger.error(msg)
            self.data[instance] = new_val

        if super(FloatArrayDescriptor, self).__set__(instance, value):  # the None handler...kinda hacky
            return

        if isinstance(value, numpy.ndarray):
            if not (len(value) == 1) and (numpy.dtype.name == 'float64'):
                raise ValueError('Only one-dimensional ndarrays of dtype float64 are supported here.')
            set_value(value)
        elif isinstance(value, ElementTree.Element):
            xml_ns = getattr(instance, '_xml_ns', None)
            # noinspection PyProtectedMember
            if hasattr(instance, '_child_xml_ns_key') and self.name in instance._child_xml_ns_key:
                # noinspection PyProtectedMember
                xml_ns_key = instance._child_xml_ns_key[self.name]
            else:
                xml_ns_key = getattr(instance, '_xml_ns_key', None)

            size = int_func(value.attrib['size'])
            child_nodes = find_children(value, self.child_tag, xml_ns, xml_ns_key)
            if len(child_nodes) != size:
                raise ValueError(
                    'Field {} of double array type functionality belonging to class {} got a ElementTree element '
                    'with size attribute {}, but has {} child nodes with tag {}.'.format(
                        self.name, instance.__class__.__name__, size, len(child_nodes), self.child_tag))
            new_value = numpy.empty((size,), dtype=numpy.float64)
            for i, node in enumerate(child_nodes):
                new_value[i] = float(get_node_value(node))
            set_value(new_value)
        elif isinstance(value, list):
            # user or json deserialization
            set_value(numpy.array(value, dtype=numpy.float64))
        else:
            raise TypeError(
                'Field {} of class {} got incompatible type {}.'.format(
                    self.name, instance.__class__.__name__, type(value)))
Beispiel #7
0
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        dim1 = int(node.attrib['size'])
        dim2 = int(node.attrib['numLuts'])
        arr = numpy.zeros((dim1, dim2), dtype=numpy.uint16)

        lut_key = cls._child_xml_ns_key.get('LUTValues', ns_key)
        lut_nodes = find_children(node, 'LUTValues', xml_ns, lut_key)
        for i, lut_node in enumerate(lut_nodes):
            arr[:, i] = [str(el) for el in get_node_value(lut_node)]
        if numpy.max(arr) < 256:
            arr = numpy.cast[numpy.uint8](arr)
        return cls(LUTValues=arr)
Beispiel #8
0
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     num_phasings = int(node.attrib['numPhasings'])
     num_points = int(node.attrib['numPoints'])
     coefs = numpy.zeros((num_phasings+1, num_points+1), dtype=numpy.float64)
     ckey = cls._child_xml_ns_key.get('Coefs', ns_key)
     coef_nodes = find_children(node, 'Coef', xml_ns, ckey)
     for cnode in coef_nodes:
         ind1 = int(cnode.attrib['phasing'])
         ind2 = int(cnode.attrib['point'])
         val = float(get_node_value(cnode))
         coefs[ind1, ind2] = val
     return cls(Coefs=coefs)
Beispiel #9
0
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     if kwargs is None:
         kwargs = OrderedDict()
     # parse the ModuleName
     mn_key = cls._child_xml_ns_key.get('ModuleName', ns_key)
     mn_node = find_first_child(node, 'ModuleName', xml_ns, mn_key)
     kwargs['ModuleName'] = get_node_value(mn_node)
     kwargs['name'] = mn_node.attrib.get('name', None)
     # parse the ProcessingModule children
     pm_key = cls._child_xml_ns_key.get('ProcessingModules', ns_key)
     kwargs['ProcessingModules'] = find_children(node, 'ProcessingModule', xml_ns, pm_key)
     return super(ProcessingModuleType, cls).from_node(node, xml_ns, ns_key=ns_key, kwargs=kwargs)
Beispiel #10
0
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        """
        Parameters
        ----------
        node
        xml_ns : None|dict
        ns_key : None|str
        kwargs : dict

        Returns
        -------
        PolygonType
        """

        vertex_key = cls._child_xml_ns_key.get('Vertex', ns_key)
        vertices = []
        for cnode in find_children(node, 'Vertex', xml_ns, vertex_key):
            vertices.append(
                LatLonArrayElementType.from_node(cnode,
                                                 xml_ns,
                                                 ns_key=vertex_key))
        return cls(Vertex=vertices)
Beispiel #11
0
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        """
        Parameters
        ----------
        node
        xml_ns : None|dict
        ns_key : None|str
        kwargs : dict

        Returns
        -------
        LineType
        """

        end_point_key = cls._child_xml_ns_key.get('EndPoint', ns_key)
        end_points = []
        for cnode in find_children(node, 'EndPoint', xml_ns, end_point_key):
            end_points.append(
                LatLonArrayElementType.from_node(cnode,
                                                 xml_ns,
                                                 ns_key=end_point_key))
        return cls(EndPoint=end_points)
Beispiel #12
0
 def _extract_polygon(cls, node, xml_ns, tag='Ring'):
     v_nodes = find_children(node, tag, xml_ns, 'sfa')
     return [cls._extract_line(v_node, xml_ns, tag='Vertex') for v_node in v_nodes]
Beispiel #13
0
    def _from_node_0_5(cls, node, xml_ns, ns_key):
        """
        Helper method, not really for public usage. For XML deserialization from SICD version prior to 1.0.

        Parameters
        ----------
        node : ElementTree.Element
            dom element for serialized class instance
        xml_ns : dict
            The xml namespace dictionary
        ns_key : str
            The namespace key in the dictionary
        Returns
        -------
        Serializable
            corresponding class instance
        """
        def get_element(tid, cid, cname, params):
            return {
                'TypeID': tid,
                'CurrentIndex': cid,
                'MatchCollections': [
                    {
                        'CoreName': cname,
                        'Parameters': params
                    },
                ]
            }

        # Note that this is NOT converting the MatchType.MatchCollection in spirit.
        # There isn't enough structure to guarantee that you actually can. This will
        # always yield MatchType.MatchCollection length 1, because the collection details are stuffed
        # into the parameters free form, while CurrentIndex is extracted and actually yields the
        # collection index number (likely larger than 1). This is at least confusing, but more likely
        # completely misleading.
        match_types = []

        coll_key = cls._child_xml_ns_key.get('Collect', ns_key)
        cnodes = find_children(node, 'Collect', xml_ns, coll_key)
        for cnode in cnodes:  # assumed non-empty
            # this describes one series of collects, possibly with more than one MatchType = TypeID
            # It is not clear how it would be possible to deconflict a repeat of MatchType between
            # Collect tags, so I will not.
            core_key = cls._child_xml_ns_key.get('CoreName', ns_key)
            core_name = get_node_value(
                find_first_child(cnode, 'CoreName', xml_ns, core_key))
            current_index = None
            parameters = []

            pkey = cls._child_xml_ns_key.get('Parameters', ns_key)
            pnodes = find_children(cnode, 'Parameter', xml_ns, pkey)
            for pnode in pnodes:
                name = pnode.attrib['name']
                value = get_node_value(pnode)
                if name == 'CURRENT_INSTANCE':
                    current_index = int(
                        value)  # extract the current index (and exclude)
                else:
                    parameters.append({
                        'name': name,
                        'value': value
                    })  # copy the parameter
            if current_index is None:
                continue  # I don't know what we would do?
            mt_key = cls._child_xml_ns_key.get('MatchType', ns_key)
            mtypes = find_children(cnode, 'MatchType', xml_ns, mt_key)
            for tnode in mtypes:
                type_id = get_node_value(tnode)
                match_types.append(
                    get_element(type_id, current_index, core_name, parameters))
        if len(match_types) > 0:
            # noinspection PyTypeChecker
            return cls(MatchTypes=match_types)
        else:
            return None