def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT, exclude=()): node = super(MonochromeDisplayRemapType, self).to_node(doc, tag, ns_key=ns_key, parent=parent, check_validity=check_validity, strict=strict) if 'RemapLUT' in self._child_xml_ns_key: rtag = '{}:RemapLUT'.format(self._child_xml_ns_key['RemapLUT']) elif ns_key is not None: rtag = '{}:RemapLUT'.format(ns_key) else: rtag = 'RemapLUT' if self._remap_lut is not None: value = ' '.join('{0:d}'.format(entry) for entry in self._remap_lut) entry = _create_text_node(doc, rtag, value, parent=node) entry.attrib['size'] = str(self._remap_lut.size) return node
def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT, exclude=()): if parent is None: parent = doc.getroot() if ns_key is None: node = _create_new_node(doc, tag, parent=parent) else: node = _create_new_node(doc, '{}:{}'.format(ns_key, tag), parent=parent) if 'RemapLUT' in self._child_xml_ns_key: rtag = '{}:RemapLUT'.format(self._child_xml_ns_key['RemapLUT']) elif ns_key is not None: rtag = '{}:RemapLUT'.format(ns_key) else: rtag = 'RemapLUT' if self._remap_lut is not None: value = ' '.join('{0:d},{1:d},{2:d}'.format(*entry) for entry in self._remap_lut) entry = _create_text_node(doc, rtag, value, parent=node) entry.attrib['size'] = str(self.size) return node
def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT, exclude=()): exclude = exclude + ('ModuleName', 'name', 'ProcessingModules') node = super(ProcessingModuleType, self).to_node(doc, tag, ns_key=ns_key, parent=parent, check_validity=check_validity, strict=strict, exclude=exclude) # add the ModuleName and name children if self.ModuleName is not None: mn_key = self._child_xml_ns_key.get('ModuleName', ns_key) mn_tag = '{}:ModuleName'.format( mn_key ) if mn_key is not None and mn_key != 'default' else 'ModuleName' mn_node = _create_text_node(doc, mn_tag, self.ModuleName, parent=node) if self.name is not None: mn_node.attrib['name'] = self.name # add the ProcessingModule children pm_key = self._child_xml_ns_key.get('ProcessingModules', ns_key) for entry in self._ProcessingModules: entry.to_node(doc, tag, ns_key=pm_key, parent=node, strict=strict) return node
def _serialize_point(coords, doc, tag, parent): if len(coords) < 2: raise ValueError('coords must have at least two elements') fmt_func = '{0:0.16G}'.format node = _create_new_node(doc, tag, parent=parent) _create_text_node(doc, 'sfa:X', fmt_func(coords[0]), parent=node) _create_text_node(doc, 'sfa:Y', fmt_func(coords[1]), parent=node) if len(coords) > 2: _create_text_node(doc, 'sfa:Z', fmt_func(coords[2]), parent=node) if len(coords) > 3: _create_text_node(doc, 'sfa:M', fmt_func(coords[3]), parent=node)
def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT): anode = super(SegmentListType, self).to_node(doc, tag, ns_key=ns_key, parent=parent, check_validity=check_validity, strict=strict) _create_text_node(doc, 'NumSegments' if ns_key is None else '{}:NumSegments'.format(ns_key), '{0:d}'.format(self.NumSegments), parent=anode) return anode
def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT, exclude=()): if parent is None: parent = doc.getroot() if ns_key is None: node = _create_new_node(doc, tag, parent=parent) else: node = _create_new_node(doc, '{}:{}'.format(ns_key, tag), parent=parent) if 'Coefs' in self._child_xml_ns_key: ctag = '{}:Coef'.format(self._child_xml_ns_key['Coefs']) elif ns_key is not None: ctag = '{}:Coef'.format(ns_key) else: ctag = 'Coef' node.attrib['numPhasings'] = str(self.numPhasings) node.attrib['numPoints'] = str(self.numPoints) fmt_func = self._get_formatter('Coefs') for i, val1 in enumerate(self._coefs): for j, val in enumerate(val1): # if val != 0.0: # should we serialize it sparsely? cnode = _create_text_node(doc, ctag, fmt_func(val), parent=node) cnode.attrib['phasing'] = str(i) cnode.attrib['point'] = str(j) return node
def make_entry(arr): value = ' '.join(str(el) for el in arr) entry = _create_text_node(doc, ltag, value, parent=node) entry.attrib['lut'] = str(arr.size)