Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

createhandletrace.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os, sys
  2. import pandas as pd
  3. sys.path.append('.')
  4. import modules.coordsi as csi
  5. import math
  6. import time
  7. def main(input):
  8. if len(input) != 2:
  9. print('Usage: python3 ./scripts/createhandletrace.py <parent path of surgery ID> ')
  10. sys.exit(1)
  11. root = input[1]
  12. summary_1 = csi.summaryOriginCoord(root, camid=1)
  13. if not os.path.exists('./handletrace'):
  14. try:
  15. os.makedirs('./handletrace')
  16. except Exception as e:
  17. print(e)
  18. #make a loop for each index
  19. for index, row in summary_1.iterrows():
  20. timestamp = []
  21. start_time = time.time()
  22. df = csi.readCam(os.path.join(index,'cam1.csv'))
  23. df = csi.convertToSI(df, 3.5, 1.5, 3.4)
  24. df = csi.getVelocity(df)
  25. df = csi.getAcceleration(df)
  26. df = csi.getFullTrace(df,row['approx_total_frame'] )
  27. df = csi.addValidDetection(df, 25.0)
  28. try:
  29. df.to_csv(os.path.join('./handletrace/', index[17:]+'.csv'), index=False)
  30. #save spend time and index of summary_1 in timestamp list
  31. timestamp.append([index, time.time() - start_time])
  32. print([index, time.time() - start_time])
  33. except Exception as e:
  34. print(e)
  35. continue
  36. #save timestamp list to csv file
  37. pd.DataFrame(timestamp, columns=['index', 'time']).to_csv('./handletrace/timestamp.csv', index=False)
  38. if __name__ == '__main__':
  39. try:
  40. main(sys.argv)
  41. except Exception as e:
  42. print(e)
  43. sys.exit(1)