changeset 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 7d76b1d70096
files datafile.py plotss.py
diffstat 2 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datafile.py	Wed Sep 28 12:29:19 2011 +0930
@@ -0,0 +1,28 @@
+import exceptions
+import numpy
+
+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.freqs = numpy.fromstring(value, sep = ', ')
+                continue
+            
+            if key == "YDATA":
+                self.powers = 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]
+    
--- 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)")