Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate datafile.py @ 81:1947d10f9395
- Search for signal frequency iteratively to improve accuracy.
- Use narrower bandwidths (via FFT filter) for close in measurements.
- Work around bug in firmware when using FFT filter.
- Actually _raise_ the exception when the signal power is too low.
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Fri, 27 Sep 2024 16:56:44 +0930 |
parents | 91b476ebc0f2 |
children |
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 | 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 | 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 |