- Timestamp:
- 01/04/11 15:03:24 (17 months ago)
- Location:
- branches/reorganization
- Files:
-
- 1 added
- 7 modified
-
doc/nonstandardmodels.txt (added)
-
src/nest/cells.py (modified) (2 diffs)
-
src/neuron/cells.py (modified) (2 diffs)
-
src/neuron/electrodes.py (modified) (1 diff)
-
src/neuron/recording.py (modified) (3 diffs)
-
test/system/test_nest.py (modified) (1 diff)
-
test/system/test_neuron.py (modified) (2 diffs)
-
test/unittests/test_neuron.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/reorganization/src/nest/cells.py
r882 r887 23 23 24 24 def get_receptor_types(model_name): 25 return nest.GetDefaults(model_name).get("receptor_types", [])25 return nest.GetDefaults(model_name).get("receptor_types", ('excitatory', 'inhibitory')) 26 26 27 27 def get_recordables(model_name): … … 43 43 cls.injectable = ("V_m" in cls.default_initial_values) 44 44 cls.recordable = get_recordables(cls.nest_model) + ['spikes'] 45 cls.standard_receptor_type = ( len(cls.synapse_types) == 0)45 cls.standard_receptor_type = (cls.synapse_types == ('excitatory', 'inhibitory')) 46 46 cls.nest_name = {"on_grid": cls.nest_model, "off_grid": cls.nest_model} 47 47 cls.conductance_based = ("g" in (s[0] for s in cls.recordable)) -
branches/reorganization/src/neuron/cells.py
r875 r887 7 7 8 8 from pyNN.standardmodels import cells, build_translations 9 from pyNN.models import BaseCellType 9 10 from pyNN import errors 10 11 from neuron import h, nrn, hclass … … 30 31 return getattr(obj, attr_name) 31 32 return property(fset=set, fget=get) 33 34 35 class NativeCellType(BaseCellType): 36 pass 32 37 33 38 -
branches/reorganization/src/neuron/electrodes.py
r870 r887 67 67 for id in cell_list: 68 68 if id.local: 69 if 'v' not in id.celltype.recordable:69 if not id.celltype.injectable: 70 70 raise TypeError("Can't inject current into a spike source.") 71 71 iclamp = h.IClamp(0.5, sec=id._cell.source_section) -
branches/reorganization/src/neuron/recording.py
r847 r887 2 2 from pyNN import recording 3 3 from pyNN.neuron import simulator 4 import re 5 from neuron import h 6 7 recordable_pattern = re.compile(r'(?P<section>\w+)(\((?P<location>[-+]?[0-9]*\.?[0-9]+)\))?\.(?P<var>\w+)') 4 8 5 9 # --- For implementation of record_X()/get_X()/print_X() ----------------------- … … 24 28 id._cell.record_gsyn("inhibitory_TM", 1) 25 29 else: 30 for id in new_ids: 31 self._native_record(id) 32 33 def _native_record(self, id): 34 match = recordable_pattern.match(self.variable) 35 if match: 36 parts = match.groupdict() 37 section = getattr(id._cell, parts['section']) 38 if parts['location']: 39 segment = section(float(parts['location'])) 40 else: 41 segment = section 42 id._cell.traces[self.variable] = vec = h.Vector() 43 vec.record(getattr(segment, "_ref_%s" % parts['var'])) 44 if not id._cell.recording_time: 45 id._cell.record_times = h.Vector() 46 id._cell.record_times.record(h._ref_t) 47 id._cell.recording_time += 1 48 else: 26 49 raise Exception("Recording of %s not implemented." % self.variable) 27 50 28 51 def _get(self, gather=False, compatible_output=True, filter=None): 29 52 """Return the recorded data as a Numpy array.""" … … 69 92 data = numpy.concatenate((data, new_data)) 70 93 else: 71 raise Exception("Recording of %s not implemented." % self.variable) 94 data = numpy.empty((0,3)) 95 for id in self.filter_recorded(filter): 96 var = numpy.array(id._cell.traces[self.variable]) 97 t = numpy.array(id._cell.record_times) 98 new_data = numpy.array([numpy.ones(var.shape)*id, t, var]).T 99 data = numpy.concatenate((data, new_data)) 100 #raise Exception("Recording of %s not implemented." % self.variable) 72 101 if gather and simulator.state.num_processes > 1: 73 102 data = recording.gather(data) -
branches/reorganization/test/system/test_nest.py
r882 r887 56 56 id, t, v = p1.recorders['V_m'].get().T 57 57 assert v.max() > 0.0 # should have some spikes 58 58 59 59 60 def test_native_stdp_model(): 60 61 nest = pyNN.nest -
branches/reorganization/test/system/test_neuron.py
r851 r887 2 2 from scenarios import scenarios 3 3 from nose.tools import assert_equal, assert_almost_equal 4 from pyNN.random import RandomDistribution 5 from pyNN.utility import init_logging 4 6 5 7 try: 6 8 import pyNN.neuron 9 from pyNN.neuron.cells import _new_property, NativeCellType 10 from nrnutils import Mechanism, Section 7 11 have_neuron = True 8 12 except ImportError: 9 13 have_neuron = False 14 15 10 16 11 17 def test_scenarios(): … … 32 38 assert_almost_equal(pynn.get_current_time(), 10.0, places=11) 33 39 assert_equal(cell[0]._cell.interval, 1000.0/12.0) 40 41 42 class SimpleNeuron(object): 34 43 44 def __init__(self, **parameters): 45 # define ion channel parameters 46 leak = Mechanism('pas', e=-65, g=parameters['g_leak']) 47 hh = Mechanism('hh', gl=parameters['g_leak'], el=-65, 48 gnabar=parameters['gnabar'], gkbar=parameters['gkbar']) 49 # create cable sections 50 self.soma = Section(L=30, diam=30, mechanisms=[hh]) 51 self.apical = Section(L=600, diam=2, nseg=5, mechanisms=[leak], parent=self.soma, 52 connect_to=1) 53 self.basilar = Section(L=600, diam=2, nseg=5, mechanisms=[leak], parent=self.soma) 54 self.axon = Section(L=1000, diam=1, nseg=37, mechanisms=[hh]) 55 # synaptic input 56 self.apical.add_synapse('ampa', 'Exp2Syn', e=0.0, tau1=0.1, tau2=5.0) 57 58 # needed for PyNN 59 self.source_section = self.soma 60 self.source = self.soma(0.5)._ref_v 61 self.parameter_names = ('g_leak', 'gnabar', 'gkbar') 62 self.traces = {} 63 self.recording_time = False 64 65 def _set_g_leak(self, value): 66 for sec in (self.apical, self.basilar): 67 for seg in sec: 68 seg.pas.g = value 69 for sec in (self.soma, self.axon): 70 for seg in sec: 71 seg.hh.gl = value 72 def _get_g_leak(self): 73 return self.apical(0.5).pas.g 74 g_leak = property(fget=_get_g_leak, fset=_set_g_leak) 75 76 def _set_gnabar(self, value): 77 for sec in (self.soma, self.axon): 78 for seg in sec: 79 seg.hh.gnabar = value 80 def _get_gnabar(self): 81 return self.soma(0.5).hh.gnabar 82 gnabar = property(fget=_get_gnabar, fset=_set_gnabar) 83 84 def _set_gkbar(self, value): 85 for sec in (self.soma, self.axon): 86 for seg in sec: 87 seg.hh.gkbar = value 88 def _get_gkbar(self): 89 return self.soma(0.5).hh.gkbar 90 gkbar = property(fget=_get_gkbar, fset=_set_gkbar) 91 92 def memb_init(self): 93 """needed for PyNN""" 94 for sec in (self.soma, self.axon, self.apical, self.basilar): 95 for seg in sec: 96 seg.v = self.v_init 97 98 99 class SimpleNeuronType(NativeCellType): 100 default_parameters = {'g_leak': 0.0002, 'gkbar': 0.036, 'gnabar': 0.12} 101 default_initial_values = {'v': -65.0} 102 recordable = ['apical(1.0).v', 'soma(0.5).ina'] # this is not good - over-ride Population.can_record()? 103 model = SimpleNeuron 104 105 106 def test_record_native_model(): 107 nrn = pyNN.neuron 108 109 init_logging(logfile=None, debug=True) 110 nrn.setup() 111 112 parameters = {'g_leak': 0.0003} 113 p1 = nrn.Population(10, SimpleNeuronType, parameters) 114 print p1.get('g_leak') 115 p1.rset('gnabar', RandomDistribution('uniform', [0.10, 0.14])) 116 print p1.get('gnabar') 117 p1.initialize('v', -63.0) 118 119 current_source = nrn.StepCurrentSource([50.0, 110.0, 150.0, 210.0], 120 [0.4, 0.6, -0.2, 0.2]) 121 p1.inject(current_source) 122 123 p2 = nrn.Population(1, nrn.SpikeSourcePoisson, {'rate': 100.0}) 124 125 p1._record('apical(1.0).v') 126 p1._record('soma(0.5).ina') 127 128 connector = nrn.AllToAllConnector(weights=0.1) 129 prj_alpha = nrn.Projection(p2, p1, connector, target='apical.ampa') 130 131 nrn.run(250.0) 132 133 assert_equal(p1.recorders['apical(1.0).v'].get().shape, (25010, 3)) 134 id, t, v = p1.recorders['apical(1.0).v'].get().T 135 return id, t, v -
branches/reorganization/test/unittests/test_neuron.py
r870 r887 9 9 recordable = ['v'] 10 10 parameters = ['romans', 'judeans'] 11 injectable = True 11 12 @classmethod 12 13 def has_parameter(cls, name):
