-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetData.py
274 lines (172 loc) · 9.06 KB
/
GetData.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
#Author - Andrew Guthrie
import numpy as np
import scipy as sc
import visa
import pyvisa.highlevel
import time
from NetworkAnalyzer import NetworkAnalyzer
from Agilent34401A import Agilent34401A
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from sys import argv
import os
import pyqtgraph.exporters
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
def MeasurementsSettings():
Measurements = {'MeasurementsDevice': '$15\,\mathrm{\mu m}$ sample (Contacts 1-2)',
'MeasurementsType': 'Pumping 1K pot. Excite 25mkm beam looking for 15mkm beam',
'LineAttenuation': -40}
Frequency = {'CenterStart': 947.5e6,
'CenterStop': 1e9,
'CenterPoints': 1001,
'CenterSpan': 50e6,
'Points': 1001}
FrequencyArray = np.linspace(Frequency['CenterStart'],Frequency['CenterStop'],Frequency['CenterPoints'])
Power = {'Start': 0,
'Stop': 0,
'Points':1}
PowerArray = np.linspace(Power['Start'],Power['Stop'],Power['Points'])
Averages = {'Points':1,
'IFBW': 100}
Field = {'Start': 5 ,
'Stop': 5,
'Points': 1,
'SweepRate': 0.5}
FieldArray = np.linspace(Field['Start'],Field['Stop'],Field['Points'])
Temperature = {'Start': 1 ,
'Stop': 1,
'Points': 1}
TemperatureArray = np.linspace(Temperature['Start'], Temperature['Stop'], Temperature['Points'])
File = {'Data':'C:/Users/guthrie/PycharmProjects/GetData/.idea/Data/' + str(time.strftime("%Y-%m-%d-%H-%M-%S")),
'Log':'C:/Users/guthrie/PycharmProjects/GetData/.idea/Labbook/Labbook.Tex',
'Plots': 'C:/Users/guthrie/PycharmProjects/GetData/.idea/Plots/Plot1' + str(time.strftime("%Y-%m-%d-%H-%M-%S"))}
NetworkAnalyzer = {'Frequency': Frequency,
'FrequencyArray': FrequencyArray,
'Power': Power,
'PowerArray': PowerArray,
'Averages': Averages}
Settings = {'NetworkAnalyzer': NetworkAnalyzer,
'Field': Field,
'FieldArray': FieldArray,
'Temperature':Temperature,
'TemperatureArray':TemperatureArray,
'Measurements': Measurements,
'File': File}
return Settings
def Plot(Settings,sReal,sImag,frequency):
#Caluclate magnitude and phase from real and imaginary parts of Signal
phase = []
magnitude = []
for x in range(0, len(sReal)):
if (sReal != 0):
phase.append(np.arctan(sImag[x] / sReal[x]))
magnitude.append(np.sqrt(np.power(sImag[x], 2) + np.power(sReal[x], 2)))
else: phase.append(0)
#Create Window
win = pg.GraphicsWindow(title="")
win.resize(600, 900)
win.setBackground((255,255,255))
win.setWindowTitle('Frequency Sweep')
#Add Frequency vs Magnitude plot
p1 = win.addPlot(title="Magnitude")
p1.setLabel('left', "|S21|", units='')
p1.setLabel('bottom', "Frequency", units='')
p1.plot(frequency, magnitude,pen= pg.mkPen('r', width=2))
win.nextRow()
#Add Frequency vs Phase plot
p2 = win.addPlot(title="Phase")
p2.plot(frequency, phase, pen= pg.mkPen('b', width=2))
p2.setLabel('left', "Phase", units='')
p2.setLabel('bottom', "Frequency", units='')
#Used in pyqtgraph to display interactive graph
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
exporter = pg.exporters.ImageExporter(p1)
exporter.parameters()['width'] = 1000
exporter.parameters()['height'] = 1000
exporter.export(str(Settings['File']['Plots'] + 'Mag.png'))
exporter = pg.exporters.ImageExporter(p2)
exporter.parameters()['width'] = 1000
exporter.parameters()['height'] = 1000
exporter.export(str(Settings['File']['Plots'] + 'Phase.png'))
#Creates data file with all frequency and amplitude data
data = open(Settings['File']['Data'] + '.txt', 'w')
data.write("Frequency(Hz)" + '\t' + 'In-Phase Amplitude' + '\t' + 'Out-of-Phase Amplitude' + '\t' + 'Magnitude' + '\t' + 'Phase' '\n')
for x in range(0,len(sReal)):
data.write(str(frequency[x]) + '\t' + str(sReal[x]) + '\t' + str(sImag[x]) + '\t' + str(magnitude[x]) + '\t' + str(phase[x]) + '\n')
data.close()
return
def Labbook(Settings):
book = open(Settings['File']['Log'], 'r+')
book.seek(0, os.SEEK_END)
book.seek(book.tell() - 16, os.SEEK_SET)
book.truncate()
book.close()
book = open(Settings['File']['Log'],'a')
Tex = [r'',
r' \section{' + time.strftime("%c")+'}',
r' \begin{tabular}{|p{0.6 \textwidth}|p{0.35\textwidth}|}',
r' \hline',
r' \begin{flushleft}',
r' \textbf{\underline{' +Settings['Measurements']['MeasurementsType']+'}}',
r' \end{flushleft}',
r' \includegraphics[width=\linewidth]{' + str(Settings['File']['Plots'] + 'Mag.png') + '}',
r' \includegraphics[width=\linewidth]{' + str(Settings['File']['Plots'] + 'Phase.png') + '}',
r' \newline \textbf{Program:} GetData.m',
r' \newline \textbf{Data file name:}',
r' \newline ' + str(Settings['File']['Data']) + '.txt',
r' \newline \textbf{Figure file name:}',
r' \newline ' + str(Settings['File']['Plots']) + '.png',
' & ',
r' \begin{flushright}',
r' \textbf{\underline{' + str(Settings['Measurements']['MeasurementsDevice']) +'}}',
' \end{flushright}',
' Line attenuation: ' + str(Settings['Measurements']['LineAttenuation']) + 'dB',
r' \newline \textbf{Instruments:}',
r' \newline Magnetic field is controlled by Oxford PS120;',
r' \newline Temperature is controlled by Lakeshore;',
r' \newline Pressure is obtained by Agilent34401A voltmeter;',
r' \newline Data are obtained by AgilentE5071C Network Analyzer;',
r' \vspace{1cm}',
r' \newline\textbf{Temperature settings:}',
r' \newline $T_{start} = ' + str(Settings['Temperature']['Start']) + '\,\mathrm{K}$',
r' \newline $T_{stop} = '+ str(Settings['Temperature']['Stop'])+ '\,\mathrm{K}$',
r' \newline $N_{T} = '+ str(Settings['Temperature']['Points'])+ '$',
r' \newline\textbf{Initial actual temperature measured by $\mathrm{RuO_x}$ thermometer:}',
r' \newline $T_{RuOx} = '+ 'str(Data.Temperature.RuOx(1))'+ '\,\mathrm{K}$',
r' \newline\textbf{Initial actual temperature measured by $\mathrm{^4He}$ thermometer:}',
r' \newline $T_{He} = '+ 'str(Data.Temperature.He4(1))'+ '\,\mathrm{K}$',
r' \newline\textbf{Magnet settings:}',
r' \newline $B_{start} = '+ str(Settings['Field']['Start'])+ '\,\mathrm{T}$',
r' \newline $B_{stop} = '+ str(Settings['Field']['Stop'])+ '\,\mathrm{T}$',
r' \newline Sweeping rate: $'+ str(Settings['Field']['SweepRate'])+ '\,\mathrm{T/min}$',
r' \newline $N = '+ str(Settings['Field']['Points'])+ '$',
r' \newline\textbf{Initial field:}',
r' \newline $B_{0} = '+ 'num2str(Data.Field(1))'+ '\,\mathrm{T}$',
r' \newline\textbf{Network analyzer settings:}',
r' \newline $f_{centre} =' + str(Settings['NetworkAnalyzer']['Frequency']['CenterStart']/1e6) + '\,\mathrm{MHz}$',
r' \newline $f_{span} =' + str(Settings['NetworkAnalyzer']['Frequency']['CenterSpan']/1e6) + '\,\mathrm{MHz}$',
r' \newline Points: $' + str(Settings['NetworkAnalyzer']['Frequency']['Points']) + '$',
r' \newline $P_{start} =' + str(Settings['NetworkAnalyzer']['Power']['Start']) + '\,\mathrm{dBm}$',
r' \newline $P_{stop} =' + str(Settings['NetworkAnalyzer']['Power']['Stop']) + '\,\mathrm{dBm}$',
r' \newline Points: $' + str(Settings['NetworkAnalyzer']['Power']['Points']) + '$',
r' \newline Bandwidth: $' + str(Settings['NetworkAnalyzer']['Averages']['IFBW']) + '\,\mathrm{Hz}$',
r' \\',
' \hline',
' \end{tabular}',
'\end{document}'
]
for x in range(0,len(Tex)):
book.write(str(Tex[x]))
book.write("\n")
book.close()
Settings = MeasurementsSettings()
NetworkAnalyzer = NetworkAnalyzer('GPIB1::17::INSTR', Settings)
sReal, sImag, frequency = NetworkAnalyzer.GetTrace()
Agilent34401A = Agilent34401A('GPIB0::21::INSTR',Settings)
print(Agilent34401A.getPressure())
Plot(Settings,sReal,sImag,frequency)
Labbook(Settings)