forked from ELGarulli/neurokin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLC_conversion.py
55 lines (47 loc) · 1.93 KB
/
DLC_conversion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import List
import pandas as pd
import numpy as np
"""
to do:
include axis_flag into df creation -> 3 or 1 column needed?
look for prettier solutions -> dlc2kin has a function for creating empty dfs
"""
class DLC_conversion():
def concat_dlc_df_to_df(df, dlc_df):
return pd.concat([df, dlc_df], axis=1)
def remove_scorer_index(df: pd.DataFrame)-> None:
sliced_df = df[df.keys()[0][0]]
return sliced_df
def add_scorer_index(df: pd.DataFrame, marker_id_filter: List[str], axis_flag: str)-> None:
expanded_df = create_empty_df(scorer = 'feature', bodyparts = marker_id_filter, frames_no = np.shape(df)[0])
count = 0
for bp in marker_id_filter:
for a in axis:
df['scorer', bp, a] = df[:, count]
count += 1
return expanded_df
def create_empty_df(scorer, bodyparts, frames_no, axis_flag: str):
"""
Creates empty dataframe to receive 3d data from c3d file
Parameters
----------
scorer: string
mock data scorer
bodyparts: list
bodyparts that will be in the dataframe
frames_no: int
number of frames of the recording
Outputs
-------
df: empty dataframe with shape compatible with dlc2kinematics
"""
df = None
a = np.full((frames_no, 3), np.nan)
for bodypart in bodyparts:
pdindex = pd.MultiIndex.from_product(
[[scorer], [bodypart], ["x", "y", "z"]],
names=["scorer", "bodyparts", "coords"],
)
frame = pd.DataFrame(a, columns=pdindex, index=range(0, frames_no))
df = pd.concat([frame, df], axis=1)
return df