Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate datafile.py @ 37:3d2306e39700
Move DataFile class to new file for ease of reuse.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 28 Sep 2011 12:29:19 +0930 |
parents | |
children | 91b476ebc0f2 |
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) |
3d2306e39700
Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 except exceptions.ValueError, e: |
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) |
3d2306e39700
Move DataFile class to new file for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 except exceptions.ValueError, e: |
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 |