-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmat2json.py
More file actions
37 lines (31 loc) · 828 Bytes
/
Copy pathmat2json.py
File metadata and controls
37 lines (31 loc) · 828 Bytes
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
import scipy.io
import numpy as np, h5py
from datetime import datetime
import glob, os
import json
def convert_to_time(hmm):
return datetime(year=int(hmm[0]),month=int(hmm[1]),day=int(hmm[2]), hour=int(hmm[3]),minute=int(hmm[4]),second=int(hmm[5]))
def loadMat(matfile):
data = scipy.io.loadmat(matfile)
filename = matfile.split(".")[0]
col = data[filename]
col = col[0][0][0][0]
size = col.shape[0]
da = []
for i in range(size):
k=list(col[i][3][0].dtype.fields.keys())
d1 = {}
d2 = {}
if str(col[i][0][0]) != 'impedance':
for j in range(len(k)):
t=col[i][3][0][0][j][0];
l=[]
for m in range(len(t)):
l.append(t[m])
d2[k[j]]=l
d1['cycle']=str(col[i][0][0])
d1['temp']=int(col[i][1][0])
d1['time']=str(convert_to_time(col[i][2][0]))
d1['data']=d2
da.append(d1)
return da