@@ -193,7 +193,8 @@ def extract_kinematic_synergies(
193193
194194def compute_umap (
195195 df ,
196- key ,
196+ keypoints = None ,
197+ pcutoff = 0.6 ,
197198 chunk_length = 30 ,
198199 fit_transform = True ,
199200 n_neighbors = 30 ,
@@ -234,7 +235,9 @@ def compute_umap(
234235 ----------
235236 df: original dataframe df, _, _ = dlc2kinematics.load_data(DLC_2D_file)
236237
237- key: list of limbs of interests ex: key = ['LeftForelimb', 'RightForelimb']
238+ keypoints: list of limbs of interests ex: key = ['LeftForelimb', 'RightForelimb'], if None, all bodyparts are taken into account
239+
240+ pcutoff: likelihood at which the keypoints are kept for analysis, if under pcutoff, set coord to 0
238241
239242 chunk_length: Number of frames per segment. #TODO: add the posibility of a sliding window?
240243
@@ -299,11 +302,17 @@ def compute_umap(
299302
300303 # pandas dataframe managing
301304 df_clean = df .copy ()
302- df_clean .columns = df_clean .columns .droplevel (
303- 0
304- ) # Drop scorer row to make it easier to navigate in the df table
305- key2 = ["x" , "y" ]
306- df_limbs = df_clean .loc [:, (key , key2 )] # Drop likelihood column
305+
306+ if keypoints is None : # If no keypoints specified, use all
307+ keypoints = df_clean .columns .get_level_values ('bodyparts' ).unique ().to_list ()
308+
309+ df_limbs = df_clean .loc [:, pd .IndexSlice [:, keypoints ]]
310+
311+ temp = df_limbs .stack (level = ['scorer' , 'bodyparts' ]) # Stack with likelihood, x, y
312+ temp .loc [temp ['likelihood' ] < pcutoff , ['x' ,'y' ]] = 0.0 # Set values under pcutoff to 0.0 to exclude
313+ unstacked_temp = temp .unstack (level = ['scorer' , 'bodyparts' ]) # Unstack again
314+ unstacked_temp .reorder_levels (['scorer' ,'bodyparts' ,'coords' ], axis = 1 ).reindex_like (df_limbs ) # Re-index like original df
315+
307316 n_frames , n_bodyparts = df_limbs .shape
308317 n_chunks = n_frames // chunk_length
309318
0 commit comments