def parse_channel_property(property_root): children = list(property_root) if len(children) > 0: version_element = children[0] version = float("".join(version_element.itertext())) if version == 2: channel, colour = parse_channel_property_version_2(children) else: raise MBFXMLException( "XML format violation channel property has unknown version '{0}'." .format(version)) else: raise MBFXMLException( "XML format violation channel property has no children.") return MBFPropertyChannel(version, channel, colour)
def parse_punctum_property(property_root): children = list(property_root) if len(children) > 0: version_element = children[0] version = float("".join(version_element.itertext())) if version == 4: spread, mean_luminance, surface_area, voxel_count, flag_2d, \ volume, location, colocalized_fraction, proximal_fraction = parse_punctum_property_version_4(children) else: raise MBFXMLException( "XML format violation punctum property has unknown version '{0}'." .format(version)) else: raise MBFXMLException( "XML format violation punctum property has no children.") return MBFPropertyPunctum(version, spread, mean_luminance, surface_area, voxel_count, flag_2d, \ volume, location, colocalized_fraction, proximal_fraction)
def _property_text(property_root): children = list(property_root) if len(children) > 0: element = children[0] text = "".join(element.itertext()) else: raise MBFXMLException( "XML format violation text property has no children.") return text
def parse_nodes(nodes_root): nodes = [] for child in nodes_root: raw_tag = get_raw_tag(child) if raw_tag == "node": nodes.append(parse_node(child)) else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) return nodes
def parse_fill_density_property(property_root): children = list(property_root) if len(children) > 0: fill_density_element = children[0] fill_density_string = "".join(fill_density_element.itertext()) fill_density = float(fill_density_string) else: raise MBFXMLException( "XML format violation fill density property has no children.") return MBFPropertyFillDensity(fill_density)
def parse_volume_rle_property(property_root): children = list(property_root) if len(children) > 0: volume_element = children[0] volume_string = "".join(volume_element.itertext()) volume_description = volume_string.split(" ") else: raise MBFXMLException( "XML format violation volume rle property has no children.") return MBFPropertyVolumeRLE(volume_description)
def parse_edgelists(edgelists_root): edgelists = [] for child in edgelists_root: raw_tag = get_raw_tag(child) if raw_tag == "edgelist": edgelists.append(parse_edgelist(child)) else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) return edgelists
def parse_node(node_root): node = { 'id': node_root.attrib['id'], } data = None for child in node_root: raw_tag = get_raw_tag(child) if raw_tag == "point": data = _create_mbf_point(child) else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) if data is None: raise MBFXMLException( "XML format violation no point tag for node with id '{0}'.".format( node['id'])) node['data'] = data return node
def parse_edge(edge_root): edge = {'id': edge_root.attrib['id']} data = [] for child in edge_root: raw_tag = get_raw_tag(child) if raw_tag == "point": data.append(_create_mbf_point(child)) else: raise MBFXMLException( "XML format violation unknown tag {0}".format(raw_tag)) edge['data'] = data return edge
def parse_channels(channels_root): channels = NeurolucidaChannels(channels_root.attrib['merge']) for child in channels_root: raw_tag = get_raw_tag(child) if raw_tag == "channel": channels.add_channel( NeurolucidaChannel(child.attrib['id'], child.attrib['source'])) else: raise MBFXMLException( "XML format violation unknown tag {0} in channels.".format( raw_tag)) return channels
def _parse_tree_structure(tree_root): tree = {'points': [], 'properties': []} for child in tree_root: raw_tag = get_raw_tag(child) if raw_tag == "point": tree['points'].append(_create_mbf_point(child)) elif raw_tag == "branch": tree['points'].append(_parse_tree_structure(child)) elif raw_tag == "property": tree['properties'].append(parse_property(child)) else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) return tree
def parse_property(property_root) -> MBFProperty: name = property_root.attrib['name'] if name == "Channel": return parse_channel_property(property_root) elif name == "Punctum": return parse_punctum_property(property_root) elif name == "VolumeRLE": return parse_volume_rle_property(property_root) elif name == "Set": return parse_set_property(property_root) elif name == "TraceAssociation": return parse_trace_association_property(property_root) elif name == "GUID": return parse_guid_property(property_root) elif name == "FillDensity": return parse_fill_density_property(property_root) elif name == "zSmear": pass else: raise MBFXMLException("Unhandled property '{0}'".format(name))
def parse_contour(contour_root): contour = { 'colour': contour_root.attrib['color'], 'rgb': hex_to_rgb(contour_root.attrib['color']), 'closed': contour_root.attrib['closed'] == 'true', 'name': contour_root.attrib['name'], 'properties': [] } data = [] for child in contour_root: raw_tag = get_raw_tag(child) if raw_tag == "point": data.append(_create_mbf_point(child)) elif raw_tag == "property": contour['properties'].append(parse_property(child)) elif raw_tag == "resolution": pass else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) contour['data'] = data return contour
def parse_marker(marker_root): marker = { 'colour': marker_root.attrib['color'], 'rgb': hex_to_rgb(marker_root.attrib['color']), 'name': marker_root.attrib['name'], 'type': marker_root.attrib['type'], 'varicosity': marker_root.attrib['varicosity'] == "true", 'properties': [] } data = [] for child in marker_root: raw_tag = get_raw_tag(child) if raw_tag == "point": data.append(_create_mbf_point(child)) elif raw_tag == "property": marker['properties'].append(parse_property(child)) else: raise MBFXMLException( "XML format violation unknown tag '{0}'.".format(raw_tag)) marker['data'] = data return marker