-
Notifications
You must be signed in to change notification settings - Fork 0
/
DT_FeatureExtractionFromTDMS.py
88 lines (73 loc) · 2.49 KB
/
DT_FeatureExtractionFromTDMS.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
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
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 18 15:24:17 2017
@author: AICPS
"""
from nptdms import TdmsFile
import numpy as np
import pandas as pd
from glob import glob
import os
from pathlib import Path
originTDMSFolder = 'D:/GDrive/DT_Data/DAQ_Auto';
destinationCSVFolder = 'D:/GDrive/DT_Data/DAQ_Auto_TDMStoCSV';
tdmsFolderName = 'UM3_Corner_Wall_130p';
tdmsFolderNameFull=glob(originTDMSFolder+'/'+tdmsFolderName);
channelNames=['Mic_1',
'Mic_2',
'Mic_3',
'Mic_4',
'Current',
'Vib_x2',
'Vib_y2',
'Vib_z2',
'Vib_x1',
'Vib_y1',
'Vib_z1',
'Vib_x0',
'Vib_y0',
'Vib_z0',
'Temperature',
'Humidity',
'Mag_x0',
'Mag_y0',
'Mag_z0',
'Mag_x1',
'Mag_y1',
'Mag_z1',
'Mag_x2',
'Mag_y2',
'Mag_z2' ];
tdmsFiles=[]
#for f in listdir(tdmsFolderName[0]):
# if re.search('.tdms', f):
# tdmsFiles+= [f]
for file in os.listdir(tdmsFolderNameFull[0]):
if file.endswith(".tdms"):
tdmsFiles+= [file]
#%% Check if the destination foldername exists
destinationFolderName=destinationCSVFolder+'/'+tdmsFolderName;
if not os.path.exists(destinationFolderName):
os.makedirs(destinationFolderName)
#%%
directoryIndex=1;
for file in tdmsFiles:
tdms_file = TdmsFile(tdmsFolderNameFull[0]+'/'+file)
directory=destinationCSVFolder+'/'+tdmsFolderName+'/data_'+str(directoryIndex);
directoryIndex+=1;
if not os.path.exists(directory):
os.makedirs(directory)
for channelName in channelNames:
channel = tdms_file.object('data',channelName)
data=channel.data
startTime=channel.property('wf_start_time')
samplingIncrement=channel.property('wf_increment')
np.savetxt(directory+'/'+channelName+'.csv', data, delimiter=',')
np.savetxt(directory+'/timingMetaData.csv', [startTime.hour,startTime.minute,startTime.second,startTime.microsecond, samplingIncrement], delimiter=',')
print(file+' : '+channelName)
# channel = tdms_file.object('data','Mic_1')
# data=channel.data;
#
# np.savetxt('testdata.csv', data, delimiter=',')
#data = channel.data
#time = channel.time_track()