def copy(self): sp = SynapseProperties() sp.internalDelay = self.internalDelay sp.preDelay = self.preDelay sp.postDelay = self.postDelay sp.propDelay = self.propDelay sp.weight = self.weight sp.threshold = self.threshold return sp
def startGroup(self, g): self.log.debug("Going into a group: "+ g._v_name) if g._v_name.count('population_')>=1: # TODO: a better check to see if the attribute is a str or numpy.ndarray self.currPopulation = g._v_attrs.name[0] if (len(self.currPopulation)==1): # i.e. it was a str and just took the first letter... self.currPopulation = g._v_attrs.name self.currentCellType = g._v_attrs.cell_type[0] if (len(self.currentCellType)==1): self.currentCellType = g._v_attrs.cell_type size = -1 # Peek ahead for size... for node in g: if node._c_classId == 'ARRAY' and node.name == self.currPopulation: size = node.shape[0] self.log.debug("Found a population: "+ self.currPopulation+", cell type: "+self.currentCellType+", size: "+ str(size)) self.netHandler.handlePopulation(self.currPopulation, self.currentCellType, size) if g._v_name.count('projection_')>=1: self.currentProjectionName = g._v_attrs.name[0] self.currentProjectionSource = g._v_attrs.source[0] self.currentProjectionTarget = g._v_attrs.target[0] self.globalSynapseProps = {} self.log.debug("------ Found a projection: "+ self.currentProjectionName+ ", from "+ self.currentProjectionSource+" to "+ self.currentProjectionTarget) if g._v_name.count('synapse_props_')>=1: newSynapseProps = SynapseProperties() name = g._v_name[len('synapse_props_'):] #print dir(g._v_attrs) for attrName in g._v_attrs._v_attrnames: val = g._v_attrs.__getattr__(attrName) self.log.debug("Val of attribute: "+ attrName + " is "+ str(val)) if attrName == "internal_delay": newSynapseProps.internalDelay = val[0] if attrName == "pre_delay": newSynapseProps.preDelay = val[0] if attrName == "post_delay": newSynapseProps.postDelay = val[0] if attrName == "prop_delay": newSynapseProps.propDelay = val[0] if attrName == "weight": newSynapseProps.weight = val[0] if attrName == "threshold": newSynapseProps.threshold = val[0] self.log.debug(str(newSynapseProps) ) self.globalSynapseProps[name] = newSynapseProps self.log.debug("Global syn props: "+ str(self.globalSynapseProps) )
def startElement(self, name, attrs): self.currentElementList.append(name) #for el in self.currentElementList: # print "<"+el+">" if name == 'networkml': self.log.debug("Found main networkml element") self.log.debug("lengthUnits: "+ attrs.get('lengthUnits',"")) elif name == 'notes' or name == 'meta:notes': self.log.debug("Found notes element") elif name == 'population': self.currPopulation = attrs.get('name',"") self.log.debug("Found population/cellGroup element: "+ self.currPopulation) if attrs.get('cell_type',"") != "": self.currentCellType = attrs.get('cell_type',"") # post NeuroML v1.7.1 form elif name == 'instances': size = -1 if attrs.get('size',"") != "": size = int(attrs.get('size',"")) self.netHandler.handlePopulation(self.currPopulation, self.currentCellType, size) elif name == 'instance': includeInstance = 0 if self.myNodeId == -1: self.log.debug("Ignoring nodeIds, handling all cells...") includeInstance = 1 self.netHandler.setParallelStatus(0) elif attrs.get('node_id',"") != "": self.log.debug("Found node_id: "+ attrs.get('node_id',"")) if self.netHandler.isParallel!=1: self.netHandler.setParallelStatus(1) if int(attrs.get('node_id',"")) == self.myNodeId: self.log.debug("Including...") includeInstance = 1 else: self.log.debug("Excluding from host id: %d..."%self.myNodeId) includeInstance = 0 else: self.log.debug("Found no node_id...") includeInstance = 1 if includeInstance == 1: self.currentInstanceId = attrs.get('id',"") self.log.debug("Found instance element: "+ self.currentInstanceId) elif name == 'cell_type': # pre NeuroML v1.7.1 form self.isCellTypeElement = 1 elif name == 'location': if self.currentInstanceId != -1: #self.log.debug('Found location: ('+ str(attrs.get('x',''))+', '+ str(attrs.get('y',''))+', '+ str(attrs.get('z','')), ')') self.totalInstances+=1 nodeInfo = "" if self.myNodeId >= 0: nodeInfo = " on node id: %d"%self.myNodeId self.log.debug('Adding instance: ' +self.currentInstanceId+" of group: "+self.currPopulation+nodeInfo) self.netHandler.handleLocation(self.currentInstanceId, self.currPopulation, self.currentCellType, attrs.get('x',""),\ attrs.get('y',""), \ attrs.get('z',"")) elif name == 'projection': self.currentProjectionName = attrs.get('name',"") self.log.debug("Found projection element: "+ self.currentProjectionName) if attrs.has_key('source'): self.currentProjectionSource = attrs.get('source',"") if attrs.has_key('target'): self.currentProjectionTarget = attrs.get('target',"") self.log.info("Projection: "+ self.currentProjectionName+" is from: "+ self.currentProjectionSource +" to: "+ self.currentProjectionTarget) elif name == 'source': if self.currentProjectionName != "": self.isSourceElement = 1 elif name == 'target' and not attrs.has_key('cell_group') and not attrs.has_key('population'): if self.currentProjectionName != "": self.isTargetElement = 1 elif name == 'connections': if attrs.get('size',"") != "": size = int(attrs.get('size',"")) self.netHandler.handleProjection(self.currentProjectionName, self.currentProjectionSource, self.currentProjectionTarget, self.globalSynapseProps, size) else: self.netHandler.handleProjection(self.currentProjectionName, self.currentProjectionSource, self.currentProjectionTarget, self.globalSynapseProps) elif name == 'connection': if self.currentProjectionName != "": self.currentConnId = attrs.get('id',"") self.log.debug("Found connection element: "+ self.currentConnId) if attrs.has_key('pre_cell_id'): self.preCellId = attrs.get('pre_cell_id',"") if attrs.has_key('pre_segment_id'): self.preSegId = attrs.get('pre_segment_id',"") else: self.preSegId = 0 if attrs.has_key('pre_fraction_along'): self.preFract = attrs.get('pre_fraction_along',"") else: self.preFract = 0.5 if attrs.has_key('post_cell_id'): self.postCellId = attrs.get('post_cell_id',"") if attrs.has_key('post_segment_id'): self.postSegId = attrs.get('post_segment_id',"") else: self.postSegId = 0 if attrs.has_key('post_fraction_along'): self.postFract = attrs.get('post_fraction_along',"") else: self.postFract = 0.5 self.localSynapseProps.clear() synTypes = self.globalSynapseProps.keys() for synType in synTypes: self.localSynapseProps[synType] = self.globalSynapseProps[synType].copy() elif name == 'pre': if self.currentProjectionName != "": self.preCellId = attrs.get('cell_id',"") if attrs.has_key('segment_id'): self.preSegId = attrs.get('segment_id',"") else: self.preSegId = 0 if attrs.has_key('fraction_along'): self.preFract = attrs.get('fraction_along',"") else: self.preFract = 0.5 self.log.debug("Found pre: "+ self.preCellId) elif name == 'post': if self.currentProjectionName != "": self.postCellId = attrs.get('cell_id',"") if attrs.has_key('segment_id'): self.postSegId = attrs.get('segment_id',"") else: self.postSegId = 0 if attrs.has_key('fraction_along'): self.postFract = attrs.get('fraction_along',"") else: self.postFract = 0.5 self.log.debug("Found post: "+ self.postCellId) elif name == 'synapse_props': if self.currentProjectionName != "": newSynapseProps = SynapseProperties() if attrs.has_key('synapse_type'): self.latestSynapseType = str(attrs.get('synapse_type')) self.log.debug("synapse_type is: "+self.latestSynapseType) if attrs.has_key('internal_delay'): newSynapseProps.internalDelay = attrs.get('internal_delay',"") if attrs.has_key('pre_delay'): newSynapseProps.preDelay = attrs.get('pre_delay',"") if attrs.has_key('post_delay'): newSynapseProps.postDelay = attrs.get('post_delay',"") if attrs.has_key('prop_delay'): newSynapseProps.propDelay = attrs.get('prop_delay',"") if attrs.has_key('weight'): newSynapseProps.weight = attrs.get('weight',"") if attrs.has_key('threshold'): newSynapseProps.threshold = attrs.get('threshold',"") self.globalSynapseProps[self.latestSynapseType] = newSynapseProps for synProp in self.globalSynapseProps.keys(): self.log.debug("globalSynapseProp "+synProp+": "+ str(self.globalSynapseProps[synProp])) elif name == 'synapse_type': if self.currentProjectionName != "": self.isSynapseTypeElement = 1 elif name == 'default_values': if self.currentProjectionName != "": newSynapseProps = SynapseProperties() if attrs.has_key('internal_delay'): newSynapseProps.internalDelay = attrs.get('internal_delay',"") if attrs.has_key('pre_delay'): newSynapseProps.preDelay = attrs.get('pre_delay',"") if attrs.has_key('post_delay'): newSynapseProps.postDelay = attrs.get('post_delay',"") if attrs.has_key('prop_delay'): newSynapseProps.propDelay = attrs.get('prop_delay',"") if attrs.has_key('weight'): newSynapseProps.weight = attrs.get('weight',"") if attrs.has_key('threshold'): newSynapseProps.threshold = attrs.get('threshold',"") self.globalSynapseProps[self.latestSynapseType] = newSynapseProps for synProp in self.globalSynapseProps.keys(): self.log.debug("globalSynapseProp "+synProp+": "+ str(self.globalSynapseProps[synProp])) elif name == 'properties': if self.currentProjectionName != "": synapse_type = "" if attrs.has_key('synapse_type'): synapse_type = attrs.get('synapse_type',"") elif len(self.localSynapseProps) == 1: synapse_type = self.localSynapseProps.keys()[0] if synapse_type != "": synProps = self.localSynapseProps[synapse_type] self.log.debug("Changing values of local syn props of: "+ synapse_type+", was: "+ str(synProps)) if attrs.has_key('internal_delay'): synProps.internalDelay = attrs.get('internal_delay',"") if attrs.has_key('pre_delay'): synProps.preDelay = attrs.get('pre_delay',"") if attrs.has_key('post_delay'): synProps.postDelay = attrs.get('post_delay',"") if attrs.has_key('prop_delay'): synProps.propDelay = attrs.get('prop_delay',"") if attrs.has_key('weight'): synProps.weight = attrs.get('weight',"") if attrs.has_key('threshold'): synProps.threshold = attrs.get('threshold',"") self.log.info("Changed vals of local syn props: "+ synapse_type+": "+ str(synProps)) elif name == 'input': self.currentInputName = attrs.get('name',"") self.log.info("Found input element: "+ self.currentInputName) elif name == 'random_stim': self.currentInputProps["synaptic_mechanism"] = attrs.get('synaptic_mechanism',"") self.currentInputProps["frequency"] = attrs.get('frequency',"") self.log.info("Found input properties: "+ str(self.currentInputProps)) elif name == 'target': self.currentInputTarget = attrs.get('cell_group',"") if len(self.currentInputTarget) == 0: self.currentInputTarget = attrs.get('population',"") self.log.info("Input: "+ self.currentInputName+" is to population: "+self.currentInputTarget) elif name == 'sites': size = -1 if attrs.has_key('size'): size = int(attrs.get('size',"")) self.netHandler.handleInputSource(self.currentInputName, self.currentInputTarget, self.currentInputProps, size) elif name == 'site': cell_id = int(attrs.get('cell_id',"")) segment_id = 0 fract = 0.5 if attrs.has_key('segment_id'): segment_id = int(attrs.get('segment_id',"")) if attrs.has_key('fract'): fract = float(attrs.get('fract',"")) self.netHandler.handleSingleInput(self.currentInputName, cell_id, segment_id, fract) else: others = ["populations", "projections", "connections", "inputs", "meta:tag", "meta:value", "meta:property", "meta:properties"] if (others.count(name) == 0): print 'Unhandled, unknown element: '+ name return
def startGroup(self, g): self.log.debug("Going into a group: " + g._v_name) if g._v_name.count('population_') >= 1: # TODO: a better check to see if the attribute is a str or numpy.ndarray self.currPopulation = g._v_attrs.name[0] if (len(self.currPopulation) == 1 ): # i.e. it was a str and just took the first letter... self.currPopulation = g._v_attrs.name self.currentCellType = g._v_attrs.cell_type[0] if (len(self.currentCellType) == 1): self.currentCellType = g._v_attrs.cell_type size = -1 # Peek ahead for size... for node in g: if node._c_classId == 'ARRAY' and node.name == self.currPopulation: size = node.shape[0] self.log.debug("Found a population: " + self.currPopulation + ", cell type: " + self.currentCellType + ", size: " + str(size)) self.netHandler.handlePopulation(self.currPopulation, self.currentCellType, size) if g._v_name.count('projection_') >= 1: self.currentProjectionName = g._v_attrs.name[0] self.currentProjectionSource = g._v_attrs.source[0] self.currentProjectionTarget = g._v_attrs.target[0] self.globalSynapseProps = {} self.log.debug("------ Found a projection: " + self.currentProjectionName + ", from " + self.currentProjectionSource + " to " + self.currentProjectionTarget) if g._v_name.count('synapse_props_') >= 1: newSynapseProps = SynapseProperties() name = g._v_name[len('synapse_props_'):] #print dir(g._v_attrs) for attrName in g._v_attrs._v_attrnames: val = g._v_attrs.__getattr__(attrName) self.log.debug("Val of attribute: " + attrName + " is " + str(val)) if attrName == "internal_delay": newSynapseProps.internalDelay = val[0] if attrName == "pre_delay": newSynapseProps.preDelay = val[0] if attrName == "post_delay": newSynapseProps.postDelay = val[0] if attrName == "prop_delay": newSynapseProps.propDelay = val[0] if attrName == "weight": newSynapseProps.weight = val[0] if attrName == "threshold": newSynapseProps.threshold = val[0] self.log.debug(str(newSynapseProps)) self.globalSynapseProps[name] = newSynapseProps self.log.debug("Global syn props: " + str(self.globalSynapseProps))