summaryrefslogtreecommitdiff
path: root/pyspike/PieceWiseConstFunc.py
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2015-05-17 17:50:39 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2015-05-17 17:50:39 +0200
commita61a14295e28e6e95fa510693a11ae8c78a552ab (patch)
tree9d0194163e2ce6727603fde241c03b470339dad1 /pyspike/PieceWiseConstFunc.py
parent8841138b74242ed9eb77c972c76e9a617778a79a (diff)
return correct values at exact spike times
pwc and pwl function object return the average of the left and right limit as function value at the exact spike times.
Diffstat (limited to 'pyspike/PieceWiseConstFunc.py')
-rw-r--r--pyspike/PieceWiseConstFunc.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/pyspike/PieceWiseConstFunc.py b/pyspike/PieceWiseConstFunc.py
index dea1a56..6d7a845 100644
--- a/pyspike/PieceWiseConstFunc.py
+++ b/pyspike/PieceWiseConstFunc.py
@@ -49,13 +49,16 @@ class PieceWiseConstFunc(object):
ind_l = np.searchsorted(self.x, t, side='left')
# if left and right side indices differ, the time t has to appear
# in self.x
- ind_at_spike = ind[np.logical_and(np.logical_and(ind != ind_l,
- ind > 1),
- ind < len(self.x))]
- value[ind_at_spike] = 0.5 * (self.y[ind_at_spike-1] +
- self.y[ind_at_spike-2])
+ ind_at_spike = np.logical_and(np.logical_and(ind != ind_l,
+ ind > 1),
+ ind < len(self.x))
+ # get the corresponding indices for the resulting value array
+ val_ind = np.arange(len(ind))[ind_at_spike]
+ # and for the arrays self.x, y1, y2
+ xy_ind = ind[ind_at_spike]
+ value[val_ind] = 0.5 * (self.y[xy_ind-1] + self.y[xy_ind-2])
return value
- else:
+ else: # t is a single value
# specific check for interval edges
if t == self.x[0]:
return self.y[0]