import mne

from utils.file_utils import get_epochs


def check_peaks():
    """
    Sanity check for the "get_peaks" method
    """
    import matplotlib.pyplot as plt
    subject = '001'
    folder = "../Dataset/n170/sub-" + subject + "/ses-n170/eeg/"
    filepath = folder + "sub-" + subject + "_task-n170"
    raw = mne.io.read_raw_fif(filepath + "_cleaned.fif")
    epochs, _ = get_epochs(raw, [('face', 'intact')], picks='P7')
    ch, latency, peak = epochs.average().get_peak(tmin=0.13, tmax=0.2, mode='neg', return_amplitude=True)
    import numpy as np
    plt.plot(epochs.times, np.squeeze(epochs.average().data.T))
    plt.vlines([0.13, 0.2], -0.00001, 0.00001, colors='gray', linestyles='dotted')
    plt.vlines(latency, -0.00001, 0.00001, colors='r', linestyles='dotted')
    plt.show()


check_peaks()
