def from_xml(cls, element, document): check_tag(element, cls) quantity = Quantity.from_xml(element, document) try: name = element.attrib['name'] except KeyError: raise Exception("Property did not have a name") return cls(name=name, value=quantity.value, units=quantity.units)
def from_xml(cls, element, document): check_tag(element, cls) layout_elem = element.find(NINEML + 'Layout') kwargs = {} if layout_elem: kwargs['positions'] = Component.from_xml(layout_elem, document) cell = expect_single(element.findall(NINEML + 'Cell')) cell_component = cell.find(NINEML + 'Component') if cell_component is None: cell_component = cell.find(NINEML + 'Reference') return cls(name=element.attrib['name'], number=int(element.find(NINEML + 'Number').text), cell=Component.from_xml(cell_component, document), **kwargs)
def from_xml(cls, element, document): if element is None: return None else: check_tag(element, cls) structure_element = element.find(NINEML + 'structure') if structure_element is not None: return cls(structure=document.resolve_ref( structure_element, Structure)) else: positions = [(float(p.attrib['x']), float(p.attrib['y']), float(p.attrib['z'])) for p in element.findall(NINEML + 'position')] return cls(positions=positions)
def from_xml(cls, element, document): check_tag(element, cls) populations = [] for pop_elem in element.findall(NINEML + 'PopulationItem'): pop = Population.from_xml(pop_elem, document) populations[pop.name] = pop projections = [] for proj_elem in element.findall(NINEML + 'ProjectionItem'): proj = Projection.from_xml(proj_elem, document) projections[proj.name] = proj selections = [] for sel_elem in element.findall(NINEML + 'Selection'): sel = Selection.from_xml(sel_elem, document) selections[sel.name] = sel network = cls(name=element.attrib["name"], populations=populations, projections=projections, selections=selections) return network
def from_xml(cls, element, _): check_tag(element, cls) return cls(float(element.text))
def from_xml(cls, element, document): check_tag(element, cls) # The only supported op at this stage op = Concatenate.from_xml( expect_single(element.findall(NINEML + 'Concatenate')), document) return cls(element.attrib['name'], op)
def from_xml(cls, element, document): check_tag(element, cls) # Get Name name = element.get('name') # Get Source e = expect_single(element.findall(NINEML + 'Source')) e = expect_single(e.findall(NINEML + 'Reference')) source = nineml.user_layer.Reference.from_xml( e, document).user_layer_object # Get Destination e = expect_single(element.findall(NINEML + 'Destination')) e = expect_single(e.findall(NINEML + 'Reference')) destination = nineml.user_layer.Reference.from_xml( e, document).user_layer_object # Get Response e = element.find(NINEML + 'Response') component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') response = Component.from_xml(component, document) # Get Plasticity e = expect_none_or_single(element.findall(NINEML + 'Plasticity')) if e is not None: component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') plasticity = Component.from_xml(component, document) else: plasticity = None # Get Connectivity e = element.find(NINEML + 'Connectivity') component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') connectivity = Component.from_xml(component, document) # Get Delay delay = Delay.from_xml( expect_single(element.findall(NINEML + 'Delay')), document) # Get port connections by Loop through 'source', 'destination', # 'response', 'plasticity' tags and extracting the "From*" elements port_connections = [] for receive_role in cls._component_roles: # Get element for component name e = element.find(NINEML + receive_role.capitalize()) if e is not None: # Plasticity is not required # Loop through all incoming port connections and add them to # list for sender_role in cls._component_roles: pc_elems = e.findall(NINEML + 'From' + sender_role.capitalize()) if sender_role == receive_role and pc_elems: msg = ("{} port connection receives from itself in " "Projection '{}'".format(name, name)) raise NineMLRuntimeError(msg) if (sender_role is 'plasticity' and plasticity is None and len(pc_elems)): msg = ("{} port connection receives from plasticity, " "which wasn't provided for Projection '{}'" .format(receive_role, name)) raise NineMLRuntimeError(msg) for pc in pc_elems: port_connections.append( PortConnection(sender_role, receive_role, pc.get('send_port'), pc.get('receive_port'))) return cls(name=element.attrib["name"], source=source, destination=destination, response=response, plasticity=plasticity, connectivity=connectivity, delay=delay, port_connections=port_connections)
def from_xml(cls, element, document): check_tag(element, cls) # Get Name name = element.get('name') # Get Source e = expect_single(element.findall(NINEML + 'Source')) e = expect_single(e.findall(NINEML + 'Reference')) source = nineml.user_layer.Reference.from_xml( e, document).user_layer_object # Get Destination e = expect_single(element.findall(NINEML + 'Destination')) e = expect_single(e.findall(NINEML + 'Reference')) destination = nineml.user_layer.Reference.from_xml( e, document).user_layer_object # Get Response e = element.find(NINEML + 'Response') component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') response = Component.from_xml(component, document) # Get Plasticity e = expect_none_or_single(element.findall(NINEML + 'Plasticity')) if e is not None: component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') plasticity = Component.from_xml(component, document) else: plasticity = None # Get Connectivity e = element.find(NINEML + 'Connectivity') component = e.find(NINEML + 'Component') if component is None: component = e.find(NINEML + 'Reference') connectivity = Component.from_xml(component, document) # Get Delay delay = Delay.from_xml( expect_single(element.findall(NINEML + 'Delay')), document) # Get port connections by Loop through 'source', 'destination', # 'response', 'plasticity' tags and extracting the "From*" elements port_connections = [] for receive_role in cls._component_roles: # Get element for component name e = element.find(NINEML + receive_role.capitalize()) if e is not None: # Plasticity is not required # Loop through all incoming port connections and add them to # list for sender_role in cls._component_roles: pc_elems = e.findall(NINEML + 'From' + sender_role.capitalize()) if sender_role == receive_role and pc_elems: msg = ("{} port connection receives from itself in " "Projection '{}'".format(name, name)) raise NineMLRuntimeError(msg) if (sender_role is 'plasticity' and plasticity is None and len(pc_elems)): msg = ( "{} port connection receives from plasticity, " "which wasn't provided for Projection '{}'".format( receive_role, name)) raise NineMLRuntimeError(msg) for pc in pc_elems: port_connections.append( PortConnection(sender_role, receive_role, pc.get('send_port'), pc.get('receive_port'))) return cls(name=element.attrib["name"], source=source, destination=destination, response=response, plasticity=plasticity, connectivity=connectivity, delay=delay, port_connections=port_connections)