-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathofetMeasure.py
executable file
·209 lines (178 loc) · 8.14 KB
/
ofetMeasure.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
OFET measurement main program linking gui and measurement thread.
Author: Ross <peregrine dot warren at physics dot ox dot ac dot uk>
"""
import ofetMeasureGUI # GUI
import k2636 # driver
import sys
import time
import pandas as pd
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication
class GUI(ofetMeasureGUI.mainWindow):
"""GUI linked to measurement thread."""
def __init__(self):
"""Take GUI and add measurement thread connection."""
super().__init__()
self.params = {} # for storing parameters
self.setupConnections()
def setupConnections(self):
"""Connect the GUI to the measurement thread."""
self.buttonWidget.ivBtn.clicked.connect(self.ivSweep)
self.buttonWidget.outputBtn.clicked.connect(self.outputSweep)
self.buttonWidget.transferBtn.clicked.connect(self.transferSweep)
self.buttonWidget.allBtn.clicked.connect(self.allMeasurements)
self.buttonWidget.inverterBtn.clicked.connect(self.inverter)
def ivSweep(self):
"""Perform IV sweep."""
try:
if self.buttonWidget.SampleName is None:
raise AttributeError
self.params['Sample name'] = self.buttonWidget.SampleName
self.statusbar.showMessage('Performing IV Sweep...')
self.buttonWidget.hideButtons()
self.params['Measurement'] = 'iv-sweep'
self.measureThread = measureThread(self.params)
self.measureThread.finishedSig.connect(self.done)
self.measureThread.start()
except AttributeError or KeyError:
self.popupWarning.showWindow('No sample name given!')
def outputSweep(self, event):
"""Perform output sweep."""
try:
if self.buttonWidget.SampleName is None:
raise AttributeError
self.params['Sample name'] = self.buttonWidget.SampleName
self.statusbar.showMessage('Performing Output Sweep...')
self.buttonWidget.hideButtons()
self.params['Measurement'] = 'output'
self.measureThread = measureThread(self.params)
self.measureThread.finishedSig.connect(self.done)
self.measureThread.start()
except AttributeError:
self.popupWarning.showWindow('No sample name given!')
def transferSweep(self, event):
"""Perform transfer sweep."""
try:
if self.buttonWidget.SampleName is None:
raise AttributeError
self.params['Sample name'] = self.buttonWidget.SampleName
self.statusbar.showMessage('Performing Transfer Sweep...')
self.buttonWidget.hideButtons()
self.params['Measurement'] = 'transfer'
self.measureThread = measureThread(self.params)
self.measureThread.finishedSig.connect(self.done)
self.measureThread.errorSig.connect(self.error)
self.measureThread.start()
except AttributeError:
self.popupWarning.showWindow('No sample name given!')
def allMeasurements(self, event):
"""Perform all sweeps."""
try:
if self.buttonWidget.SampleName is None:
raise AttributeError
self.params['Sample name'] = self.buttonWidget.SampleName
self.statusbar.showMessage('Performing all...')
self.buttonWidget.hideButtons()
self.params['Measurement'] = 'all'
self.measureThread = measureThread(self.params)
self.measureThread.finishedSig.connect(self.done)
self.measureThread.errorSig.connect(self.error)
self.measureThread.start()
except AttributeError:
self.popupWarning.showWindow('No sample name given!')
def inverter(self, event):
"""Perform voltage inverter measurement."""
try:
if self.buttonWidget.SampleName is None:
raise AttributeError
self.params['Sample name'] = self.buttonWidget.SampleName
self.statusbar.showMessage('Performing inverter measurement...')
self.buttonWidget.hideButtons()
self.params['Measurement'] = 'inverter'
self.measureThread = measureThread(self.params)
self.measureThread.finishedSig.connect(self.done)
self.measureThread.errorSig.connect(self.error)
self.measureThread.start()
except AttributeError:
self.popupWarning.showWindow('No sample name given!')
def done(self):
"""Update display when finished measurement."""
self.statusbar.showMessage('Measurement(s) complete.')
self.dislpayMeasurement()
self.buttonWidget.showButtons()
def error(self, message):
"""Raise error warning."""
self.popupWarning.showWindow(str(message))
self.statusbar.showMessage('Measurement error!')
self.buttonWidget.hideButtons()
def dislpayMeasurement(self):
"""Display the data on screen."""
try:
# IV sweep display
if self.params['Measurement'] == 'iv-sweep':
df = pd.read_csv(str(self.params['Sample name'] + '-' +
self.params['Measurement'] + '.csv'), '\t')
self.mainWidget.drawIV(df)
# OUTPUT sweep display
elif self.params['Measurement'] == 'output':
df = pd.read_csv(str(self.params['Sample name'] + '-' +
self.params['Measurement'] + '.csv'), '\t')
self.mainWidget.drawOutput(df)
# TRANSFER sweep display
elif self.params['Measurement'] == 'transfer':
df = pd.read_csv(str(self.params['Sample name'] + '-neg-pos-' +
self.params['Measurement'] + '.csv'), '\t')
self.mainWidget.drawTransfer(df)
# ALL sweeps display
elif self.params['Measurement'] == 'all':
self.mainWidget.drawAll(str(self.params['Sample name']))
# INVERTER sweep display
elif self.params['Measurement'] == 'inverter':
df = pd.read_csv(str(self.params['Sample name'] + '-' +
self.params['Measurement'] + '.csv'), '\t')
self.mainWidget.drawInverter(df)
except FileNotFoundError:
self.popupWarning.showWindow('Could not find data!')
class measureThread(QThread):
"""Thread for running measurements."""
finishedSig = pyqtSignal()
errorSig = pyqtSignal(str)
def __init__(self, params):
"""Initialise threads."""
QThread.__init__(self)
self.params = params
def __del__(self):
"""When thread is deconstructed wait for porcesses to complete."""
self.wait()
def run(self):
"""Logic to be run in background thread."""
try:
keithley = k2636.K2636()
begin_measure = time.time()
if self.params['Measurement'] == 'iv-sweep':
keithley.IVsweep(self.params['Sample name'])
if self.params['Measurement'] == 'output':
keithley.Output(self.params['Sample name'])
if self.params['Measurement'] == 'transfer':
keithley.Transfer(self.params['Sample name'])
if self.params['Measurement'] == 'all':
keithley.IVsweep(self.params['Sample name'])
keithley.Output(self.params['Sample name'])
keithley.Transfer(self.params['Sample name'])
if self.params['Measurement'] == 'inverter':
keithley.Inverter(self.params['Sample name'])
keithley.closeConnection()
self.finishedSig.emit()
finish_measure = time.time()
print('-------------------------------------------\nAll measurements complete. Total time % .2f mins.'
% ((finish_measure - begin_measure) / 60))
except ConnectionError:
self.errorSig.emit('No measurement made. Please retry.')
self.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainGUI = GUI()
sys.exit(app.exec_())