In the third chapter we tested a reduced neuron model. Here we'll test a multicomparmental Cerebellar Granule Cell model using data from the NeuroElectro project.
import os
import quantities as pq
import sciunit
from neuronunit import tests,capabilities
from neuronunit import neuroelectro # This module allows interaction with NeuroElecto through a REST API.
In this example, we'll use models downloaded from Open Source Brain and run via neuroConstruct using execnet.
import neuronunit.neuroconstruct.models as nc_models # Model classes for use with neuroConstruct
# (http://www.neuroconstruct.org), a model and
# simulation manager for detailed neuron models.
from pythonnC.utils.putils import OSB_MODELS # Path to models downloaded from Open Source Brain.
# We will test cerebellar granule cell models.
brain_area = 'cerebellum'
neuron_type = 'cerebellar_granule_cell'
neuron_type_path = os.path.join(OSB_MODELS,brain_area,neuron_type)
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) /opt/conda/lib/python3.5/site-packages/neuronunit-0.1.8.6-py3.5.egg/neuronunit/neuroconstruct/__init__.py in <module>() 6 try: ----> 7 NC_HOME = os.environ["NC_HOME"] 8 except KeyError: /opt/conda/lib/python3.5/os.py in __getitem__(self, key) 724 # raise KeyError with the original key value --> 725 raise KeyError(key) from None 726 return self.decodevalue(value) KeyError: 'NC_HOME' During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) <ipython-input-2-e9bc29934011> in <module>() ----> 1 import neuronunit.neuroconstruct.models as nc_models # Model classes for use with neuroConstruct 2 # (http://www.neuroconstruct.org), a model and 3 # simulation manager for detailed neuron models. 4 from pythonnC.utils.putils import OSB_MODELS # Path to models downloaded from Open Source Brain. 5 /opt/conda/lib/python3.5/site-packages/neuronunit-0.1.8.6-py3.5.egg/neuronunit/neuroconstruct/__init__.py in <module>() 8 except KeyError: 9 raise Exception("Please add an NC_HOME environment variable corresponding\ ---> 10 to the location of the neuroConstruct directory.") 11 12 if NC_HOME not in sys.path: Exception: Please add an NC_HOME environment variable corresponding to the location of the neuroConstruct directory.
neurolex_id = 'nifext_128' # Cerebellar Granule Cell
One for resting membrane potential:
# Specify reference data for a test of resting potential for a granule cell.
reference_data = neuroelectro.NeuroElectroSummary(
neuron = {'nlex_id':neurolex_id}, # Neuron type lookup using the NeuroLex ID.
ephysprop = {'name':'Resting Membrane Potential'}) # Ephys property name in the NeuroElectro ontology.
reference_data.get_values() # Get and verify summary data for the combination above from neuroelectro.org.
rmp_test = tests.RestingPotentialTest(
observation = {'mean':reference_data.mean*pq.mV, # In millivolts.
'std':reference_data.std*pq.mV},
name = 'Resting Potential')
Getting data values from neuroelectro.org http://www.neuroelectro.org/api/1/nes/?nlex=nifext_128&e__name=Resting+Membrane+Potential
And one for action potential width:
# Specify reference data for a test of action potential width.
reference_data = neuroelectro.NeuroElectroSummary(
neuron = {'nlex_id':neurolex_id}, # Neuron type lookup using the NeuroLex ID.
ephysprop = {'name':'Spike Half-Width'}) # Ephys property name in the NeuroElectro ontology.
reference_data.get_values() # Get and verify summary data for the combination above from neuroelectro.org.
spikewidth_test = tests.InjectedCurrentAPWidthTest(
observation = {'mean':reference_data.mean*pq.ms, # In milliseconds.
'std':reference_data.std*pq.ms},
name = 'Spike Width',
params={'injected_square_current':{'amplitude':6.0*pq.pA,
'delay':50.0*pq.ms,
'duration':500.0*pq.ms}}) # 6 pA of injected current in a 500 ms square pulse.
Getting data values from neuroelectro.org http://www.neuroelectro.org/api/1/nes/?nlex=nifext_128&e__name=Spike+Half-Width
x = tests.InjectedCurrentAPWidthTest(
observation = {'mean':reference_data.mean*pq.ms, # In milliseconds.
'std':reference_data.std*pq.ms},
name = 'Spike Width',
injected_square_current = {'amplitude':6.0*pq.pA,
'delay':50.0*pq.ms,
'duration':500.0*pq.ms}) # 6 pA of injected current in a 500 ms square pulse.
x.params
{'injected_square_current': {'amplitude': array(6.0) * pA, 'delay': array(50.0) * ms, 'duration': array(500.0) * ms}, 'params': {'injected_square_current': {'amplitude': array(6.0) * pA, 'delay': array(50.0) * ms, 'duration': array(500.0) * ms}}}
# Create a test suite from these two tests.
suite = sciunit.TestSuite('EPhys Tests',(spikewidth_test,rmp_test))
Let's instantiate a few different granule cell models and add them to a list to be tested.
Each of them is already parameterized in corresponding NeuroML files associated with the Open Source Brain project.
model_names = ['GranuleCell','cereb_grc_mc'] # The names of two granule cell models
# available at http://opensourcebrain.org.
models = [] # Our list of models to be tested.
for model_name in model_names:
model_info = (brain_area,neuron_type,model_name) # Information about each model.
model = nc_models.OSBModel(*model_info) # Instantiate a model using that information.
models.append(model) # Add to the list of models to be tested.
# Running these 2 tests against these 2 models means 4 total simulations.
score_matrix = suite.judge(models,stop_on_error=True)
Running simulation...
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-10-2a71a1c42b20> in <module>() 1 # Running these 2 tests against these 2 models means 4 total simulations. ----> 2 score_matrix = suite.judge(models,stop_on_error=True) /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py in judge(self, models, skip_incapable, stop_on_error, deep_error) 422 score = test.judge(model, skip_incapable=skip_incapable, 423 stop_on_error=stop_on_error, --> 424 deep_error=deep_error) 425 log('Score is <a style="color: rgb(%d,%d,%d)">' % score.color() 426 + '%s</a>' % score) /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py in judge(self, model, skip_incapable, stop_on_error, deep_error) 294 score = ErrorScore(e) 295 if isinstance(score,ErrorScore) and stop_on_error: --> 296 raise score.score # An exception. 297 return score 298 /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py in judge(self, model, skip_incapable, stop_on_error, deep_error) 288 else: 289 try: --> 290 score = self._judge(model, skip_incapable=skip_incapable) 291 except CapabilityError as e: 292 score = NAScore(str(e)) /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py in _judge(self, model, skip_incapable) 231 self.check_capabilities(model) 232 # 2. --> 233 prediction = self.generate_prediction(model) 234 self.last_model = model 235 # 3. /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neuronunit/tests/__init__.py in generate_prediction(self, model) 576 model.rerun = True 577 model.inject_square_current(self.params['injected_square_current']) --> 578 median = model.get_median_vm() # Use median for robustness. 579 std = model.get_std_vm() 580 prediction = {'mean':median, 'std':std} /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neuronunit/neuroconstruct/capabilities.py in get_median_vm(self, **kwargs) 87 vm = self.get_membrane_potential(**kwargs) 88 # A neo.core.AnalogSignal object ---> 89 median_vm = np.median(vm) 90 return median_vm 91 /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py in median(a, axis, out, overwrite_input, keepdims) 3509 """ 3510 r, k = _ureduce(a, func=_median, axis=axis, out=out, -> 3511 overwrite_input=overwrite_input) 3512 if keepdims: 3513 return r.reshape(k) /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py in _ureduce(a, func, **kwargs) 3423 keepdim = [1] * a.ndim 3424 -> 3425 r = func(a, **kwargs) 3426 return r, keepdim 3427 /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py in _median(a, axis, out, overwrite_input) 3563 rout = mean(part[indexer], axis=axis, out=out) 3564 part = np.rollaxis(part, axis, part.ndim) -> 3565 n = np.isnan(part[..., -1]) 3566 if rout.ndim == 0: 3567 if n == True: /Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neo-0.4.1-py3.5.egg/neo/core/analogsignal.py in __getitem__(self, i) 207 slice_step = i.step 208 elif isinstance(i, tuple) and len(i) == 2: --> 209 slice_start = i[0].start 210 slice_step = i[0].step 211 if slice_start: AttributeError: 'ellipsis' object has no attribute 'start'
The 'cereb_grc_mc' model doesn't seem to spike, so there is insufficient data to produce a score.
score_matrix.view()
%matplotlib inline
import matplotlib.pyplot as plt
fig,ax = plt.subplots(2,2,figsize=(8,6)) # Create plot windows.
for i,test in enumerate(score_matrix.tests): # For each test...
for j,model in enumerate(score_matrix.models): # And each model...
score = score_matrix[test,model] # Get the score.
score.plot_vm(ax[i,j]) # And use a convenience method to plot the membrane potential.
fig.tight_layout() # Space the plots nicely.