Skip to content

Commit

Permalink
Minor updates for NetworkBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Dec 11, 2018
1 parent 71bd9dc commit c66e30e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion neuroml/hdf5/DefaultNetworkHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def handle_network(self, network_id, notes, temperature=None):
#
# Should be overridden to create population array
#
def handle_population(self, population_id, component, size=-1, component_obj=None, properties={}):
def handle_population(self, population_id, component, size=-1, component_obj=None, properties={}, notes=None):
sizeInfo = " as yet unspecified size"
if size>=0:
sizeInfo = " size: "+ str(size)+ " cells"
Expand Down
16 changes: 13 additions & 3 deletions neuroml/hdf5/NetworkBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class NetworkBuilder(DefaultNetworkHandler):
populations = {}
projections = {}
projection_syns = {}
projection_types = {}
projection_syns_pre = {}
input_lists = {}

Expand Down Expand Up @@ -61,12 +62,16 @@ def handle_network(self, network_id, notes, temperature=None):
#
# Overridden from DefaultNetworkHandler
#
def handle_population(self, population_id, component, size, component_obj=None, properties={}):
def handle_population(self, population_id, component, size, component_obj=None, properties={}, notes=None):

if component_obj:
self.nml_doc.append(component_obj)

pop = neuroml.Population(id=population_id, component=component, size=size)

if notes and len(notes)>0:
pop.notes = notes

self.populations[population_id] = pop
self.network.populations.append(pop)
for p in properties:
Expand Down Expand Up @@ -129,18 +134,23 @@ def handle_projection(self, id, prePop, postPop, synapse, hasWeights=False, hasD
self.projection_syns_pre[id] = pre_synapse_obj.id

self.projections[id] = proj
self.projection_types[id] = type
self.weightDelays[id] = hasWeights or hasDelays

self.log.debug("Projection: %s (%s) from %s to %s with syn: %s, weights: %s, delays: %s"%(id, type, prePop, postPop, synapse, hasWeights, hasDelays))

#
# Overridden from DefaultNetworkHandler
#
def finalise_projection(self, id, prePop, postPop, synapse=None, type="projection"):
def finalise_projection(self, id, prePop, postPop, synapse=None, type=None):
'''
Check whether handle_projection was not called, e.g. due to no connections present
'''
self.log.debug("Projection: %s from %s to %s completed"%(id,prePop,postPop))
if type==None:
type=self.projection_types[id]

self.log.debug("Projection: %s (%s) from %s to %s completed"%(id,type,prePop,postPop))

if type=="projection":
present = False
for p in self.network.projections:
Expand Down
6 changes: 3 additions & 3 deletions neuroml/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def write(cls,nmldoc,file,close=True):
via chain of responsibility pattern.
"""

if isinstance(file,str):
if isinstance(file,str) or isinstance(file,unicode):
file = open(file,'w')

#TODO: this should be extracted from the schema:
Expand Down Expand Up @@ -138,14 +138,14 @@ def __sanitize_doc(cls,neuroml_document):

@classmethod
def __file_handle(file):
if isinstance(cls,file,str):
if isinstance(cls,file,str) or isinstance(cls,file,unicode):
import tables
fileh = tables.open_file(filepath, mode = "w")


@classmethod
def write(cls,neuroml_document,file):
if isinstance(file,str):
if isinstance(file,str) or isinstance(file,unicode):
fileh = open(file, mode = 'w')
else:
fileh = file
Expand Down

0 comments on commit c66e30e

Please sign in to comment.