run_analysis_timeresolved.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import os
  2. import mr_epilepsy_timeresolved
  3. def run_2parts_regions():
  4. # -----------------------------------------------------------------------#
  5. # preictal data 4ms
  6. # -----------------------------------------------------------------------#
  7. data_path = '../Data/preictal/'
  8. result_path = '../Results/preictal/singleunits_regions/'
  9. # -----------------------------------------------------------------------#
  10. # create result directories
  11. # -----------------------------------------------------------------------#
  12. recordings = [dI for dI in os.listdir(data_path) if os.path.isdir(
  13. os.path.join(data_path, dI))]
  14. if not os.path.exists(result_path):
  15. os.makedirs(result_path)
  16. for rec in recordings:
  17. if not os.path.exists(result_path + rec):
  18. os.makedirs(result_path + rec)
  19. # -----------------------------------------------------------------------#
  20. # run mr analysis
  21. # -----------------------------------------------------------------------#
  22. outputfilename = 'pkl/activity_brainregions_SU_4ms.pkl'
  23. x = 2
  24. mr_epilepsy_timeresolved.mt_x_parts(x, outputfilename, data_path,
  25. result_path, recordings=recordings, binnings='all', ksteps=(1, 400),
  26. fit_method="offset")
  27. def run_2parts_hemispheres():
  28. # -----------------------------------------------------------------------#
  29. # preictal data 4ms
  30. # -----------------------------------------------------------------------#
  31. data_path = '../Data/preictal/'
  32. result_path = '../Results/preictal/singleunits/'
  33. # -----------------------------------------------------------------------#
  34. # create result directories
  35. # -----------------------------------------------------------------------#
  36. recordings = [dI for dI in os.listdir(data_path) if os.path.isdir(
  37. os.path.join(data_path, dI))]
  38. if not os.path.exists(result_path):
  39. os.makedirs(result_path)
  40. for rec in recordings:
  41. if not os.path.exists(result_path + rec):
  42. os.makedirs(result_path + rec)
  43. # -----------------------------------------------------------------------#
  44. # run timeresolved mr analysis
  45. # -----------------------------------------------------------------------#
  46. x = 2
  47. outputfilename = "pkl/activity_SU_4ms.pkl"
  48. mr_epilepsy_timeresolved.mt_x_parts(x, outputfilename, data_path,
  49. result_path, recordings=recordings, binnings=['left', 'right'],
  50. ksteps=(1, 400), fit_method="offset")
  51. def run_timeresolved_hemispheres():
  52. # -----------------------------------------------------------------------#
  53. # preictal data 4ms
  54. # -----------------------------------------------------------------------#
  55. data_path = '../Data/preictal/'
  56. result_path = '../Results/preictal/singleunits/'
  57. # -----------------------------------------------------------------------#
  58. # create result directories
  59. # -----------------------------------------------------------------------#
  60. recordings = [dI for dI in os.listdir(data_path) if os.path.isdir(
  61. os.path.join(data_path, dI))]
  62. if not os.path.exists(result_path):
  63. os.makedirs(result_path)
  64. for rec in recordings:
  65. if not os.path.exists(result_path + rec):
  66. os.makedirs(result_path + rec)
  67. # -----------------------------------------------------------------------#
  68. # run timeresolved mr analysis
  69. # -----------------------------------------------------------------------#
  70. ksteps = (1, 400)
  71. for binning in ['left', 'right']:
  72. for rec in recordings[60:]:
  73. windowsize = 20000
  74. windowstep = 500
  75. binning = binning
  76. fit_method = 'offset'
  77. dt = 4
  78. mt_file = '{}{}/mt_results_{}_{}_kmin{}_kmax{}_winsize{}_winstep{}_dt{}.pkl'.format(
  79. result_path, rec, binning, fit_method, ksteps[0], ksteps[1],
  80. windowsize, windowstep, dt)
  81. if not os.path.isfile(mt_file):
  82. mr_epilepsy_timeresolved.analyse_timeresolved_mr(data_path,
  83. result_path, recordings=[rec], binnings=[binning],
  84. ksteps=ksteps, windowsize=20000, windowstep=500,
  85. fit_method='offset')
  86. def main():
  87. run_2parts_hemispheres()
  88. run_2parts_regions()
  89. run_timeresolved_hemispheres() # warning: timeresolved analysis is computationally costly
  90. if __name__ == '__main__':
  91. main()