def sanitize_spike_times(spike_times): """ PCSIM has a bug that the SpikingInputNeuron sometimes stops emitting spikes I think this happens when two spikes fall in the same time step. This workaround removes any spikes after the first within a given time step. """ time_step = common.get_time_step() try: spike_times = numpy.array(spike_times, float) except ValueError, e: raise errors.InvalidParameterValueError("Spike times must be floats. %s")
def _create_device(self): """Create a NEST recording device.""" device_name = RECORDING_DEVICE_NAMES[self.variable] self._device = nest.Create(device_name) device_parameters = {"withgid": True, "withtime": True} if self.variable != 'spikes': device_parameters["interval"] = common.get_time_step() if self.file is False: device_parameters.update(to_file=False, to_memory=True) else: # (includes self.file is None) device_parameters.update(to_file=True, to_memory=False) try: nest.SetStatus(self._device, device_parameters) except nest.hl_api.NESTError, e: raise nest.hl_api.NESTError("%s. Parameter dictionary was: %s" % (e, device_parameters))
def sanitize_spike_times(spike_times): """ PCSIM has a bug that the SpikingInputNeuron sometimes stops emitting spikes I think this happens when two spikes fall in the same time step. This workaround removes any spikes after the first within a given time step. """ time_step = common.get_time_step() try: spike_times = numpy.array(spike_times, float) except ValueError as e: raise errors.InvalidParameterValueError("Spike times must be floats. %s") bins = (spike_times/time_step).astype('int') mask = numpy.concatenate((numpy.array([True]), bins[1:] != bins[:-1])) if mask.sum() < len(bins): logger.warn("Spikes have been thrown away because they were too close together.") logger.debug(spike_times[(1-mask).astype('bool')]) if len(spike_times) > 0: return spike_times[mask] else: return spike_times
def __init__(self, device_type, to_memory=False): assert device_type in ("multimeter", "spike_detector") self.type = device_type self.device = nest.Create(device_type) device_parameters = {"withgid": True, "withtime": True} if self.type is 'multimeter': device_parameters["interval"] = common.get_time_step() else: device_parameters["precise_times"] = True device_parameters[ "precision"] = simulator.state.default_recording_precision if to_memory: device_parameters.update(to_file=False, to_memory=True) else: device_parameters.update(to_file=True, to_memory=False) try: nest.SetStatus(self.device, device_parameters) except nest.hl_api.NESTError, e: raise nest.hl_api.NESTError("%s. Parameter dictionary was: %s" % (e, device_parameters))
def sanitize_spike_times(spike_times): """ PCSIM has a bug that the SpikingInputNeuron sometimes stops emitting spikes I think this happens when two spikes fall in the same time step. This workaround removes any spikes after the first within a given time step. """ time_step = common.get_time_step() try: spike_times = numpy.array(spike_times, float) except ValueError as e: raise errors.InvalidParameterValueError( "Spike times must be floats. %s") bins = (spike_times / time_step).astype('int') mask = numpy.concatenate((numpy.array([True]), bins[1:] != bins[:-1])) if mask.sum() < len(bins): logger.warn( "Spikes have been thrown away because they were too close together." ) logger.debug(spike_times[(1 - mask).astype('bool')]) if len(spike_times) > 0: return spike_times[mask] else: return spike_times