test2.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import os
  4. import importlib
  5. from helpers import data_management as dm
  6. from analytics import analytics1
  7. from analytics import fr_analytics as fran
  8. importlib.reload(fran)
  9. import aux
  10. from scipy import signal
  11. params = aux.load_config()
  12. data_tot, tt, triggers_tot, ch_rec_list, file_names = dm.get_raw(n_triggers=2, exploration=False)
  13. ch_id = 20
  14. data2 = data_tot[0, 0]
  15. ids = np.argwhere(data2.mean(axis=0) == 0)
  16. data3 = np.delete(data2, ids, axis=1)
  17. cc = np.corrcoef(data3.T)
  18. # y = signal.savgol_filter(data2[:, ch_id], 41, 2)
  19. # ch_ids = list(range(32)) + list(range(96, 128))
  20. # args = {'v_thr': 10, 'ymax': 7, 'arr_id': 1}
  21. # an.plot_pdf(f_id=0, arr_id=args['arr_id'])
  22. # an.plot_pdf(f_id=1, arr_id=args['arr_id'])
  23. for fid in range(len(file_names)):
  24. an = fran.fr_analytics(data_tot, params, file_names[fid])
  25. args = {'v_thr': 10, 'ymax': 7, 'arr_id': 1, 'save_fig': True}
  26. an.plot_spectra(f_id=fid, recompute=True, **args)
  27. args = {'v_thr': 10, 'ymax': 7, 'arr_id': 2}
  28. an.plot_spectra(f_id=0, recompute=True, **args)
  29. # an.plot_spectra(f_id=1, recompute=True, **args)
  30. xx
  31. # plt.tight_layout()
  32. tt2 = np.arange(data2.shape[0]) * 0.050
  33. # nperseg = 100
  34. # fmax = 5
  35. # ff, tt1, Sxx1 = signal.spectrogram(y, fs=20, axis=0, nperseg=nperseg, noverlap=int(nperseg * 0.9))
  36. # fidx = (ff >= 0) & (ff < fmax)
  37. plt.figure()
  38. plt.clf()
  39. plt.subplot(211)
  40. # plt.plot(tt2, data2[:, ch_id])
  41. plt.plot(tt2, y, 'C2')
  42. # plt.plot(data2[:, ch_id])
  43. plt.xlim(0, tt2.max())
  44. for tr_id in range(3, 4):
  45. plt.vlines(triggers_tot[0, 0][0][tr_id] * 0.05, 0, 50, color='r', alpha=0.8)
  46. plt.vlines(triggers_tot[0, 0][1][0] * 0.05, 0, 50, color='k', alpha=0.8)
  47. # # plt.vlines(triggers_tot[0, 0][0][3], 0, 50, color='r', alpha=0.8)
  48. # plt.subplot(212)
  49. # plt.pcolormesh(tt1, ff[fidx], Sxx1[fidx, :])
  50. # plt.vlines(triggers_tot[0, 0][0][3] * 0.05, 0, fmax, color='r', alpha=0.8)
  51. # plt.xlim(0, tt2.max())
  52. # # plt.clim(0, 1)
  53. plt.draw()
  54. plt.show()