# HG changeset patch # User Daniel O'Connor # Date 1317178759 -34200 # Node ID 3d2306e397009b82e5d372471b4ac234f3dc3678 # Parent ff63d71e1383daea508dad69b208098356922f9e Move DataFile class to new file for ease of reuse. diff -r ff63d71e1383 -r 3d2306e39700 datafile.py --- /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] + diff -r ff63d71e1383 -r 3d2306e39700 plotss.py --- 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)")