-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsts.py
140 lines (115 loc) · 3.22 KB
/
sts.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import threading
import time
import sys
import Queue
import navio.leds
import navio.util
import seabreeze
import numpy as np
seabreeze.use('pyseabreeze')
import seabreeze.spectrometers as sb
navio.util.check_apm()
led = navio.leds.Led()
#spec0.integration_time_micros(400000)
#spec1.integration_time_micros(1800000)
def optuSpec(spec,mini=0,maxi=2):
led.setColor('Red')
intens=0
inttime=mini*1e6-100000
if inttime<0:
inttime=0
while intens<14500 and inttime<maxi*1e6:
inttime+=100000
spec.integration_time_micros(inttime)
led.setColor('Blue')
intens=max(spec.intensities())
led.setColor('Red')
print "time: "+str(inttime/1e6)+" / intensity: "+str(intens)
led.setColor('Green')
# np.savetxt('STS'+spec.serial_number+'-inttime.log',[inttime],delimiter=',')
return inttime
def getBlack(spec):
#ress=[]
spec0=spec
nrmsmt=20
# spec0.integration_time_micros(float(np.genfromtxt('STS'+spec0.serial_number+'-inttime.log')))
out0=np.zeros((nrmsmt+1,1025))
out0[0,:-1]=spec0.wavelengths()
for i in np.arange(1,nrmsmt+1):
out0[i,:-1]=spec0.intensities()
out0[i,-1]=time.time()
print '#'+str(i)+' '
np.savetxt('STS'+spec.serial_number+'-dark.log',out0.T,delimiter=',')
def stswait(czas,kolor=['Red','Black']):
led.setColor('Black')
cnt=0
while cnt<czas:
led.setColor(kolor[cnt%2])
time.sleep(1)
cnt+=1
print czas-cnt
led.setColor('Black')
devices = sb.list_devices()
nospec=len(devices)
#Present number of Spectrometers with red blinks
print "Number of devices"+str(nospec)
#stswait(nospec*2+1,['Green','Red'])
#Wait 45 seconds for optimilisation of integration time
#print "Prepare for integration time measurement"
#stswait(15,['Green','Yellow'])
print "Integration time test"
if nospec>1:
global spec0
global spec1
spec0 = sb.Spectrometer(devices[0])
spec1 = sb.Spectrometer(devices[1])
#spec0IT=optuSpec(spec0,mini=0,maxi=2)
#spec3IT=optuSpec(spec1,mini=0,maxi=2)
#Wait 45 minutes for dark msmt
print "Prepare for black measurements"
#stswait(25,['Black','Yellow'])
print "Black measurements"
if nospec>1:
spec0.integration_time_micros(2e6)
spec1.integration_time_micros(8e5)
getBlack(spec0)
getBlack(spec1)
#Wait before flight
print "Prepare for flight"
#stswait(20,['Green','Blue'])
print "FLIGHT!"
def getSpec0():
#ress=[]
while True:
out0=np.zeros((101,1025))
out0[0,:-1]=spec0.wavelengths()
for i in np.arange(1,101):
out0[i,:-1]=spec0.intensities()
out0[i,-1]=time.time()
print '#'+str(i)+' '
np.savetxt('DATA/sts'+spec0.serial_number+'_'+time.strftime('%Y%m%d-%H%M%S')+'.dat',out0.T,delimiter=',')
#return ress
def getSpec1():
#ress=[]
while True:
out1=np.zeros((101,1025))
out1[0,:-1]=spec1.wavelengths()
for i in np.arange(1,101):
out1[i,:-1]=spec1.intensities()
out1[i,-1]=time.time()
print time.time()
np.savetxt('DATA/sts'+spec1.serial_number+'_'+time.strftime('%Y%m%d-%H%M%S')+'.dat',out1.T,delimiter=',')
global start_time
start_time=time.time()+5
def read0():
while time.time() <= start_time:
pass
threading.Thread(target=getSpec0).start()
def read1():
while time.time() <= start_time:
pass
threading.Thread(target=getSpec1).start()
threading.Thread(target=read0).start()
threading.Thread(target=read1).start()
#spec0.close()
#spec1.close()