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.

merge_data.py~ 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Takes all processed_data .h5 session files and puts just the Rat data (position and orientation) into a single
  3. file, along with the metadata. Makes for easier analysis.
  4. """
  5. import os
  6. from glob import glob
  7. import pandas as pd
  8. import h5py
  9. loadpath = '/home/nickdg/theta_labshare/Projects/VRExperiments_Round2/Data/motion_tracking/processed'
  10. fnames = glob(loadpath + '/*/VRWall*.h5', recursive=True)
  11. def merge_dataframes(fnames):
  12. pos, ori = [], []
  13. for idx, fname in enumerate(fnames):
  14. try:
  15. for key, dfs in (('Position', pos), ('Orientation', ori)):
  16. df = pd.read_hdf(fname, '/preprocessed/Rigid Body/Rat/'+key).dropna()
  17. df['Session_id'] = idx
  18. dfs.append(df)
  19. except KeyError:
  20. print(f'Skipped {fname}')
  21. pos = pd.concat(pos)
  22. ori = pd.concat(ori)
  23. return pos, ori
  24. if __name__ == '__main__':
  25. names = ['RAT', 'PAPER_LOG_CODE', 'Capture Start Time', 'VR_WALL_X_OFFSET']
  26. sessions = []
  27. for idx, fname in enumerate(fnames):
  28. sess_dict = {}
  29. with h5py.File(fname, 'r') as f:
  30. try:
  31. for name in names:
  32. new_name = name.replace('_', ' ').title().replace(' ', '')
  33. sess_dict[new_name] = f.attrs[name]
  34. phase_frames = f['events/phaseStartFrameNum'][:]
  35. except KeyError:
  36. continue
  37. sess_dict['id'] = idx
  38. print(phase_frames)
  39. for phase, frame in enumerate(phase_frames):
  40. sess_dict[f'PhaseFrame{phase}'] = frame
  41. sessions.append(sess_dict)
  42. sessions = pd.DataFrame(sessions)
  43. save_fname = '../data/VRWall_AllData.h5'
  44. sessions.to_hdf(save_fname, '/Session')
  45. pos, ori = merge_dataframes(fnames)
  46. pos.to_hdf(save_fname, '/Position')
  47. ori.to_hdf(save_fname, '/Orientation')