# Path: apasvo/picking/findpeaks.py
# def find_peaks(x, threshold=None, order=1):


import numpy as np
from apasvo.picking import findpeaks
from numpy.lib import stride_tricks
from scipy import signal
    lta = min(len(x), lta_length * fs + 1)
    peak_window = int(peak_window * fs / 2.)
    x_norm = np.abs(x - np.mean(x))
    cf = np.zeros(len(x))

    if len(cf) > 0:
        if method == 'strides':
            sta_win = stride_tricks.as_strided(np.concatenate((x_norm, np.zeros(sta))),
                                               shape=(len(x), sta),
                                               strides=(1 * x_norm.dtype.itemsize, 1 * x_norm.dtype.itemsize))
            lta_win = stride_tricks.as_strided(np.concatenate((x_norm, np.zeros(lta))),
                                               shape=(len(x), lta),
                                               strides=(1 * x_norm.dtype.itemsize, 1 * x_norm.dtype.itemsize))
            sta_win_len = np.concatenate((np.ones(len(x) - sta) * sta,
                                          np.arange(sta, 0, -1)))
            lta_win_len = np.concatenate((np.ones(len(x) - lta) * lta,
                                          np.arange(lta, 0, -1)))
            cf = (sta_win.sum(axis=1) / sta_win_len) / (lta_win.sum(axis=1) / lta_win_len)
        elif method == 'convolution':
            sta_win = signal.fftconvolve(np.ones(sta), x_norm)[sta - 1:]
            lta_win = signal.fftconvolve(np.ones(lta), x_norm)[lta - 1:]
            sta_win_len = np.concatenate((np.ones(len(x) - sta) * sta,
                                          np.arange(sta, 0, -1)))
            lta_win_len = np.concatenate((np.ones(len(x) - lta) * lta,
                                          np.arange(lta, 0, -1)))
            cf = (sta_win / sta_win_len) / (lta_win / lta_win_len)
        elif method == 'iterative':
            for i in xrange(len(x)):
                cf[i] = np.mean(x_norm[i:i + sta]) / np.mean(x_norm[i:i + lta])


# Path: apasvo/picking/findpeaks.py
# def find_peaks(x, threshold=None, order=1):


# Path: apasvo/picking/stalta.py
import numpy as np
from apasvo.picking import findpeaks
from numpy.lib import stride_tricks
from scipy import signal

    lta = min(len(x), lta_length * fs + 1)
    peak_window = int(peak_window * fs / 2.)
    x_norm = np.abs(x - np.mean(x))
    cf = np.zeros(len(x))

    if len(cf) > 0:
        if method == 'strides':
            sta_win = stride_tricks.as_strided(np.concatenate((x_norm, np.zeros(sta))),
                                               shape=(len(x), sta),
                                               strides=(1 * x_norm.dtype.itemsize, 1 * x_norm.dtype.itemsize))
            lta_win = stride_tricks.as_strided(np.concatenate((x_norm, np.zeros(lta))),
                                               shape=(len(x), lta),
                                               strides=(1 * x_norm.dtype.itemsize, 1 * x_norm.dtype.itemsize))
            sta_win_len = np.concatenate((np.ones(len(x) - sta) * sta,
                                          np.arange(sta, 0, -1)))
            lta_win_len = np.concatenate((np.ones(len(x) - lta) * lta,
                                          np.arange(lta, 0, -1)))
            cf = (sta_win.sum(axis=1) / sta_win_len) / (lta_win.sum(axis=1) / lta_win_len)
        elif method == 'convolution':
            sta_win = signal.fftconvolve(np.ones(sta), x_norm)[sta - 1:]
            lta_win = signal.fftconvolve(np.ones(lta), x_norm)[lta - 1:]
            sta_win_len = np.concatenate((np.ones(len(x) - sta) * sta,
                                          np.arange(sta, 0, -1)))
            lta_win_len = np.concatenate((np.ones(len(x) - lta) * lta,
                                          np.arange(lta, 0, -1)))
            cf = (sta_win / sta_win_len) / (lta_win / lta_win_len)
        elif method == 'iterative':
            for i in xrange(len(x)):
                cf[i] = np.mean(x_norm[i:i + sta]) / np.mean(x_norm[i:i + lta])


    event_t = findpeaks.find_peaks(cf, threshold, order=peak_window * fs)