@@ -882,28 +882,30 @@ def write_angle_as_list(img, ang, ang_name, person_label_position, ang_label_lin
882
882
883
883
def read_trc (trc_path ):
884
884
'''
885
- Read trc file
885
+ Read a TRC file and extract its contents.
886
886
887
887
INPUTS:
888
- - trc_path: path to the trc file
888
+ - trc_path (str): The path to the TRC file.
889
889
890
890
OUTPUTS:
891
- - Q_coords: dataframe of coordinates
892
- - frames_col: series of frames
893
- - time_col: series of time
894
- - markers: list of marker names
895
- - header: list of header lines
891
+ - tuple: A tuple containing the Q coordinates, frames column, time column, marker names, and header.
896
892
'''
897
-
898
- with open (trc_path , 'r' ) as trc_file :
899
- header = [next (trc_file ) for line in range (5 )]
900
- markers = header [3 ].split ('\t ' )[2 ::3 ]
901
-
902
- trc_df = pd .read_csv (trc_path , sep = "\t " , skiprows = 4 )
903
- frames_col , time_col = pd .Series (trc_df .iloc [:,0 ], name = 'frames' ), pd .Series (trc_df .iloc [:,1 ], name = 'time' )
904
- Q_coords = trc_df .drop (trc_df .columns [[0 , 1 ]], axis = 1 )
905
893
906
- return Q_coords , frames_col , time_col , markers , header
894
+ try :
895
+ with open (trc_path , 'r' ) as trc_file :
896
+ header = [next (trc_file ) for _ in range (5 )]
897
+ markers = header [3 ].split ('\t ' )[2 ::3 ]
898
+ markers = [m .strip () for m in markers if m .strip ()] # remove last \n character
899
+
900
+ trc_df = pd .read_csv (trc_path , sep = "\t " , skiprows = 4 , encoding = 'utf-8' )
901
+ frames_col , time_col = trc_df .iloc [:, 0 ], trc_df .iloc [:, 1 ]
902
+ Q_coords = trc_df .drop (trc_df .columns [[0 , 1 ]], axis = 1 )
903
+ Q_coords = Q_coords .loc [:, ~ Q_coords .columns .str .startswith ('Unnamed' )] # remove unnamed columns
904
+
905
+ return Q_coords , frames_col , time_col , markers , header
906
+
907
+ except Exception as e :
908
+ raise ValueError (f"Error reading TRC file at { trc_path } : { e } " )
907
909
908
910
909
911
def load_pose_file (Q_coords ):
0 commit comments