forked from Cryostat-GUI/Cryostat-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequence.py
More file actions
128 lines (96 loc) · 4.42 KB
/
Sequence.py
File metadata and controls
128 lines (96 loc) · 4.42 KB
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
"""Module containing the class and possible helperfunctions to run a measuring sequence
Author(s): bklebel (Benjamin Klebel)
"""
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
# import sys
# import datetime
# import pickle
# import os
# import re
import time
from util import AbstractEventhandlingThread
class BreakCondition(Exception):
"""docstring for BreakCondition"""
pass
class Sequence_Thread(AbstractEventhandlingThread):
"""docstring for Sequence_Thread"""
sig_aborted = pyqtSignal()
def __init__(self, mainthread, sequence):
super(Sequence_Thread, self).__init__()
self.__isRunning = True
self.sequence = sequence
self.mainthread = mainthread
self.dataLock = mainthread.dataLock
self.threshold_Temp = 0.1
self.threshold_Field = 0.1
self.temp_VTI_offset = 5
def running(self):
try:
self.mainthread.ITC_window.widgetSetpoints.setEnabled(False)
self.mainthread.ILM_window.widgetSetpoints.setEnabled(False)
self.mainthread.IPS_window.widgetSetpoints.setEnabled(False)
self.mainthread.LakeShore350_window.widgetSetpoints.setEnabled(False)
for entry in self.sequence:
if entry['typ'] == 'scan_T':
for temp_setpoint_sample in entry['sequence_temperature']:
temp_setpoint_VTI = temp_setpoint_sample - self.temp_VTI_offset
temp_setpoint_VTI = 4.3 if temp_setpoint_VTI < 4.3 else temp_setpoint_VTI
self.mainthread.threads['control_ITC'][0].gettoset_Temperature(temp_setpoint_VTI)
self.mainthread.threads['control_ITC'][0].setTemperature()
self.mainthread.threads['control_LakeShore350'][0].gettoset_Temp_K(temp_setpoint_sample)
self.mainthread.threads['control_LakeShore350'][0].setTemp_K()
self.check_Temp_in_Scan(temp_setpoint_sample)
# always use the sweep option, so the rate can be controlled!
# in case stabilisation is needed, just sweep to the respective point (let's try this...)
if entry['typ'] == 'Wait':
self.wait_for_Temp(entry['Temp'])
self.wait_for_Field(entry['Field'])
time.sleep(entry['Delay'])
except BreakCondition:
self.sig_aborted.emit()
return 'Aborted!'
finally:
self.mainthread.ITC_window.widgetSetpoints.setEnabled(True)
self.mainthread.ILM_window.widgetSetpoints.setEnabled(True)
self.mainthread.IPS_window.widgetSetpoints.setEnabled(True)
self.mainthread.LakeShore350_window.widgetSetpoints.setEnabled(True)
def check_Temp_in_Scan(self, Temp, direction=0):
pass
def wait_for_Temp(self, Temp_target, threshold=0.01):
"""repeatedly check whether the temperature was reached,
given the respective threshold, return once it has
produce a possibility to abort the sequence, through
repeated check for value, for breaking condition, and sleeping
"""
# check for break condition
if not self.__isRunning:
raise BreakCondition
with self.dataLock:
Temp_now = self.mainthread.data['LakeShore350']['Sensor_1_K']
while abs(Temp_now-Temp_target) > threshold:
with self.dataLock:
# check for value
Temp_now = self.mainthread.data['LakeShore350']['Sensor_1_K']
# sleep for short time OUTSIDE of Lock
time.sleep(0.1)
def wait_for_Field(self, Field):
"""repeatedly check whether the field was reached,
given the respective threshold, return once it has
produce a possibility to abort the sequence, through
repeated check for value, for breaking condition, and sleeping
"""
# check for break condition
if not self.__isRunning:
raise BreakCondition
with self.dataLock:
# check for value
pass
# sleep for short time OUTSIDE of Lock
time.sleep(0.1)
def stop(self):
"""stop the sequence execution by setting self.__isRunning to False"""
self.__isRunning = False
@pyqtSlot()
def setTempVTIOffset(self, offset):
self.temp_VTI_offset = offset