diff 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
line wrap: on
line diff
--- a/plotss.py	Wed Sep 28 11:45:52 2011 +0930
+++ b/plotss.py	Wed Sep 28 12:29:19 2011 +0930
@@ -1,40 +1,16 @@
 #!/usr/bin/env python
 
+import datafile
 import exceptions
 import numpy
 import pylab
 import sys
 
-class DataFile(object):
-    def __init__(self, fname):
-        f = file(fname)
-        self.opts = {}
-        for line in f:
-            key, value = line.strip().split(' ', 1)
-            if key == "XDATA":
-                self.xdata = numpy.fromstring(value, sep = ', ')
-                continue
-            
-            if key == "YDATA":
-                self.ydata = numpy.fromstring(value, sep = ', ')
-                continue
-            
-            try:
-                self.opts[key] = int(value)
-            except exceptions.ValueError, e:
-                try:
-                    self.opts[key] = float(value)
-                except exceptions.ValueError, e:
-                    self.opts[key] = value
-
-    def __getitem__(self, k):
-        return self.opts[k]
-    
 def doplot(fname):
     dfile = DataFile(fname)
     
-    xdata = dfile.xdata / 1e6
-    ydata = dfile.ydata
+    xdata = dfile.freqs / 1e6
+    ydata = dfile.powers
     pylab.title("Tag \'" + dfile['TAG'] + "\' at " + dfile['TIMESTAMP'])
     pylab.xlabel("Frequency (MHz)")
     pylab.ylabel("Level (dBm)")