def from_node(cls, node, xml_ns, ns_key=None, kwargs=None): if kwargs is not None: kwargs = {} # NoiseLevelType and NoisePoly used to be at this level prior to SICD 1.0. nkey = cls._child_xml_ns_key.get('NoiseLevelType', ns_key) nlevel = find_first_child(node, 'NoiseLevelType', xml_ns, nkey) if nlevel is not None: kwargs['NoiseLevel'] = NoiseLevelType_.from_node(nlevel, xml_ns, ns_key=ns_key, kwargs=kwargs) return super(RadiometricType, cls).from_node(node, xml_ns, ns_key=ns_key, kwargs=kwargs)
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 ]
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 ]
def from_node(cls, node, xml_ns, ns_key=None, kwargs=None): coll_key = cls._child_xml_ns_key.get('Collect', ns_key) coll = find_first_child(node, 'Collect', xml_ns, coll_key) if coll is not None: # This is from SICD version prior to 1.0, so handle manually. return cls._from_node_0_5(node, xml_ns, ns_key) else: return super(MatchInfoType, cls).from_node(node, xml_ns, ns_key=ns_key, kwargs=kwargs)
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)
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)
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: logger.error( 'Parsing RemapLUT is likely compromised.\n\t' '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()
def from_node(cls, node, xml_ns, ns_key=None, kwargs=None): win_key = cls._child_xml_ns_key.get('WindowName', ns_key) win_name = find_first_child(node, 'WindowName', xml_ns, win_key) if win_name is None: # SICD 0.4 standard compliance, this could just be a space delimited string of the form # "<WindowName> <name1>=<value1> <name2>=<value2> ..." if kwargs is None: kwargs = {} values = node.text.strip().split() kwargs['WindowName'] = values[0] params = {} for entry in values[1:]: try: name, val = entry.split('=') params[name] = val except ValueError: continue kwargs['Parameters'] = params return cls.from_dict(kwargs) else: return super(WgtTypeType, cls).from_node(node, xml_ns, ns_key=ns_key, kwargs=kwargs)
def _deserialize_polygon(cls, node, xml_ns, tag='Polygon'): poly_node = find_first_child(node, tag, xml_ns, 'sfa') if poly_node is None: return None return cls._extract_polygon(poly_node, xml_ns, tag='Ring')
def _deserialize_line(cls, node, xml_ns, tag='Line'): line_node = find_first_child(node, tag, xml_ns, 'sfa') if line_node is None: return None return cls._extract_line(line_node, xml_ns, tag='Vertex')
def _deserialize_point(cls, node, xml_ns, tag='Point'): point_node = find_first_child(node, tag, xml_ns, 'sfa') if point_node is None: return None return cls._extract_point(point_node, xml_ns)
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))
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