scipy maxima detection is really slow so added some a c function