Lessons learned

Spot the bug:

def compute_derivative(x, dt): 
  deriv_filter = numpy.array([-0.5, 0, 0.5]) / dt
  d = scipy.signal.convolve(x, deriv_filter, mode=1)
  d[0] = d[1]
  d[-1] = d[-2]
  return d

Hint: this snipped is correct:

def second_derivative(x, dt):
  return compute_derivative(compute_derivative(x, dt), dt)

Moral of the story: always, always, always write unit tests, otherwise you run the risk of spending nights trying to understand why certain flies go left when they are supposed to go right, and in the end, who knows, they might prefer to go left, this is not an exact science, maybe this is an important discovery, perhaps I need more coffee.