Skip to content

Commit

Permalink
Harmonized signature of inject_current (now inject_square_current) ac…
Browse files Browse the repository at this point in the history
…ross modules
  • Loading branch information
rgerkin committed May 20, 2016
1 parent f146c2a commit d00286c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ reference_data = neuroelectro.NeuroElectroSummary(
ephysprop = {'name':'Spike Half-Width'}) # Electrophysiological property name.
# Get and verify summary data for the combination above from neuroelectro.org.
reference_data.get_values()
spikewidth_test = tests.InjectedCurrentSpikeWidthTest(
spikewidth_test = tests.InjectedCurrentAPWidthTest(
observation = {'mean':reference_data.mean,
'std':reference_data.std},
name = 'Spike Width',
params={'injected_current':{'ampl':0.0053}}) # 0.0053 nA (5.3 pA) of injected current.
params={'injected_square_current':{'amplitude':5.3*pq.pA,
'delay':50.0*pq.ms,
'duration':500.0*pq.ms}})
# 5.3 pA of injected current in a 500 ms square pulse.
# Create a test suite from these two tests.
suite = sciunit.TestSuite('Neuron Tests',(spikewidth_test,vm_test))
Expand Down
6 changes: 4 additions & 2 deletions docs/chapter3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@
" ephysprop = {'name':'Spike Half-Width'}) # Ephys property name in the NeuroElectro ontology. \n",
"reference_data.get_values() # Get and verify summary data for the combination above from neuroelectro.org. \n",
"\n",
"spikewidth_test = tests.InjectedCurrentSpikeWidthTest(\n",
"spikewidth_test = tests.InjectedCurrentAPWidthTest(\n",
" observation = {'mean':reference_data.mean*pq.ms, # In milliseconds. \n",
" 'std':reference_data.std*pq.ms},\n",
" name = 'Spike Width',\n",
" params={'injected_current':{'ampl':0.006}}) # 0.0053 nanoamps of injected current. "
" params={'injected_square_current':{'amplitude':6.0*pq.pA,\n",
" 'delay':50.0*pq.ms,\n",
" 'duration':500.0*pq.ms}}) # 6 pA of injected current in a 500 ms square pulse. "
]
},
{
Expand Down
15 changes: 15 additions & 0 deletions neuronunit/capabilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def inject_current(self,current):

raise NotImplementedError()

def inject_square_current(self,current):
"""Injects somatic current into the model.
Parameters
----------
current : a dictionary like:
{'amplitude':-10.0*pq.pA,
'delay':100*pq.ms,
'duration':500*pq.ms}}
where 'pq' is the quantities package
This describes the current to be injected.
"""

raise NotImplementedError()


class Runnable(sciunit.Capability):
"""Capability for models that can be run."""
Expand Down
5 changes: 3 additions & 2 deletions neuronunit/neuroconstruct/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ class Current(object):
duration = 0
offset = 0

def inject_current(self,injected_current):
def inject_square_current(self,injected_current):
self.prepare()
cmd = 'import %s as j;' % JUTILS_PATH
cmd += 'import sys;'
cmd += 'err = j.sim.set_current_ampl(%f);' % injected_current['ampl']
cmd += 'err = j.sim.set_current_ampl(%f);' % \
injected_current['amplitude']
cmd += 'channel.send(err);'
channel = self.gateway.remote_exec(cmd)
#print(cmd)
Expand Down
29 changes: 17 additions & 12 deletions neuronunit/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ class InputResistanceTest(VmTest):

units = pq.ohm*1e6

params = {'injected_current':
params = {'injected_square_current':
{'amplitude':-10.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

ephysprop_name = 'Input Resistance'

def generate_prediction(self, model, verbose=False):
"""Implementation of sciunit.Test.generate_prediction."""
model.inject_current(self.params['injected_current'])
model.inject_square_current(self.params['injected_square_current'])
vm = model.get_membrane_potential()

def get_segment(self,vm,start,finish):
start = int((start/vm.sampling_period).simplified)
finish = int((finish/vm.sampling_period).simplified)
return vm[start:finish]

i = self.params['injected_current']
i = self.params['injected_square_current']
start, stop = -11*pq.ms, -1*pq.ms
before = get_segment(self,vm,start+i['delay'],
stop+i['delay'])
Expand Down Expand Up @@ -198,7 +198,7 @@ class InjectedCurrentAPWidthTest(APWidthTest):

required_capabilities = (cap.ReceivesCurrent,)

params = {'injected_current':
params = {'injected_square_current':
{'amplitude':100.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

name = "Injected current AP width test"
Expand All @@ -208,7 +208,7 @@ class InjectedCurrentAPWidthTest(APWidthTest):
"is injected into cell.")

def generate_prediction(self, model, verbose=False):
model.inject_current(self.params['injected_current'])
model.inject_square_current(self.params['injected_square_current'])
return super(InjectedCurrentAPWidthTest,self).\
generate_prediction(model, verbose=verbose)

Expand Down Expand Up @@ -273,7 +273,7 @@ class InjectedCurrentAPAmplitudeTest(APAmplitudeTest):

required_capabilities = (cap.ReceivesCurrent,)

params = {'injected_current':
params = {'injected_square_current':
{'amplitude':100.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

name = "Injected current AP amplitude test"
Expand All @@ -283,7 +283,7 @@ class InjectedCurrentAPAmplitudeTest(APAmplitudeTest):
"is injected into cell.")

def generate_prediction(self, model, verbose=False):
model.inject_current(self.params['injected_current'])
model.inject_square_current(self.params['injected_square_current'])
return super(InjectedCurrentAPAmplitudeTest,self).\
generate_prediction(model, verbose=verbose)

Expand Down Expand Up @@ -334,7 +334,7 @@ class InjectedCurrentAPThresholdTest(APThresholdTest):

required_capabilities = (cap.ReceivesCurrent,)

params = {'injected_current':
params = {'injected_square_current':
{'amplitude':100.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

name = "Injected current AP threshold test"
Expand All @@ -343,7 +343,7 @@ class InjectedCurrentAPThresholdTest(APThresholdTest):
"action potentials are produced under current injection.")

def generate_prediction(self, model, verbose=False):
model.inject_current(self.params['injected_current'])
model.inject_square_current(self.params['injected_square_current'])
return super(InjectedCurrentAPThresholdTest,self).\
generate_prediction(model, verbose=verbose)

Expand All @@ -357,7 +357,7 @@ class RheobaseTest(VmTest):
required_capabilities = (cap.ReceivesCurrent,
cap.ProducesSpikes)

params = {'injected_current':
params = {'injected_square_current':
{'amplitude':100.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

name = "Rheobase test"
Expand Down Expand Up @@ -406,7 +406,9 @@ def threshold_FI(self, model, units, guess=None, verbose=False):

def f(ampl):
if float(ampl) not in lookup:
model.inject_current({'amplitude':ampl})
current = params.copy()
current['amplitude'] = ampl
model.inject_square_current(current)
n_spikes = model.get_spike_count()
if verbose:
print("Injected %s current and got %d spikes" % \
Expand Down Expand Up @@ -459,6 +461,9 @@ class RestingPotentialTest(VmTest):

required_capabilities = (cap.ReceivesCurrent,)

params = {'injected_square_current':
{'amplitude':0.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

name = "Resting potential test"

description = ("A test of the resting potential of a cell "
Expand All @@ -481,7 +486,7 @@ def validate_observation(self, observation):
def generate_prediction(self, model, verbose=False):
"""Implementation of sciunit.Test.generate_prediction."""
model.rerun = True
model.inject_current({'amplitude':0.0*pq.pA})
model.inject_square_current(self.params['injected_square_current'])
median = model.get_median_vm() # Use median for robustness.
std = model.get_std_vm()
prediction = {'mean':median, 'std':std}
Expand Down
2 changes: 1 addition & 1 deletion neuronunit/tests/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def validate_observation(self, observation):
nonunited_keys=['cv'])

def generate_prediction(self, model, verbose=False):
model.inject_current(observation['current'])
model.inject_square_current(observation['current'])
spike_train = model.get_spike_train()
if len(spike_train) >= 3:
isis = isi(spike_train)
Expand Down

0 comments on commit d00286c

Please sign in to comment.