annotate datafile.py @ 68:f95db5ea2fe1

Add example code to configure a Rigol DSG815 for a frequency sweep
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 19 Jan 2021 17:32:57 +1030
parents 91b476ebc0f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 import exceptions
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 import numpy
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 class DataFile(object):
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 def __init__(self, fname):
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 f = file(fname)
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 self.opts = {}
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 for line in f:
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 key, value = line.strip().split(' ', 1)
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 if key == "XDATA":
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 self.freqs = numpy.fromstring(value, sep = ', ')
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 continue
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 if key == "YDATA":
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 self.powers = numpy.fromstring(value, sep = ', ')
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 continue
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 try:
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 self.opts[key] = int(value)
56
91b476ebc0f2 Run through 2to3
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 37
diff changeset
20 except exceptions.ValueError as e:
37
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 try:
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 self.opts[key] = float(value)
56
91b476ebc0f2 Run through 2to3
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 37
diff changeset
23 except exceptions.ValueError as e:
37
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 self.opts[key] = value
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 def __getitem__(self, k):
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 return self.opts[k]
3d2306e39700 Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28