-
Notifications
You must be signed in to change notification settings - Fork 4
/
mat2csv.py
50 lines (37 loc) · 952 Bytes
/
mat2csv.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
from __future__ import annotations
from pathlib import Path
import pandas as pd
import scipy.io as scio
mat_dir = Path("datasets")
csv_dir = Path("data/vulpi")
cols = {
"imu": [
"wx",
"wy",
"wz",
"ax",
"ay",
"az",
],
"pro": [
"velL",
"velR",
"curL",
"curR",
],
}
def mat_to_csv(fname: Path) -> Path:
terr = fname.parent.stem
datatype = fname.stem.split("_")[0]
data = scio.loadmat(fname, matlab_compatible=True)[datatype]
datacols = ["time", *cols[datatype]]
df = pd.DataFrame(data, columns=datacols)
csv_terr_dir = csv_dir / terr
csv_terr_dir.mkdir(exist_ok=True, parents=True)
export_path = (csv_terr_dir / fname.stem).with_suffix(".csv")
df.to_csv(export_path, index=False)
return export_path
if __name__ == "__main__":
files = [*mat_dir.rglob("*.mat")]
for f in files:
mat_to_csv(f)