annotate agilent_r5071.py @ 70:6ffa6fcf278e

Move pylab import to where graphing is so we don't need an X server
author Daniel O'Connor <doconnor@gsoft.com.au>
date Mon, 30 Aug 2021 12:40:43 +0930
parents 6bd941d96c03
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 # Docs are at http://ena.tm.agilent.com/e5071c/manuals/webhelp/eng/
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
3 import numpy
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 import scpi
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 import pylab
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
7 fname = 'data'
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
8
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 # Connect
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 inst = scpi.instURL('vxi://203.31.81.47')
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 # Read ID
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 inst.write('*IDN?')
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 inst.read()
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 # 'Agilent Technologies,E5071C,MY46109815,A.09.54\n'
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 # Set to 8 byte floats
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 inst.write(":FORM:DATA REAL")
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 # Set to little endian
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 inst.write(':FORM:BORD SWAP')
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 # Grab frequency data
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 inst.write(":SENS1:FREQ:DATA?")
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 freqs = scpi.bindecode(inst.read(), dtype = numpy.float64)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 # Grab trace data
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 inst.write(":CALC1:TRACE1:DATA:FDATA?")
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 dat = scpi.bindecode(inst.read(), dtype = numpy.float64)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 # We only want the real part (no imag for this measurement)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 dat = dat[::2]
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
34 # Plot
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
35 pylab.plot(freqs, dat)
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
36 pylab.show()
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
37
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 # Save for later
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
39 numpy.savez('data.npz', freqs, dat)
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 # Load..
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
42 f = numpy.load(fname + '.npz')
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 freqs = f['arr_0']
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 dat = f['arr_1']
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45
45
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
46 f = file(fname + '.csv', 'wb')
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
47 f.write("Frequencies\n")
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
48 numpy.savetxt(f, [freqs], delimiter = ',')
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
49 f.write("Gain\n")
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
50 numpy.savetxt(f, [dat], delimiter = ',')
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
51 del f
6bd941d96c03 Commit final version that went to Norway
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
52