예제 #1
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)
예제 #2
0
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        dim1 = int_func(node.attrib['size'])
        dim2 = int_func(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)
예제 #3
0
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     numPhasings = int_func(node.attrib['numPhasings'])
     numPoints = int_func(node.attrib['numPoints'])
     coefs = numpy.zeros((numPhasings + 1, numPoints + 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_func(cnode.attrib['phasing'])
         ind2 = int_func(cnode.attrib['point'])
         val = float(_get_node_value(cnode))
         coefs[ind1, ind2] = val
     return cls(Coefs=coefs)
예제 #4
0
    def NODATA(self, value):
        if value is None:
            self._NODATA = None
            return

        if isinstance(value, ElementTree.Element):
            value = _get_node_value(value)

        if isinstance(value, string_types):
            self._NODATA = value
        elif isinstance(value, bytes):
            self._NODATA = value.decode('utf-8')
        elif isinstance(value, int):
            raise NotImplementedError
        elif isinstance(value, float):
            raise NotImplementedError
        else:
            raise TypeError('Got unexpected type {}'.format(type(value)))
예제 #5
0
파일: Display.py 프로젝트: nyulacska/sarpy
    def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
        if kwargs is None:
            kwargs = {}

        lut_key = cls._child_xml_ns_key.get('RemapLUT', ns_key)
        lut_node = _find_first_child(node, 'RemapLUT', xml_ns, lut_key)
        if lut_node is not None:
            dim1 = int_func(lut_node.attrib['size'])
            arr = numpy.zeros((dim1, ), dtype=numpy.uint8)
            entries = _get_node_value(lut_node).split()
            i = 0
            for entry in entries:
                if len(entry) == 0:
                    continue
                arr[i] = int(entry)
                i += 1
            kwargs['RemapLUT'] = arr
        return super(MonochromeDisplayRemapType, cls).from_node(node,
                                                                xml_ns,
                                                                ns_key=ns_key,
                                                                **kwargs)
예제 #6
0
파일: Display.py 프로젝트: nyulacska/sarpy
 def from_node(cls, node, xml_ns, ns_key=None, kwargs=None):
     lut_key = cls._child_xml_ns_key.get('RemapLUT', ns_key)
     lut_node = _find_first_child(node, 'RemapLUT', xml_ns, lut_key)
     if lut_node is not None:
         dim1 = int_func(lut_node.attrib['size'])
         dim2 = 3
         arr = numpy.zeros((dim1, dim2), dtype=numpy.uint16)
         entries = _get_node_value(lut_node).split()
         i = 0
         for entry in entries:
             if len(entry) == 0:
                 continue
             sentry = entry.split(',')
             if len(sentry) != 3:
                 logging.error(
                     'Parsing RemapLUT is likely compromised. Got entry {}, '
                     'which we are skipping.'.format(entry))
                 continue
             arr[i, :] = [int(el) for el in entry]
             i += 1
         if numpy.max(arr) < 256:
             arr = numpy.cast[numpy.uint8](arr)
         return cls(RemapLUT=arr)
     return cls()
예제 #7
0
 def _get_value(node, tag, xml_ns, ns_key):
     t_node = _find_first_child(node, tag, xml_ns, ns_key)
     if t_node is None:
         return None
     else:
         return float(_get_node_value(t_node))