Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

loading.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import sys, os
  2. sys.path.append(os.path.join(os.getcwd(), '..'))
  3. sys.path.append(os.path.join(os.getcwd(), '..', '..'))
  4. from imports import *
  5. from target import build_tgt_matrix
  6. def load_session_data(session):
  7. all_areas = ['A1', 'PPC', 'HPC']
  8. animal = session.split('_')[0]
  9. sessionpath = os.path.join(source, animal, session)
  10. aeps_file = os.path.join(sessionpath, 'AEPs.h5')
  11. h5_file = os.path.join(sessionpath, session + '.h5')
  12. report_path = os.path.join(report, 'PSTH', session)
  13. if not os.path.exists(report_path):
  14. os.makedirs(report_path)
  15. # load timeline and configuration
  16. with h5py.File(h5_file, 'r') as f:
  17. tl = np.array(f['processed']['timeline']) # time, X, Y, speed, etc.
  18. trials = np.array(f['processed']['trial_idxs']) # t_start_idx, t_end_idx, x_tgt, y_tgt, r_tgt, result
  19. cfg = json.loads(f['processed'].attrs['parameters'])
  20. # load AEPs
  21. aeps = {}
  22. with h5py.File(aeps_file, 'r') as f:
  23. for area in all_areas:
  24. if not area in f:
  25. continue
  26. aeps[area] = np.array(f[area]['aeps'])
  27. aeps_events = np.array(f['aeps_events'])
  28. areas = list(aeps.keys())
  29. # TODO find better way. Remove outliers
  30. if 'A1' in areas:
  31. aeps['A1'][aeps['A1'] > 5000] = 5000
  32. aeps['A1'][aeps['A1'] < -5000] = -5000
  33. if 'PPC' in areas:
  34. aeps['PPC'][aeps['PPC'] > 1500] = 1500
  35. aeps['PPC'][aeps['PPC'] < -1500] = -1500
  36. if 'HPC' in areas:
  37. aeps['HPC'][aeps['HPC'] > 1500] = 1500
  38. aeps['HPC'][aeps['HPC'] < -1500] = -1500
  39. aeps[areas[0]].shape
  40. # load LFP
  41. lfp = {}
  42. with h5py.File(aeps_file, 'r') as f:
  43. for area in areas:
  44. if 'LFP' in f[area]:
  45. lfp[area] = np.array(f[area]['LFP'])
  46. # load AEP metrics
  47. AEP_metrics_lims = dict([(area, {}) for area in areas])
  48. AEP_metrics_raw = dict([(area, {}) for area in areas])
  49. AEP_metrics_norm = dict([(area, {}) for area in areas])
  50. with h5py.File(aeps_file, 'r') as f:
  51. for area in areas:
  52. grp = f[area]
  53. for metric_name in grp['raw']:
  54. AEP_metrics_raw[area][metric_name] = np.array(grp['raw'][metric_name])
  55. AEP_metrics_norm[area][metric_name] = np.array(grp['norm'][metric_name])
  56. AEP_metrics_lims[area][metric_name] = [int(x) for x in grp['raw'][metric_name].attrs['limits'].split(',')]
  57. # build target matrix
  58. tgt_matrix = build_tgt_matrix(tl, trials, aeps_events)
  59. # get available units
  60. unit_names = []
  61. with h5py.File(h5_file, 'r') as f:
  62. unit_names = [x for x in f['units']]
  63. # read single units
  64. single_units = {}
  65. spike_times = {}
  66. with h5py.File(h5_file, 'r') as f:
  67. for unit_name in unit_names:
  68. spike_times[unit_name] = np.array(f['units'][unit_name][H5NAMES.spike_times['name']])
  69. single_units[unit_name] = np.array(f['units'][unit_name][H5NAMES.inst_rate['name']])
  70. #single_units[unit_name] = instantaneous_rate(unit_times, tl[:, 0], k_width=50)
  71. return {
  72. 'tl': tl,
  73. 'trials': trials,
  74. 'cfg': cfg,
  75. 'areas': areas,
  76. 'aeps': aeps,
  77. 'aeps_events': aeps_events,
  78. 'lfp': lfp,
  79. 'AEP_metrics_lims': AEP_metrics_lims,
  80. 'AEP_metrics_raw': AEP_metrics_raw,
  81. 'AEP_metrics_norm': AEP_metrics_norm,
  82. 'tgt_matrix': tgt_matrix,
  83. 'single_units': single_units,
  84. 'spike_times': spike_times,
  85. 'unit_names': unit_names,
  86. 'animal': animal,
  87. 'aeps_file': aeps_file,
  88. 'h5_file': h5_file,
  89. 'report_path': report_path
  90. }