-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkerClass.py
114 lines (90 loc) · 4.35 KB
/
WorkerClass.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
# Copyright George Nelson 2020
# Worker thread
import time
import math
import numpy
from PyQt5.QtCore import pyqtSignal,pyqtSlot
from LogClass import LogObject
from LakeshoreClass import Lakeshore
from MFIAClass import MFIA
from FileClass import FileSave
class AcquireData(LogObject):
init_fail = pyqtSignal() # Cannot put signals in constructor(?)
graph_update = pyqtSignal()
def __init__(self):
super(AcquireData, self).__init__()
## LOCAL VARS
#self.device_id = []
self.cap_data = numpy.array([])
self.avg_trnst = []
## CREATE PARAM STRUCTS
self.sample = []
self.dlts = []
self.temp = []
self.lake = []
self.mfia = []
## CREATE HARDWARE INSTANCES
self.lakeshore = Lakeshore()
self.device = MFIA()
## CREATE FILE SAVE SUBWORKER
self.file = FileSave()
def reset(self,sampleParam,dltsParam,tempParam,lakeshoreParam,mfiaParam):
## SYNC PARAM STRUCTS FROM UI
self.sample = sampleParam
self.dlts = dltsParam
self.temp = tempParam
self.lake = lakeshoreParam
self.mfia = mfiaParam
self.cap_data = numpy.array([])
## CREATE FILE SAVE SUBWORKER
del self.file
self.file = FileSave()
#self.graph_update.emit()
## INITIALIZE HARDWARE
if self.lakeshore.reset(self.lake) == False: # Now initialize Lakeshore
self.init_fail.emit()
return
self.device.reset(self.dlts,self.mfia) # Now initialize MFIA
@pyqtSlot()
def stop_signal(self):
self.lakeshore.stopped = True
@pyqtSlot()
def do_scan(self):
self.cap_data = numpy.array([])
current_temp = self.temp.temp_init;
current_num = 0;
steps = math.ceil(abs(self.temp.temp_init - self.temp.temp_final)/self.temp.temp_step)
while current_num <= steps and not self.lakeshore.stopped:
self.generate_log("Waiting for set point {}... ".format(current_temp),"blue")
time.sleep(1)
self.lakeshore.SET_TEMP(current_temp,self.temp.temp_stability,self.temp.time_stability) #Wait for lakeshore to reach set temp
if not self.lakeshore.stopped:
# Capture transient data from MFIA
self.generate_log("Capturing transient...","blue")
temp_before = self.lakeshore.sampleSpaceTemperature()
#[timestamp, sampleCap] = MFIA_CAPACITANCE_POLL(device,mfia); #TODO implement constant polling?
self.cap_data = self.device.MFIA_CAPACITANCE_DAQ(self.dlts)
temp_after = self.lakeshore.sampleSpaceTemperature()
avg_temp = (temp_before + temp_after) / 2
self.generate_log("Finished transient for this temperature.","green")
# Find the amount of data loss, if more than a few percent lower duty cycle or lower sampling rate
dataloss = numpy.sum(numpy.isnan(self.cap_data))/numpy.size(self.cap_data)
if dataloss:
#cprintf('systemcommands', 'Warning: %1.1f%% data loss detected.\n',100*dataloss);
self.generate_log("Warning: {:1.1f}% data loss detected.".format(dataloss*100),"orange")
#avg_trnst = MFIA_TRANSIENT_AVERAGER_POLL(sampleCap,mfia); #Not implemented in python yet
self.file.transient = self.device.MFIA_TRANSIENT_AVERAGER_DAQ(self.cap_data)
self.graph_update.emit()
self.generate_log("Saving transient...","blue")
self.file.TRANSIENT_FILE(self.sample,self.dlts,self.mfia,current_num,current_temp,avg_temp)
if self.temp.temp_init > self.temp.temp_final:
current_temp = current_temp - self.temp.temp_step # Changes +/- for up vs down scan
elif self.temp.temp_init < self.temp.temp_final:
current_temp = current_temp + self.temp.temp_step
current_num = current_num + 1
if not self.lakeshore.stopped:
self.generate_log("Finished data collection, returning to idle temp.","blue")
self.lakeshore.SET_TEMP(self.temp.temp_idle,self.temp.temp_stability,self.temp.time_stability) # Wait for lakeshore to reach set temp
elif self.lakeshore.stopped:
self.generate_log("Stop successful.","orange")
self.finished.emit()