Changeset 887 for branches

Show
Ignore:
Timestamp:
01/04/11 15:03:24 (17 months ago)
Author:
apdavison
Message:

In reorganization branch, added support for recording from native cells in NEURON.

Location:
branches/reorganization
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • branches/reorganization/src/nest/cells.py

    r882 r887  
    2323 
    2424def 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')) 
    2626 
    2727def get_recordables(model_name): 
     
    4343        cls.injectable = ("V_m" in cls.default_initial_values) 
    4444        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')) 
    4646        cls.nest_name  = {"on_grid": cls.nest_model, "off_grid": cls.nest_model} 
    4747        cls.conductance_based = ("g" in (s[0] for s in cls.recordable)) 
  • branches/reorganization/src/neuron/cells.py

    r875 r887  
    77 
    88from pyNN.standardmodels import cells, build_translations 
     9from pyNN.models import BaseCellType 
    910from pyNN import errors 
    1011from neuron import h, nrn, hclass 
     
    3031        return getattr(obj, attr_name) 
    3132    return property(fset=set, fget=get) 
     33 
     34 
     35class NativeCellType(BaseCellType): 
     36    pass 
    3237 
    3338 
  • branches/reorganization/src/neuron/electrodes.py

    r870 r887  
    6767        for id in cell_list: 
    6868            if id.local: 
    69                 if 'v' not in id.celltype.recordable: 
     69                if not id.celltype.injectable: 
    7070                    raise TypeError("Can't inject current into a spike source.") 
    7171                iclamp = h.IClamp(0.5, sec=id._cell.source_section) 
  • branches/reorganization/src/neuron/recording.py

    r847 r887  
    22from pyNN import recording 
    33from pyNN.neuron import simulator 
     4import re 
     5from neuron import h 
     6 
     7recordable_pattern = re.compile(r'(?P<section>\w+)(\((?P<location>[-+]?[0-9]*\.?[0-9]+)\))?\.(?P<var>\w+)') 
    48 
    59# --- For implementation of record_X()/get_X()/print_X() ----------------------- 
     
    2428                    id._cell.record_gsyn("inhibitory_TM", 1) 
    2529        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: 
    2649            raise Exception("Recording of %s not implemented." % self.variable) 
    27          
     50     
    2851    def _get(self, gather=False, compatible_output=True, filter=None): 
    2952        """Return the recorded data as a Numpy array.""" 
     
    6992                data = numpy.concatenate((data, new_data)) 
    7093        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) 
    72101        if gather and simulator.state.num_processes > 1: 
    73102            data = recording.gather(data) 
  • branches/reorganization/test/system/test_nest.py

    r882 r887  
    5656    id, t, v = p1.recorders['V_m'].get().T 
    5757    assert v.max() > 0.0 # should have some spikes 
    58      
     58 
     59  
    5960def test_native_stdp_model(): 
    6061    nest = pyNN.nest 
  • branches/reorganization/test/system/test_neuron.py

    r851 r887  
    22from scenarios import scenarios 
    33from nose.tools import assert_equal, assert_almost_equal 
     4from pyNN.random import RandomDistribution 
     5from pyNN.utility import init_logging 
    46 
    57try: 
    68    import pyNN.neuron 
     9    from pyNN.neuron.cells import _new_property, NativeCellType 
     10    from nrnutils import Mechanism, Section 
    711    have_neuron = True 
    812except ImportError: 
    913    have_neuron = False 
     14 
     15    
    1016 
    1117def test_scenarios(): 
     
    3238    assert_almost_equal(pynn.get_current_time(), 10.0, places=11) 
    3339    assert_equal(cell[0]._cell.interval, 1000.0/12.0) 
     40 
     41 
     42class SimpleNeuron(object): 
    3443     
     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 
     99class 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 
     106def 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  
    99    recordable = ['v'] 
    1010    parameters = ['romans', 'judeans'] 
     11    injectable = True 
    1112    @classmethod 
    1213    def has_parameter(cls, name):