-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameter.py
114 lines (80 loc) · 2.55 KB
/
parameter.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import time
start_time = time.time()
import opusFC
import os
import pandas as pd
import numpy
import csv
SNM = []
INS = []
DAT = []
TIM = []
EXP = []
DUR = []
CNM = []
RES = []
ZFF = []
NPT = []
LWN = []
LXV = []
FXV = []
minY = []
maxY = []
values = []
def file_list():
# Change current working directory to where OPUS files are stored in your computer
os.chdir('file path')
# Check currect working directory
cwd = os.getcwd()
file_list = os.listdir(os.curdir)
#print file_list
return file_list
#a=file_list()
#print(a)
counter=[]
f=[]
def parameters():
fl=file_list()
count = 0
for f in fl:
try:
dbs = opusFC.isOpusFile(f)
#control structure for the loop
if dbs==True:
conte=opusFC.listContents(f)
data=opusFC.getOpusData(f,conte[0])
count += 1
print(count)
#print conte, f
data=opusFC.getOpusData(f, conte[0])
print data.parameters, f
SNM.append(data.parameters['SNM'])
INS.append(data.parameters['INS'])
DAT.append(data.parameters['DAT'])
TIM.append(data.parameters['TIM'])
DUR.append(data.parameters['DUR'])
CNM.append(data.parameters['CNM'])
RES.append(data.parameters['RES'])
ZFF.append(data.parameters['ZFF'])
NPT.append(data.parameters['NPT'])
LWN.append(data.parameters['LWN'])
FXV.append(data.parameters['FXV'])
LXV.append(data.parameters['LXV'])
minY.append(data.minY)
maxY.append(data.maxY)
continue
else:
print('identified as non-Opus', f)
except ValueError:
print('Cant process a non-Opus file', f)
continue
b=parameters()
print(b)
# metadata
varnames = 'SNM', 'Instrument', 'Scan_date', "Time", "Duration", "Operator", "Resolution", "Zero_filling_Factor", "Number_points", "Laser_Wavenumber", "Wavenumber_one", "Wavenumber_last", "Min_absorbance", "Max_Absorbance"
metadata = numpy.vstack((SNM, INS, DAT, TIM, DUR, CNM, RES, ZFF, NPT, LWN, FXV, LXV, minY, maxY)).T
metadata = pd.DataFrame(metadata, columns=varnames)
print(metadata)
# write metadata to a csv file
metadata.to_csv('OPUS files metadata.csv')
print "time elapsed: {:.2f}s".format(time.time() - start_time)