annotate datafile.py @ 85:60ad91b4c67c default tip

Add 'quick' option to use a faster sweep time with no averaging. Useful for testing the hardware is setup correctly without having to wait 3 minutes.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Mon, 21 Oct 2024 14:12:50 +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