analyse_CY_3D.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. from scipy import signal
  4. import numpy as np
  5. import math
  6. from mpl_toolkits import mplot3d
  7. import easygui
  8. from master_funcs import *
  9. import dill
  10. import dataframe_image as dfi
  11. %matplotlib qt
  12. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  13. for z in patients:
  14. Cyl_3D='/home/user/owncloud/3D_videos/CY_3D/'+z+'_P3_CY_DLC_3D.csv'
  15. data=pd.read_csv(Cyl_3D, delimiter=',', skiprows=0, index_col=0, header=[1,2])
  16. names=[i[0] for i in data.columns[::3]]
  17. zero='cylinder_left'
  18. x='cylinder_top'
  19. y='cylinder_bottom'
  20. data=transform(data, zero, x, y)
  21. vel, acc=vel_acc(data, '3D')
  22. df_vel=pd.DataFrame(vel, columns=names)
  23. df_acc=pd.DataFrame(acc, columns=names)
  24. touch_reset=0
  25. drag_reset=0
  26. print(z)
  27. touch=[]
  28. drag=[]
  29. for i in range(0, len(data-3)):
  30. if (distance_single(data, 'snout', 'hindpaw_right', i)>25) and (distance_single(data, 'snout', 'hindpaw_left', i)>25):
  31. #touch right
  32. if (touch_reset==0) and ((circle_dis(data, 'forepaw_right', i)>=0.90) or (circle_dis(data, 'forepaw_left', i)>=0.90)):
  33. touch.append(i)
  34. touch_reset=1
  35. print('touch at ', i)
  36. #drag right
  37. if (drag_reset==0) and ((df_acc['forepaw_right'][i]>=0.02) or (df_acc['forepaw_left'][i]>=0.02)):
  38. drag.append(i)
  39. drag_reset=1
  40. print('drag at ', i)
  41. if (touch_reset==1) and (distance_single(data, 'snout', 'hindpaw_right', i)<5):
  42. touch_reset=0
  43. drag_reset=0
  44. if z=='PB_T2_3_1':
  45. touch_3d=pd.DataFrame([touch], index=[z])
  46. drag_3d=pd.DataFrame([drag], index=[z])
  47. else:
  48. touch_3d_temp=pd.DataFrame([touch], index=[z])
  49. touch_3d=touch_3d.append(touch_3d_temp)
  50. drag_3d_temp=pd.DataFrame([drag], index=[z])
  51. drag_3d=drag_3d.append(drag_3d_temp)
  52. touch_3d.columns=['Frame #']*touch_3d.shape[1]
  53. dfi.export(touch_3d, '/home/user/owncloud/thesis_figures/DLC_CY_touch_3d.png')
  54. drag_3d.columns=['Frame #']*drag_3d.shape[1]
  55. dfi.export(drag_3d, '/home/user/owncloud/thesis_figures/DLC_CY_drag_3d.png')
  56. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  57. for z in patients:
  58. print(z)
  59. dill.load_session('/home/user/Documents/Master/CY_'+z+'_data.pkl')
  60. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  61. pred_rfc_touch = best_model_touch.predict(X_touch_test)
  62. det_touch_3d=np.where(pred_rfc_touch)
  63. pred_rfc_drag = best_model_drag.predict(X_drag_test)
  64. det_drag_3d=np.where(pred_rfc_drag)
  65. if z=='PB_T2_3_1':
  66. touch_FI_3d=pd.DataFrame(det_touch_3d, index=[z])
  67. drag_FI_3d=pd.DataFrame(det_drag_3d, index=[z])
  68. else:
  69. touch_FI_3d_temp=pd.DataFrame(det_touch_3d, index=[z])
  70. touch_FI_3d=touch_FI_3d.append(touch_FI_3d_temp)
  71. drag_FI_3d_temp=pd.DataFrame(det_drag_3d, index=[z])
  72. drag_FI_3d=drag_FI_3d.append(drag_FI_3d_temp)