In [2]:
%matplotlib inline
import matplotlib.pyplot as g
from neuronunit.neuron.models import *
from neuronunit.tests import *
import neuronunit.neuroelectro
from quantities import nA, pA, s, ms, mV
from neuron import h
# DEBUG TESTING
#from importlib import *
#import neuronunit
#reload(neuronunit.neuron.models)
#from neuronunit.neuron.models import *
In [31]:
soma = h.Section()
soma.L = 100
soma.diam = 100
soma.cm = 10
soma.Ra = 180
soma.insert("pas")
soma.insert("hh")
Out[31]:
In [32]:
mod1 = SingleCellModel(hVar = h, \
section = soma, \
loc = 0.5, # Current and voltage injection and measurement location on the section \
name = "SimpleHHCellModel")
mod1.setIntegrationMethod("fixed") # Or "variable"
mod1.setTimeStep(1/128.0 * ms) # 2^-n are preferable
#mod1.setTolerance(0.01) # Only needed if "variable"
mod1.setStopTime(2*s)
In [33]:
from ipywidgets import interact
def inject(i):
mod1.inject_square_current({'amplitude': float(i)*nA, 'delay': .5*s, 'duration': 5*ms})
g.plot(mod1.get_membrane_potential())
g.show()
g.plot(mod1.get_APs()[0])
g.show()
interact(inject,i="20")
Out[33]:
In [17]:
i_tau = {'amplitude': -1*nA, 'delay': 0.5*s, 'duration': 1*s}
i_ap = {'amplitude': 20*nA, 'delay': 1*s, 'duration': 5*ms}
In [34]:
t1 = neuronunit.tests.InjectedCurrentAPWidthTest({ 'mean': 1.5*ms, 'std': 0.5*ms }) # Example values
t1.params = {'injected_square_current': i_ap }
t2 = neuronunit.tests.RestingPotentialTest({ 'mean': -67*mV, 'std': 5*mV })
suite = sciunit.TestSuite("SimpleTestSuite",[t1,t2])
In [35]:
score = suite.judge(mod1)
score.view()
Out[35]:
In [37]:
# Load previously saved data
import pickle
# These are saved in ExperimentalObservations notebook
with open("observations.dat", "rb") as file:
observations = pickle.load(file)
# Define the tests to perform on the cell
testTypes = [ \
[InputResistanceTest, None],
[RestingPotentialTest, None],
[TimeConstantTest, {'injected_square_current': i_tau }],
[InjectedCurrentAPWidthTest, {'injected_square_current': i_ap }], \
[InjectedCurrentAPThresholdTest, {'injected_square_current': i_ap }], \
[InjectedCurrentAPAmplitudeTest, {'injected_square_current': i_ap }],
]
tests = []
# Fetch NeuroElectro property values for each test
for t in xrange(len(testTypes)):
testType = testTypes[t][0]
params = testTypes[t][1]
# Create a test instance using the observations
test = testType(observations["Pooled"][testType.name])
if(params is not None):
test.params = params
tests.append(test)
# Create a test suite
suite = sciunit.TestSuite("Membrane Property Tests", tests)
In [38]:
score = suite.judge(mod1)
score.view()
Out[38]: