Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate datafile.py @ 83:4cc3d0706dd1
Add suffixes down to atto
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Thu, 03 Oct 2024 08:56:07 +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 |