comparison plotss.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 ff63d71e1383
children c6089f1ecc75
comparison
equal deleted inserted replaced
36:ff63d71e1383 37:3d2306e39700
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import datafile
3 import exceptions 4 import exceptions
4 import numpy 5 import numpy
5 import pylab 6 import pylab
6 import sys 7 import sys
7 8
8 class DataFile(object):
9 def __init__(self, fname):
10 f = file(fname)
11 self.opts = {}
12 for line in f:
13 key, value = line.strip().split(' ', 1)
14 if key == "XDATA":
15 self.xdata = numpy.fromstring(value, sep = ', ')
16 continue
17
18 if key == "YDATA":
19 self.ydata = numpy.fromstring(value, sep = ', ')
20 continue
21
22 try:
23 self.opts[key] = int(value)
24 except exceptions.ValueError, e:
25 try:
26 self.opts[key] = float(value)
27 except exceptions.ValueError, e:
28 self.opts[key] = value
29
30 def __getitem__(self, k):
31 return self.opts[k]
32
33 def doplot(fname): 9 def doplot(fname):
34 dfile = DataFile(fname) 10 dfile = DataFile(fname)
35 11
36 xdata = dfile.xdata / 1e6 12 xdata = dfile.freqs / 1e6
37 ydata = dfile.ydata 13 ydata = dfile.powers
38 pylab.title("Tag \'" + dfile['TAG'] + "\' at " + dfile['TIMESTAMP']) 14 pylab.title("Tag \'" + dfile['TAG'] + "\' at " + dfile['TIMESTAMP'])
39 pylab.xlabel("Frequency (MHz)") 15 pylab.xlabel("Frequency (MHz)")
40 pylab.ylabel("Level (dBm)") 16 pylab.ylabel("Level (dBm)")
41 annstr = "FStart\t%.2f MHz\nFStop\t%.2f MHz\nPoints\t%d" % ( 17 annstr = "FStart\t%.2f MHz\nFStop\t%.2f MHz\nPoints\t%d" % (
42 float(dfile['FSTART']) / 1e6, 18 float(dfile['FSTART']) / 1e6,