Changeset 991 for trunk

Show
Ignore:
Timestamp:
09/30/11 15:05:02 (8 months ago)
Author:
apdavison
Message:

Allow modifying parameters of CurrentSource objects after creation in pyNN.nest (patch from Jan Antolik)

Location:
trunk/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common.py

    r979 r991  
    571571                         self.label, parametername, value_array.shape, 
    572572                         value_array.min(), value_array.max()) 
    573         except TypeError:  # min() and max() won't work for non-numeric values 
     573        except (TypeError,ValueError):  # min() and max() won't work for non-numeric values 
    574574            logger.debug("%s.tset('%s', non_numeric_array(shape=%s))", 
    575575                         self.label, parametername, value_array.shape) 
     
    885885            else: 
    886886                raise Exception("A maximum of 3 dimensions is allowed. What do you think this is, string theory?") 
    887             size = reduce(operator.mul, size) 
     887            size = int(reduce(operator.mul, size)) # NEST doesn't like numpy.int, so to be safe we cast to Python int 
    888888        self.size = size 
    889889        self.label = label or 'population%d' % Population.nPop 
  • trunk/src/nest/__init__.py

    r957 r991  
    193193        # perhaps should check for that 
    194194        assert n > 0, 'n must be a positive integer' 
     195        n = int(n) 
     196         
    195197        celltype = cellclass(cellparams) 
    196198        nest_model = celltype.nest_name[simulator.state.spike_precision] 
     
    325327        self.synapse_model = synapse_dynamics._get_nest_synapse_model("projection_%d" % Projection.nProj) 
    326328        Projection.nProj += 1 
     329         
    327330        self.connection_manager = simulator.ConnectionManager(self.synapse_type, 
    328331                                                              self.synapse_model, 
  • trunk/src/nest/electrodes.py

    r957 r991  
    100100        """ 
    101101        self._device = nest.Create('step_current_generator') 
     102         
     103        self._set(times,amplitudes) 
     104 
     105 
     106    def _set(self, times, amplitudes): 
     107        """Set currents in existing current source. 
     108        Arguments: 
     109            times      -- list/array of times at which the injected current changes. 
     110            amplitudes -- list/array of current amplitudes to be injected at the 
     111                          times specified in `times`. 
     112                           
     113        The injected current will be zero up until the first time in `times`. The 
     114        current will continue at the final value in `amplitudes` until the end 
     115        of the simulation. 
     116        """ 
    102117        assert len(times) == len(amplitudes), "times and amplitudes must be the same size (len(times)=%d, len(amplitudes)=%d" % (len(times), len(amplitudes)) 
    103118        try: 
     
    109124        except AttributeError: 
    110125            numpy.append(amplitudes, amplitudes[-1]) 
    111         nest.SetStatus(self._device, {'amplitude_times': numpy.array(times, 'float'), 
    112                                       'amplitude_values': 1000.0*numpy.array(amplitudes, 'float')}) 
    113          
    114          
     126        nest.SetStatus(self._device, {'amplitude_times': list(numpy.array(times, 'float')), 
     127                                      'amplitude_values':list(1000.0*numpy.array(amplitudes, 'float'))}) 
     128 
    115129class NoisyCurrentSource(CurrentSource): 
    116130    """A Gaussian "white" noise current source. The current amplitude changes at fixed 
     
    146160                     specified, a NumpyRNG is used. 
    147161        """ 
     162        self._device = nest.Create('noise_generator') 
     163        self._set(mean, stdev, dt, start, stop, rng) 
     164 
     165    def _set(self, mean, stdev, dt=None, start=0.0, stop=None, rng=None): 
    148166        self.rng = rng or NumpyRNG() 
    149167        self.dt = dt or state.dt 
     
    155173        self.stdev = stdev 
    156174        if isinstance(rng, NativeRNG): 
    157             self._device = nest.Create('noise_generator') 
    158175            nest.SetStatus(self._device, {'mean': mean*1000.0, 
    159176                                           'std': stdev*1000.0, 
  • trunk/src/nest/recording.py

    r970 r991  
    271271        except ValueError: 
    272272            pass 
     273         
     274        if self._device != None: 
     275              recorders_to_reset=[] 
     276              for recorder in self.population.recorders.values(): 
     277                  if hasattr(recorder, "_device") and recorder._device == self._device: 
     278                     recorders_to_reset.append(recorder) 
     279              for recorder in recorders_to_reset: 
     280                  recorder._device = None  
    273281        self._create_device() 
    274282 
  • trunk/src/nest/simulator.py

    r957 r991  
    128128            gid = self 
    129129        try: 
     130            #nest does not like numpy array and so we will convert them to lists whenever we encounter one 
     131            for key in parameters: 
     132                if type(parameters[key]) == numpy.ndarray: 
     133                   parameters[key] = parameters[key].tolist() 
    130134            nest.SetStatus([gid], [parameters]) 
    131135        except: # I can't seem to catch the NESTError that is raised, hence this roundabout way of doing it.