From d00286ceb20505a82db17c75a7c0bf9cd049e2cf Mon Sep 17 00:00:00 2001 From: Richard C Gerkin Date: Fri, 20 May 2016 11:38:13 -0700 Subject: [PATCH] Harmonized signature of inject_current (now inject_square_current) across modules --- README.md | 7 ++++-- docs/chapter3.ipynb | 6 +++-- neuronunit/capabilities/__init__.py | 15 ++++++++++++ neuronunit/neuroconstruct/capabilities.py | 5 ++-- neuronunit/tests/__init__.py | 29 +++++++++++++---------- neuronunit/tests/dynamics.py | 2 +- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2bfa708e7..da5585a8e 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/docs/chapter3.ipynb b/docs/chapter3.ipynb index 98136fb3a..6336f54ab 100644 --- a/docs/chapter3.ipynb +++ b/docs/chapter3.ipynb @@ -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. " ] }, { diff --git a/neuronunit/capabilities/__init__.py b/neuronunit/capabilities/__init__.py index 74dadadbd..adfb5b3f7 100644 --- a/neuronunit/capabilities/__init__.py +++ b/neuronunit/capabilities/__init__.py @@ -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.""" diff --git a/neuronunit/neuroconstruct/capabilities.py b/neuronunit/neuroconstruct/capabilities.py index 49481b0b7..a4238d65d 100644 --- a/neuronunit/neuroconstruct/capabilities.py +++ b/neuronunit/neuroconstruct/capabilities.py @@ -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) diff --git a/neuronunit/tests/__init__.py b/neuronunit/tests/__init__.py index 8fe983ee3..a1b7a4cf1 100644 --- a/neuronunit/tests/__init__.py +++ b/neuronunit/tests/__init__.py @@ -124,14 +124,14 @@ 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): @@ -139,7 +139,7 @@ def get_segment(self,vm,start,finish): 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']) @@ -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" @@ -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) @@ -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" @@ -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) @@ -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" @@ -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) @@ -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" @@ -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" % \ @@ -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 " @@ -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} diff --git a/neuronunit/tests/dynamics.py b/neuronunit/tests/dynamics.py index e4a5533b9..12f599530 100644 --- a/neuronunit/tests/dynamics.py +++ b/neuronunit/tests/dynamics.py @@ -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)