diff plotss.py @ 33:e80c2ff5fa87

Add program to plot data files from sitesurvey.py
author Daniel O'Connor <darius@dons.net.au>
date Wed, 21 Sep 2011 15:34:49 +0930
parents
children ff63d71e1383
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plotss.py	Wed Sep 21 15:34:49 2011 +0930
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import exceptions
+import numpy
+import pylab
+import sys
+
+def doplot(fname):
+    f = file(fname)
+    opts = {}
+    for line in f:
+        key, value = line.strip().split(' ', 1)
+        try:
+            opts[key] = int(value)
+        except exceptions.ValueError, e:
+            try:
+                opts[key] = float(value)
+            except exceptions.ValueError, e:
+                opts[key] = value
+        
+    xdata = numpy.fromstring(opts['XDATA'], sep = ', ')
+    ydata = numpy.fromstring(opts['YDATA'], sep = ', ')
+    xdata /= 1e6
+    pylab.title("Tag \'" + opts['TAG'] + "\' at " + opts['TIMESTAMP'])
+    pylab.xlabel("Frequency (MHz)")
+    pylab.ylabel("Level (dBm)")
+    annstr = "FStart\t%.2f MHz\nFStop\t%.2f MHz\nPoints\t%d" % (
+        float(opts['FSTART']) / 1e6,
+        float(opts['FSTOP']) / 1e6,
+        len(xdata))
+    pylab.annotate(annstr, xy=(5, -40),  xycoords='axes points')
+
+    annstr = "Video BW\t%.1f kHz\nResol. BW\t%.1f kHz\nAttenuation\t%.1f dB\nRef Level\t%.1f dBm" % (
+        float(opts['VIDBW']) / 1e3,
+        float(opts['RESBW']) / 1e3,
+        float(opts['ATTEN']),
+        float(opts['REFLEV']))        
+    pylab.annotate(annstr, xy=(-140, -55),  xycoords='axes points')
+    pylab.grid(True)
+    pylab.plot(xdata, ydata, linestyle='solid', marker='.')
+    pylab.show()
+    
+if __name__ == "__main__":
+    if len(sys.argv) < 2:
+        print "Need at least one file to plot"
+        sys.exit(1)
+
+    for fn in sys.argv[1:]:
+        doplot(fn)
+