Skip to content

Commit

Permalink
Merge pull request #513 from appukuttan-shailesh/fixes_482
Browse files Browse the repository at this point in the history
Fixes #482 - Handles timestamps of StepCurrentSource for NEST
  • Loading branch information
apdavison committed Sep 5, 2017
2 parents 1e279b9 + 75d3a6b commit 44d1500
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pyNN/nest/standardmodels/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,24 @@ def _phase_correction(self, start, freq, phase):
phase_fix = phase_fix.evaluate()[0]
nest.SetStatus(self._device, {'phase': phase_fix})

def _round_timestamp(self, value, resolution):
# subtraction by 1e-12 to match NEURON working
return round ((float(value)-1e-12)/ resolution) * resolution

def set_native_parameters(self, parameters):
parameters.evaluate(simplify=True)
for key, value in parameters.items():
if key == "amplitude_values":
assert isinstance(value, Sequence)
times = self._delay_correction(parameters["amplitude_times"].value)
numpy.append(times, 1e12)
amplitudes = value.value
numpy.append(amplitudes, amplitudes[-1])
if amplitudes[0] != 0:
times[0] = max(times[0], state.dt) # NEST ignores changes at time zero.
# must it be dt, or would any positive value work?
# this will fail if the second, third, etc. time points are also close to zero
ctr = next((i for i,v in enumerate(times) if v > state.dt), len(times)) - 1
if ctr >= 0:
times[ctr] = state.dt
times = times[ctr:]
amplitudes = amplitudes[ctr:]
for ind in range(len(times)):
times[ind] = self._round_timestamp(times[ind], state.dt)
nest.SetStatus(self._device, {key: amplitudes,
'amplitude_times': times})
elif key in ("start", "stop"):
Expand Down Expand Up @@ -149,3 +154,4 @@ class NoisyCurrentSource(NestCurrentSource, electrodes.NoisyCurrentSource):
('dt', 'dt')
)
nest_name = 'noise_generator'

0 comments on commit 44d1500

Please sign in to comment.