analyze_CY_2D.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. import easygui
  7. from master_funcs import *
  8. import dill
  9. import dataframe_image as dfi
  10. 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']
  11. for z in patients:
  12. print(z)
  13. pathway='/home/user/owncloud/3D_videos/CY_2D/'+z+'_P3_CY_camera-1DLC_resnet50_Cylinder_camera-1Jun15shuffle1_250000_filtered.csv'
  14. data=prep_dlc(pathway, 0.9, 1080)
  15. names=[i[0] for i in data.columns[::3]]
  16. for j in names:
  17. data[j, 'x']=data[j, 'x'].interpolate(method='polynomial', order=1)
  18. data[j, 'y']=data[j, 'y'].interpolate(method='polynomial', order=1)
  19. dill.load_session('/home/user/Documents/Master/CY_2D_'+z+'_data_save.pkl')
  20. touch_reset=0
  21. drag_reset=0
  22. touch=[]
  23. drag=[]
  24. length=[len(data), len(df_vel_acc1)]
  25. for i in range(0, np.min(length)):
  26. if data['snout', 'y'][i]>data['cylinder_top', 'y'][i]:
  27. #touch right
  28. if (touch_reset==0) and (df_vel_acc1['angle_shoulder_right_elbow_right_wrist_right'][i]>150):
  29. touch.append(i)
  30. touch_reset=1
  31. print('touch at ', i)
  32. #drag right
  33. if (drag_reset==0) and (df_vel_acc1['angle_acceleration_tailbase_shoulder_right_wrist_right'][i]>30):
  34. drag.append(i)
  35. drag_reset=1
  36. print('drag at ', i)
  37. if (touch_reset==1) and (data['snout', 'y'][i]<data['cylinder_top', 'y'][i]):
  38. touch_reset=0
  39. drag_reset=0
  40. if z=='PB_T2_3_1':
  41. touch_2d=pd.DataFrame([touch], index=[z])
  42. drag_2d=pd.DataFrame([drag], index=[z])
  43. else:
  44. touch_2d_temp=pd.DataFrame([touch], index=[z])
  45. touch_2d=touch_2d.append(touch_2d_temp)
  46. drag_2d_temp=pd.DataFrame([drag], index=[z])
  47. drag_2d=drag_2d.append(drag_2d_temp)
  48. touch_2d.columns=['Frame #']*touch_2d.shape[1]
  49. dfi.export(touch_2d, '/home/user/owncloud/thesis_figures/DLC_CY_touch_2d.png', max_cols=touch_2d.shape[1])
  50. drag_2d.columns=['Frame #']*drag_2d.shape[1]
  51. dfi.export(drag_2d, '/home/user/owncloud/thesis_figures/DLC_CY_drag_2d.png', max_cols=drag_2d.shape[1])
  52. 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']
  53. for z in patients:
  54. print(z)
  55. dill.load_session('/home/user/Documents/Master/CY_2D_'+z+'_data.pkl')
  56. pred_rfc_touch_2d = best_model_touch.predict(X_touch_test)
  57. det_touch_2d=np.where(pred_rfc_touch_2d)
  58. pred_rfc_drag_2d = best_model_drag.predict(X_drag_test)
  59. det_drag_2d=np.where(pred_rfc_drag_2d)
  60. if z=='PB_T2_3_1':
  61. touch_FI_2d=pd.DataFrame(det_touch_2d, index=[z])
  62. drag_FI_2d=pd.DataFrame(det_drag_2d, index=[z])
  63. else:
  64. touch_FI_temp_2d=pd.DataFrame(det_touch_2d, index=[z])
  65. touch_FI_2d=touch_FI_2d.append(touch_FI_temp_2d)
  66. drag_FI_temp_2d=pd.DataFrame(det_drag_2d, index=[z])
  67. drag_FI_2d=drag_FI_2d.append(drag_FI_temp_2d)