-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (71 loc) · 2.53 KB
/
Copy pathmain.py
File metadata and controls
90 lines (71 loc) · 2.53 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: EmilianoRavera
@email: emiliano.ravera@uner.edu.ar
"""
# ----------- import packages --------------
from utilities.PublicFuntions import c3d2opensim
from ezc3d import c3d
import matplotlib.pyplot as plt
import pandas as pd
import csv
import gc
import os
import glob
import shutil
from pathlib import Path
# ------------------------------------------
class MOCAPData2OpenSim:
def __init__(self, root_path, path_MOCAP):
self.path_MOCAP = path_MOCAP # path of c3ds folder
self.dname = root_path # path of the main folder where the OpenSim model and the ExperimentalData folder will be created
def convert_c3d2opensim(self):
# create ExperimentalData folder if required
output_ExperimentalData = os.path.join(
self.dname, "ExperimentalData"
)
dst = Path(output_ExperimentalData)
dst.mkdir(parents=True, exist_ok=True)
walking_files = [
file
for file in self.path_MOCAP
if ("standing" not in Path(file).name.lower()
and "std" not in Path(file).name.lower())
]
standig_file = [
file
for file in self.path_MOCAP
if ("standing" in Path(file).name.lower()
or "std" in Path(file).name.lower())
]
# 1) convert c3d file to trc (OpenSim format)
if standig_file != []:
TrialType = "Static"
self.Static_TRCFileName = c3d2opensim(self.dname, standig_file[0], TrialType)
else:
print("Standing file not exist")
return
if walking_files != []:
self.Dynamic_TRCFileName = []
TrialType = "Dynamic"
for file in walking_files:
self.Dynamic_TRCFileName.append(c3d2opensim(self.dname, file, TrialType))
else:
print("Walking file not exist")
return
gc.collect() # Forzar limpieza de memoria
if __name__ == "__main__":
# -----------------------------------------------------------------------
# Set to Executables directory if running in Python directly
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
#
data_folder = os.path.join(dname, 'Data')
archivos_c3d = glob.glob(os.path.join(data_folder, '*.c3d'))
conversor = MOCAPData2OpenSim(
root_path=dname,
path_MOCAP=archivos_c3d,
)
# RUN convertion of MOCAP data to OpenSim data
conversor.convert_c3d2opensim()