import matplotlib.pyplot as plt
import os
import numpy as np
import glob
import scipy.signal as sg


exp = 'Exp1'
folder = "/run/user/1003/gvfs/sftp:host=10.2.248.22,user=pierre.mahe/"+"/nfs/NAS3/SABIOD/SITE/ANTILLES_CCS_2021/"+exp+"/*/*"

files = np.array(sorted([f for f in glob.glob(folder+'/*') if f.lower().endswith('.wav')]))

histo = np.load(exp+'_hist.npy')
pred = np.load(exp+'_pred.npy')

pers = np.percentile(histo, 90, axis=1)

thd = 250
file_candidates = files[(pers)<thd] #files[(pers-sg.medfilt(pers, 3))<thd]

plt.figure()
plt.imshow(histo.T, aspect='auto', interpolation=None, cmap="jet")
plt.figure()
plt.plot(pers)
plt.figure()
#plt.plot((pers-sg.medfilt(pers, 3))<thd)
plt.plot((pers)<thd)
plt.show()
