Skip to content

Commit

Permalink
Update to allow use with old parser API, e.g. handleNetwork not handl…
Browse files Browse the repository at this point in the history
…e_network
  • Loading branch information
pgleeson committed Dec 20, 2017
1 parent 7380e49 commit 626ca31
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
2 changes: 1 addition & 1 deletion neuroml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .nml.nml import * # allows importation of all neuroml classes

__version__ = '0.2.35'
__version__ = '0.2.36'


current_neuroml_version = "v2beta5"
Binary file modified neuroml/examples/test_files/complete.nml.h5
Binary file not shown.
10 changes: 8 additions & 2 deletions neuroml/hdf5/DefaultNetworkHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def print_location_information(self, id, population_id, component, x, y, z):
position = "(%s, %s, %s)" % (x, y, z)
self.log.debug("Location "+str(id)+" of population: "+population_id+", component: "+component+": "+position)


#
# Internal info method, can be reused in overriding classes for debugging
#
Expand All @@ -50,7 +50,13 @@ def print_input_information(self, inputName, population_id, component, size=-1):
sizeInfo = " size: "+ str(size)+ " cells"
self.log.debug("Input Source: "+inputName+", on population: "+population_id+sizeInfo+" with component: "+ component)


# Temp for older API version
def printLocationInformation(self, id, population_id, component, x, y, z):
return self.print_location_information(id, population_id, component, x, y, z)
def printConnectionInformation(self, projName, id, prePop, postPop, synapseType, preCellId, postCellId, weight):
return self.print_connection_information(projName, id, prePop, postPop, synapseType, preCellId, postCellId, weight)
def printInputInformation(self, inputName, population_id, component, size=-1):
return self.print_input_information(inputName, population_id, component, size)

#
# Should be overridden
Expand Down
32 changes: 31 additions & 1 deletion neuroml/hdf5/NeuroMLHdf5Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import logging
import sys
import inspect

import tables # pytables for HDF5 support
import numpy as np
Expand Down Expand Up @@ -61,6 +62,32 @@ def __init__ (self, netHandler, optimized=False):
self.netHandler = netHandler
self.optimized = optimized

if not self.optimized:
# For continued use with old API
if not hasattr(self.netHandler,'handle_network') or hasattr(self.netHandler,'handleNetwork'):
self.netHandler.handle_network = self.netHandler.handleNetwork
if not hasattr(self.netHandler,'handle_document_start') or hasattr(self.netHandler,'handleDocumentStart'):
self.netHandler.handle_document_start = self.netHandler.handleDocumentStart
if not hasattr(self.netHandler,'handle_population') or hasattr(self.netHandler,'handlePopulation'):
self.netHandler.handle_population = self.netHandler.handlePopulation
if not hasattr(self.netHandler,'handle_location') or hasattr(self.netHandler,'handleLocation'):
self.netHandler.handle_location = self.netHandler.handleLocation

if not hasattr(self.netHandler,'handle_projection') or hasattr(self.netHandler,'handleProjection'):
self.netHandler.handle_projection = self.netHandler.handleProjection
if not hasattr(self.netHandler,'finalise_projection') or hasattr(self.netHandler,'finaliseProjection'):
self.netHandler.finalise_projection = self.netHandler.finaliseProjection

if not hasattr(self.netHandler,'handle_connection') or hasattr(self.netHandler,'handleConnection'):
self.netHandler.handle_connection = self.netHandler.handleConnection
if not hasattr(self.netHandler,'handle_input_list') or hasattr(self.netHandler,'handleInputList'):
self.netHandler.handle_input_list = self.netHandler.handleInputList
if not hasattr(self.netHandler,'handle_single_input') or hasattr(self.netHandler,'handleSingleInput'):
self.netHandler.handle_single_input = self.netHandler.handleSingleInput
if not hasattr(self.netHandler,'finalise_input_source') or hasattr(self.netHandler,'finaliseInputSource'):
self.netHandler.finalise_input_source = self.netHandler.finaliseInputSource



def parse(self, filename):

Expand Down Expand Up @@ -463,7 +490,10 @@ def start_group(self, g):
else:
component_obj = None

self.netHandler.handle_population(self.currPopulation, self.currentComponent, size, component_obj=component_obj, properties=properties)
if 'properties' in inspect.getargspec(self.netHandler.handle_population)[0]:
self.netHandler.handle_population(self.currPopulation, self.currentComponent, size, component_obj=component_obj, properties=properties)
else:
self.netHandler.handle_population(self.currPopulation, self.currentComponent, size, component_obj=component_obj)
else:
self.currOptPopulation = PopulationContainer(id=self.currPopulation, component=self.currentComponent, size=size)

Expand Down
60 changes: 51 additions & 9 deletions neuroml/hdf5/NeuroMLXMLParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

import logging
import inspect

class NeuroMLXMLParser():

Expand All @@ -31,6 +32,33 @@ def __init__ (self, netHandler):

self.netHandler = netHandler

# For continued use with old API
if not hasattr(self.netHandler,'handle_network') or hasattr(self.netHandler,'handleNetwork'):
self.netHandler.handle_network = self.netHandler.handleNetwork
if not hasattr(self.netHandler,'handle_document_start') or hasattr(self.netHandler,'handleDocumentStart'):
self.netHandler.handle_document_start = self.netHandler.handleDocumentStart
if not hasattr(self.netHandler,'handle_population') or hasattr(self.netHandler,'handlePopulation'):
self.netHandler.handle_population = self.netHandler.handlePopulation
if not hasattr(self.netHandler,'handle_location') or hasattr(self.netHandler,'handleLocation'):
self.netHandler.handle_location = self.netHandler.handleLocation

if not hasattr(self.netHandler,'handle_projection') or hasattr(self.netHandler,'handleProjection'):
self.netHandler.handle_projection = self.netHandler.handleProjection
if not hasattr(self.netHandler,'finalise_projection') or hasattr(self.netHandler,'finaliseProjection'):
self.netHandler.finalise_projection = self.netHandler.finaliseProjection

if not hasattr(self.netHandler,'handle_connection') or hasattr(self.netHandler,'handleConnection'):
self.netHandler.handle_connection = self.netHandler.handleConnection
if not hasattr(self.netHandler,'handle_input_list') or hasattr(self.netHandler,'handleInputList'):
self.netHandler.handle_input_list = self.netHandler.handleInputList
if not hasattr(self.netHandler,'handle_single_input') or hasattr(self.netHandler,'handleSingleInput'):
self.netHandler.handle_single_input = self.netHandler.handleSingleInput
if not hasattr(self.netHandler,'finalise_input_source') or hasattr(self.netHandler,'finaliseInputSource'):
self.netHandler.finalise_input_source = self.netHandler.finaliseInputSource




def _parse_delay(self, delay_string):
if delay_string.endswith('ms'):
return float(delay_string[:-2].strip())
Expand Down Expand Up @@ -67,11 +95,17 @@ def parse(self, filename):

if len(population.instances)>0 and population.type=='populationList':

self.netHandler.handle_population(population.id,
population.component,
len(population.instances),
component_obj=component_obj,
properties=properties)
if 'properties' in inspect.getargspec(self.netHandler.handle_population)[0]:
self.netHandler.handle_population(population.id,
population.component,
len(population.instances),
component_obj=component_obj,
properties=properties)
else:
self.netHandler.handle_population(population.id,
population.component,
len(population.instances),
component_obj=component_obj)

for inst in population.instances:

Expand All @@ -83,10 +117,18 @@ def parse(self, filename):
loc.y, \
loc.z)
else:
self.netHandler.handle_population(population.id,
population.component,
population.size,
component_obj=component_obj)

if 'properties' in inspect.getargspec(self.netHandler.handle_population)[0]:
self.netHandler.handle_population(population.id,
population.component,
population.size,
component_obj=component_obj,
properties=properties)
else:
self.netHandler.handle_population(population.id,
population.component,
population.size,
component_obj=component_obj)

for i in range(population.size):
self.netHandler.handle_location(i, \
Expand Down

0 comments on commit 626ca31

Please sign in to comment.