-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArbitrary_sweep.py
604 lines (462 loc) · 19.1 KB
/
Arbitrary_sweep.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# This script runs Hall and Temperature sweeps using a QD Dynacool
# PPMS cryostat and Keithley electronics. The Keithleys are controlled
# directly, while the cryostat is controlled through MultiVu via QD scripts
# in the PythonControl library, and my wrapper MultiVu_talk_ngc. This script
# allows an arbitrary number of sweeps to be run one after the other and
# and parameters for each sweep to be selected customly. This allows a high
# degree of automation when using custom pin configurations with the PPMS.
import numpy as np
import pandas as pd
import logging
#import matplotlib.pyplot as plt
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
import sys
import tempfile
import os
from time import sleep, time
from datetime import datetime
from pymeasure.log import console_log
from pymeasure.display.Qt import QtGui
#from PyQt5.QtWidgets import QApplication
from pymeasure.display.windows import ManagedWindow
from pymeasure.display import Plotter
from pymeasure.adapters import VISAAdapter
from pymeasure.experiment import Procedure, Results, Worker
from pymeasure.experiment import IntegerParameter, FloatParameter, BooleanParameter, Parameter
from pymeasure.experiment.results import unique_filename
import ngcmeas.current_voltage as cv
import ngcmeas.switch_matrix as sm
import MultiVu_talk_ngc as mv
from PythonControl.parse_inputs import inputs
# Specific host and port for UW-Madison PPMS
host = "128.104.184.130"
port = 5000
class TransportMeas(Procedure):
"""
This class allows either a Hall or Temp sweep to be performed, and it
integrates with the ManagedWindow gui. The startup and execute methods
are run by PyMeausre, and are what controls the exeperiment procedure.
"""
# Experiment parameters for the sweeps.
iterations = IntegerParameter('Measurement Number', default=1)
high_current = FloatParameter('Max Current', units='A', default=1.e-6)
delta = FloatParameter('Delta', units='s', default=1.e-3)
swpct1 = IntegerParameter('Sweep Count 1', default=10)
swpct2 = IntegerParameter('Sweep Count 2', default=1)
swpct3 = IntegerParameter('Sweep Count 3', default=10)
nplc = IntegerParameter('Num Power Line Cycles', default=3)
rvng = FloatParameter('Voltmeter Range', units='V', default=1.e1)
date = Parameter('Date Time', default='now')
meastype = Parameter('Measurement Type', default='Temp')
tempset = FloatParameter('Temperature Set Point', units='K', default=300.)
tempramp = FloatParameter('Temperature Ramp Rate', units='K/min', default=3.)
maxfield = FloatParameter('Maximum Field', units='Oe', default=0.)
fieldramp = FloatParameter('Magnetic Field Ramp Rate', units='Oe/sec', default=60.)
hysteresis = BooleanParameter('Do we expect a hysteresis in B', default = False)
pinconfig = Parameter('Pin Configuration', default='2vdP')
#DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
# 'R vdp 2', 'R Hall 1', 'R Hall 2'] # Had to have something
# here with no logic in order
# for MainWindow def__init__
# line to work
DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
'R vdp 2', 'R Hall 1', 'R Hall 2', 'R vdp 12', \
'R vdp 22', 'R Hall 12', 'R Hall 22']
#DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
# 'R bridge 2', 'R long 2', 'R hall 2']
#DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
# 'R vdp 2', 'R Hall 1', 'R Hall 2']
# Check if these work at all to change the Data Columns
#if self.pinconfig == '1vdP':
if pinconfig == '1vdP':
DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
'R vdp 2', 'R Hall 1', 'R Hall 2']
#if self.pinconfig == '2vdP':
if pinconfig == '2vdP':
DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
'R vdp 2', 'R Hall 1', 'R Hall 2', 'R vdp 12', \
'R vdp 22', 'R Hall 12', 'R Hall 22']
#if self.pinconfig == '2bridge':
if pinconfig == '2bridge':
DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R bridge 1', \
'R bridge 2']
def resistance_measure(self, config):
print('in resistance_measure', config)
if config == 'vdp1':
self.switch.clos_vdp1()
if config == 'vdp2':
self.switch.clos_vdp2()
if config == 'Hall1':
self.switch.clos_Hall1()
if config == 'Hall2':
self.switch.clos_Hall2()
if config == 'vdp12':
self.switch.clos_vdp12()
if config == 'vdp22':
self.switch.clos_vdp22()
if config == 'Hall12':
self.switch.clos_Hall12()
if config == 'Hall22':
self.switch.clos_Hall22()
if config == 'c1':
self.switch.clos_custom(2, 6, 4, 3)
if config == 'c2':
self.switch.clos_custom(2, 6, 1, 4)
if config == 'c3':
self.switch.clos_custom(2, 6, 5, 9)
if config == 'c4':
self.switch.clos_custom(2, 6, 9, 8)
sleep(0.36)
res = self.currentsource.min_inloop_delta()
self.switch.open_all()
print('Done and opened switches', res)#/self.high_current)
return res[0]/self.high_current
def startup(self):
"""
This method controls the device startup that occurs for every new sweep
the user runs. This method connects to the voltmeter and switch matrix
and initializes and arms the current source for specific measurement.
"""
print('Starting Up')
KE6221adapter = VISAAdapter("GPIB0::12")
KE7001adapter = VISAAdapter("GPIB0::7")
self.currentsource = cv.myKeithley6221(KE6221adapter)
self.switch = sm.Keithley7001(KE7001adapter, "SwitchMatrix")
print('instruments mapped')
self.currentsource.reset()
self.currentsource.arm_preloop_delta(self.high_current, self.delta,
self.swpct1, self.swpct2,
self.swpct3, self.nplc, self.rvng,
self.swpct1)
#self.currentsource.arm_preloop_delta(self.high_current, delta, swpct1, \
# swpct2, swpct3, npld, rvng, \
# swpct1)
print('Done Startup')
# Assign host and port as attributes of class
self.host = host
self.port = port
self.currentsource.write("FORM:ELEM DEF")
sleep(0.1)
def execute(self):
#self.maxb = 100000.
self.switch.set_pins(1,3,4,2) #1,3,4,2 Jieun wiring; 1243 Neil wiring
self.switch.set_pins2(5,9,8,6) #1,3,4,2 # 7 -> 9 b/c 7 is bad at SM
if self.pinconfig == '1vdP':
configs = ['vdp1', 'vdp2', 'Hall1', 'Hall2'] #added extra 2s for Zach L
if self.pinconfig == '2vdP':
configs = ['vdp1', 'vdp2', 'Hall1', 'Hall2', \
'vdp12', 'vdp22', 'Hall12', 'Hall22']
if self.pinconfig == '2bridge':
configs = ['c1', 'c2', 'c3', 'c4']
ress = []
ts = []
bs = []
self.starttime = time()
if self.meastype == 'Temp':
self.stable_relevant = r'"Stable"'
if self.meastype == 'Hall':
self.stable_relevant = r'"Holding (Driven)"'
#mv.set_field(host, port, self.maxb, 600)
#for i in range(self.iterations):
if self.meastype == 'Hall':
print('Selected Hall')
bfld = 0.
if self.hysteresis:
# Do an extra leg if we expect hysteresis
mv.set_field(self.host, self.port, -self.maxfield, 100)
sleep(1.8)
print('Hysteresis True so going to negative field.')
done = False
while not done: # wait until at max neg field
done = bfield[1] == self.stable_field
print("About to set field")
mv.set_field(self.host, self.port, self.maxfield, self.fieldramp)
sleep(1.8)
print("set field")
done = False
mv.set_field(self.host, self.port, self.maxfield, self.fieldramp)
sleep(1.8)
done = False
print('about to measure')
#while bfld < 0.999*self.maxb:
while not done: # Run the first leg of the Hall sweep
print('Doing done loop')
relevant = self.in_loop(configs)
print(relevant)
bfld = relevant[0]
done = relevant[1] == self.stable_relevant
print(relevant[1], done)
mv.set_field(host, port, -self.maxfield, self.fieldramp)
sleep(1.8)
done = False
while not done: # Run the middle leg of the Hall sweep
relevant = self.in_loop(configs)
print(relevant)
bfld = relevant[0]
done = relevant[1] == self.stable_relevant
print(relevant[1], done)
print('About to set field to zero.')
mv.set_field(host, port, 0.0, self.fieldramp)
sleep(1.8)
done = False
while not done: # Run the last leg of the Hall sweep
print('In last leg of sweep.')
relevant = self.in_loop(configs)
print(relevant)
bfld = relevant[0]
done = relevant[1] == self.stable_relevant
print(relevant[1], done)
print('Done Hall Sweep')
if self.meastype == 'Temp':
mv.set_temp(host, port, self.tempset, self.tempramp)
sleep(1.6)
bfld = 0.
done = False
print('about to measure')
#while bfld < 0.999*self.maxb:
inum = 0
new_time = time()
while not done:
relevant = self.in_loop(configs)
print(relevant)
bfld = relevant[0]
done = relevant[1] == self.stable_relevant
print(relevant[1], done)
# Force temp sweep for run for at least 300 seconds
#nn_time = time() - new_time
#if nn_time < 300:
# done = False
# Handle the PPMS not stabilizing at 2K
if self.tempset < 2.3:
if relevant[0] < 2.3:
if inum > 10:
done = True
inum += 1
print('Done Temp Sweep')
def resistance_measure(self, config):
"""
This function runs the individual resitance measurements, from setting
the switch matrix pins, to actually collecting the voltage. Custom
pin configurations for non-vdP situations are also set here.
"""
print('in resistance_measure', config)
if config == 'vdp1':
self.switch.clos_vdp1()
if config == 'vdp2':
self.switch.clos_vdp2()
if config == 'Hall1':
self.switch.clos_Hall1()
if config == 'Hall2':
self.switch.clos_Hall2()
if config == 'vdp12':
self.switch.clos_vdp12()
if config == 'vdp22':
self.switch.clos_vdp22()
if config == 'Hall12':
self.switch.clos_Hall12()
if config == 'Hall22':
self.switch.clos_Hall22()
# These are for bridges or other configurations that do not use van
# der Pauw configurations.
if config == 'cust1':
self.switch.clos_custom(1, 2, 3, 9) #5, 1, 6, 2
if config == 'cust2':
self.switch.clos_custom(1, 2, 3, 5)
if config == 'cust3':
self.switch.clos_custom(1, 2, 8, 4) #5, 1, 6, 2
if config == 'cust4':
self.switch.clos_custom(1, 2, 8, 6)
sleep(0.36)
# Below is where the voltage is actually measured
volt = self.currentsource.min_inloop_delta()
self.switch.open_all()
print('Done and opened switches', volt)#/self.high_current)
return volt[0]/self.high_current
def in_loop(self, configs):
ress = []
# get_temp and get_field from Dynacool
temp = mv.query_temp(host, port)
bfield = mv.query_field(host, port)
print(bfield)
tim = time() - self.starttime
#print('Temp ', temp, 'Field ', bfield)
# This is where comment starts for bridges
print('Active configs are', configs)
for c in configs:
ress.append(self.resistance_measure(c))
print(ress[-1])
print('about to emit', tim)
if self.pinconfig == '1vdP':
#print('In correct emitting block.', temp[0], bfield[0], ress)
self.emit('results', {
'Time': tim, \
'Temperature': temp[0], \
'\g(m)\-(0)H': bfield[0], \
'R vdp 1': ress[0], \
'R vdp 2': ress[1], \
'R Hall 1': ress[2], \
'R Hall 2': ress[3], \
})
print('Emit successful')
if self.pinconfig == '2vdP':
#DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R vdp 1', \
# 'R vdp 2', 'R Hall 1', 'R Hall 2', 'R vdp 12', \
# 'R vdp 22', 'R Hall 12', 'R Hall 22']
self.emit('results', {
'Time': tim, \
'Temperature': temp[0], \
'\g(m)\-(0)H': bfield[0], \
'R vdp 1': ress[0], \
'R vdp 2': ress[1], \
'R Hall 1': ress[2], \
'R Hall 2': ress[3], \
'R vdp 12': ress[4], \
'R vdp 22': ress[5], \
'R Hall 12': ress[6], \
'R Hall 22': ress[7], \
})
if self.pinconfig == '2bridge':
DATA_COLUMNS = ['Time', 'Temperature', '\g(m)\-(0)H', 'R bridge 1', \
'R bridge 2']
self.emit('results', {
'Time': tim, \
'Temperature': temp[0], \
'\g(m)\-(0)H': bfield[0], \
'R vdp 1': ress[0], \
'R bridge 2': ress[1], \
'R long 2': ress[2], \
'R hall 2': ress[3], \
})
sleep(0.01)
'''
for c in configs:
ress.append(self.resistance_measure(c))
print(ress[-1])
print('about to emit', tim)
self.emit('results', {
'Time': tim, \
'Temperature': temp, \
'\g(m)\-(0)H': bfield[0], \
'R bridge 1': ress[0], \
'R bridge 2': ress[1], \
#'R Hall 1': ress[2], \
#'R Hall 2': ress[3], \
})
sleep(0.01)
'''
if self.meastype == 'Temp':
relevant = temp
if self.meastype == 'Hall':
relevant = bfield
print('done emitting')
return relevant
class MainWindow(ManagedWindow):
def __init__(self):
#super(MainWindow, self).__init__(
super().__init__(
procedure_class = TransportMeas,
inputs=['iterations', 'high_current', 'delta', 'swpct1', 'swpct2',\
'swpct3', 'nplc', 'rvng', 'date', 'meastype', 'tempset',\
'tempramp', 'maxfield', 'fieldramp', 'hysteresis', 'pinconfig'],
displays=['iterations', 'high_current', 'delta', 'swpct1', 'swpct2',\
'swpct3', 'nplc', 'rvng', 'date', 'meastype', 'tempset',\
'tempramp', 'maxfield', 'fieldramp', 'hysteresis', 'pinconfig'],
x_axis='Time',
y_axis='R vdp 1',
directory_input=True,
sequencer=True,
sequencer_inputs=['iterations', 'high_current', 'delta', 'swpct1', 'swpct2',\
'swpct3', 'nplc', 'rvng', 'date', 'meastype', 'tempset',\
'tempramp', 'maxfield', 'fieldramp', 'hysteresis', 'pinconfig'],
inputs_in_scrollarea = True)#,
#sequence_file="gui_sequencer_example_sequence.txt"
#)
self.setWindowTitle('Arbitrary Sweep')
def queue(self, procedure=None):
directory = self.directory
print(self.directory)
print('mydir', directory)
#self.directory = r'C:\\Users\\Neil\\Documents'
#print(self.inputs, 'meastype')
mtype = getattr(self.inputs, 'meastype').parameter.value
print('About to do meastype: ', mtype)
prefix = 'rho_'# + mtype + '_'
filename = unique_filename(directory, prefix=prefix)
#procedure = self.make_procedure()
if procedure is None:
procedure = self.make_procedure()
elif not procedure:
print('making procedure my way')
procedure = self.make_procedure()
#procedure = self.make_procedure()
results = Results(procedure, filename)
experiment = self.new_experiment(results)
self.manager.queue(experiment)
def field_ramp(host, port, maxb):
flds = []
mv.set_field(host, port, maxb, 600.)
sleep(0.48)
fld = 0.
while fld < 0.99999*maxb:
fld = mv.query_field(host, port)
print(fld)
flds.append(fld)
sleep(1.0)
mv.set_field(host, port, -1*maxb, 600.)
sleep(0.48)
while fld > -0.99999*maxb:
fld = mv.query_field(host, port)
print(fld)
flds.append(fld)
sleep(1.0)
mv.set_field(host, port, 0., 600.)
sleep(0.48)
while fld < -0.10:
fld = mv.query_field(host, port)
print(fld)
flds.append(fld)
sleep(1.0)
return flds
def main():
host = "128.104.184.130"
port = 5000
#print('about to set field')
#flds = field_ramp(host, port, 2000.)
#print('field set')
#plt.plot(flds)
#plt.show()
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
directory = r'C:\Users\maglab\Documents\Python Scripts\qdppms\NSTO'
os.chdir(directory)
data_filename = 'rho_v_B_350K_5T_NS035g_1.csv'
procedure = HallSweep(50000)
procedure.iterations = 1
procedure.high_current = 80.e-6
procedure.delta = 1.e-3
procedure.swpct1 = 10
procedure.swpct2 = 1
procedure.swpct2 = 1
procedure.sswpct3 = 10
procedure.nplc = 3
procedure.rvng = 1.e1
now = datetime.now()
#procedure.date = now.strftime("%m/%d/%Y, %H:%M:%s")
#print('Params: ', procedure.parameter_objects())
#procedure.startup()
#procedure.execute()
#hs = HallSweep(host, port)
#hs.startup()
#print('Hall sweep started up')
'''
results = Results(procedure, data_filename)
worker = Worker(results)
print('Starting worker to run Hall Sweep')
worker.start()
worker.join(timeout=120) # wait at most 2 min
'''
if __name__ == '__main__':
main()