Changeset 1026 for branches

Show
Ignore:
Timestamp:
12/08/11 11:16:40 (6 months ago)
Author:
apdavison
Message:

In neo_output branch, fixed a bug when recording gsyn, re-added scaling and prepending of initial value for nest data

Location:
branches/neo_output/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/neo_output/src/nest/__init__.py

    r1025 r1026  
    3434NEST_SYNAPSE_TYPES = nest.Models(mtype='synapses') 
    3535 
    36 STATE_VARIABLE_MAP = {"v": "V_m", "w": "w"} 
     36STATE_VARIABLE_MAP = {"v": "V_m", "w": "w", "gsyn_exc": "g_ex", 
     37                      "gsyn_inh": "g_in"} 
    3738logger = logging.getLogger("PyNN") 
    3839 
     
    286287 
    287288    def _set_initial_value_array(self, variable, value): 
    288         if variable in STATE_VARIABLE_MAP: 
    289             variable = STATE_VARIABLE_MAP[variable] 
    290         nest.SetStatus(self.local_cells.tolist(), variable, value) 
     289        variable = STATE_VARIABLE_MAP.get(variable, variable) 
     290        try: 
     291            nest.SetStatus(self.local_cells.tolist(), variable, value) 
     292        except nest.NESTError, e: 
     293            logger.warning("NEST does not allow setting an initial value for %s" % variable) # assuming this is an "Unused dictionary items" error - should really check 
    291294 
    292295 
  • branches/neo_output/src/nest/recording.py

    r1025 r1026  
    1919VARIABLE_MAP = {'v': 'V_m', 'gsyn_exc': 'g_ex', 'gsyn_inh': 'g_in'} 
    2020REVERSE_VARIABLE_MAP = dict((v,k) for k,v in VARIABLE_MAP.items()) 
     21SCALE_FACTORS = {'v': 1, 'gsyn_exc': 0.001, 'gsyn_inh': 0.001} 
    2122 
    2223logger = logging.getLogger("PyNN") 
     
    5556        each neuron, ids as keys. 
    5657        """ 
     58        scale_factor = SCALE_FACTORS.get(variable, 1) 
     59        nest_variable = VARIABLE_MAP.get(variable, variable) 
    5760        events = nest.GetStatus(self.device,'events')[0] 
    5861        ids = events['senders'] 
    59         values = events[variable] 
     62        values = events[nest_variable] * scale_factor # I'm hoping numpy optimises for the case where scale_factor = 1, otherwise should avoid this multiplication in that case 
    6063        data = {} 
    6164        for id in desired_ids: 
    6265            data[id] = values[ids==id] 
     66            if variable != 'spikes': 
     67                initial_value = id.get_initial_value(variable) 
     68                data[id] = numpy.concatenate(([initial_value], data[id])) 
    6369        return data 
    64      
     70 
    6571 
    6672class SpikeDetector(RecordingDevice): 
     
    115121        current_variables.add(VARIABLE_MAP.get(variable, variable)) 
    116122        _set_status(self.device, {'record_from': list(current_variables)}) 
    117      
    118  
    119123 
    120124 
     
    416420                    for id in self.filter_recorded('spikes', filter_ids)] 
    417421            else: 
    418                 data = self._multimeter.get_data(VARIABLE_MAP.get(variable, variable), 
     422                data = self._multimeter.get_data(variable, 
    419423                                                 self.filter_recorded(variable, filter_ids)) 
    420                 segment.analogsignals = [ 
     424                segment.analogsignals.extend( 
    421425                    neo.AnalogSignal(data[id], 
    422426                                     units=recording.UNITS_MAP.get(variable, 'dimensionless'), 
     
    426430                                     source_population=self.population.label, 
    427431                                     source_id=int(id)) 
    428                     for id in self.filter_recorded(variable, filter_ids)] 
     432                    for id in self.filter_recorded(variable, filter_ids)) 
    429433        return segment 
    430434 
  • branches/neo_output/src/nest/simulator.py

    r1025 r1026  
    126126            gid = self 
    127127        try: 
    128             #nest does not like numpy array and so we will convert them to lists whenever we encounter one 
    129             for key in parameters: 
    130                 if type(parameters[key]) == numpy.ndarray: 
    131                    parameters[key] = parameters[key].tolist() 
     128            #nest does not like numpy array if numpy was not available when it was compiled, and so we will convert them to lists whenever we encounter one 
     129            # to avoid this inefficiency, would be better to check at import time that NEST has been built with numpy support and raise an Exception if it hasn't 
     130            for key in parameters: 
     131                if type(parameters[key]) == numpy.ndarray: 
     132                   parameters[key] = parameters[key].tolist() 
    132133            nest.SetStatus([gid], [parameters]) 
    133134        except: # I can't seem to catch the NESTError that is raised, hence this roundabout way of doing it. 
  • branches/neo_output/src/neuron/recording.py

    r1008 r1026  
    145145                else: 
    146146                    signal = lambda id: id._cell.traces[variable] 
    147                 segment.analogsignals = [ 
     147                segment.analogsignals.extend( 
    148148                    neo.AnalogSignal(get_signal(id), # assuming not using cvode, otherwise need to use IrregularlySampledAnalogSignal 
    149149                                     units=recording.UNITS_MAP.get(variable, 'dimensionless'), 
     
    153153                                     source_population=self.population.label, 
    154154                                     source_id=int(id)) 
    155                     for id in self.filter_recorded(variable, filter_ids) 
    156                 ] 
     155                    for id in self.filter_recorded(variable, filter_ids)) 
    157156                assert segment.analogsignals[0].t_stop - simulator.state.t*pq.ms < simulator.state.dt*pq.ms 
    158157                # need to add `Unit` and `RecordingChannel` objects 
  • branches/neo_output/src/standardmodels/cells.py

    r1025 r1026  
    101101    default_initial_values = { 
    102102        'v': -65.0, #'v_rest', 
     103        'gsyn_exc': 0.0, 
     104        'gsyn_inh': 0.0, 
    103105    } 
    104106     
     
    125127    default_initial_values = { 
    126128        'v': -65.0, #'v_rest', 
     129        'gsyn_exc': 0.0, 
     130        'gsyn_inh': 0.0, 
    127131    } 
    128132 
     
    162166    default_initial_values = { 
    163167        'v': -65.0, #'v_rest', 
     168        'gsyn_exc': 0.0, 
     169        'gsyn_inh': 0.0, 
    164170    } 
    165171     
     
    187193    default_initial_values = { 
    188194        'v': -65.0, #'v_rest', 
     195        'gsyn_exc': 0.0, 
     196        'gsyn_inh': 0.0, 
    189197    } 
    190198 
     
    213221    default_initial_values = { 
    214222        'v': -65.0, #'v_rest', 
     223        'gsyn_exc': 0.0, 
     224        'gsyn_inh': 0.0, 
    215225    } 
    216226 
     
    248258        'v': -65.0, #'v_rest', 
    249259        'w': 0.0, 
     260        'gsyn_exc': 0.0, 
     261        'gsyn_inh': 0.0, 
    250262    } 
    251263 
     
    283295        'v': -65.0, #'v_rest', 
    284296        'w': 0.0, 
     297        'gsyn_exc': 0.0, 
     298        'gsyn_inh': 0.0, 
    285299    } 
    286300