Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate plotss.py @ 36:ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 28 Sep 2011 11:45:52 +0930 |
parents | e80c2ff5fa87 |
children | 3d2306e39700 |
rev | line source |
---|---|
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 import exceptions |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 import numpy |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 import pylab |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 import sys |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 |
36
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
8 class DataFile(object): |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
9 def __init__(self, fname): |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
10 f = file(fname) |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
11 self.opts = {} |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
12 for line in f: |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
13 key, value = line.strip().split(' ', 1) |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
14 if key == "XDATA": |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
15 self.xdata = numpy.fromstring(value, sep = ', ') |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
16 continue |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
17 |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
18 if key == "YDATA": |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
19 self.ydata = numpy.fromstring(value, sep = ', ') |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
20 continue |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
21 |
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 try: |
36
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
23 self.opts[key] = int(value) |
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 except exceptions.ValueError, e: |
36
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
25 try: |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
26 self.opts[key] = float(value) |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
27 except exceptions.ValueError, e: |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
28 self.opts[key] = value |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
29 |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
30 def __getitem__(self, k): |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
31 return self.opts[k] |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
32 |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
33 def doplot(fname): |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
34 dfile = DataFile(fname) |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
35 |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
36 xdata = dfile.xdata / 1e6 |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
37 ydata = dfile.ydata |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
38 pylab.title("Tag \'" + dfile['TAG'] + "\' at " + dfile['TIMESTAMP']) |
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 pylab.xlabel("Frequency (MHz)") |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 pylab.ylabel("Level (dBm)") |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 annstr = "FStart\t%.2f MHz\nFStop\t%.2f MHz\nPoints\t%d" % ( |
36
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
42 float(dfile['FSTART']) / 1e6, |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
43 float(dfile['FSTOP']) / 1e6, |
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 len(xdata)) |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 pylab.annotate(annstr, xy=(5, -40), xycoords='axes points') |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 annstr = "Video BW\t%.1f kHz\nResol. BW\t%.1f kHz\nAttenuation\t%.1f dB\nRef Level\t%.1f dBm" % ( |
36
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
48 float(dfile['VIDBW']) / 1e3, |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
49 float(dfile['RESBW']) / 1e3, |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
50 float(dfile['ATTEN']), |
ff63d71e1383
Separate out data file reader into a new class for ease of reuse.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
51 float(dfile['REFLEV'])) |
33
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 pylab.annotate(annstr, xy=(-140, -55), xycoords='axes points') |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 pylab.grid(True) |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 pylab.plot(xdata, ydata, linestyle='solid', marker='.') |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 pylab.show() |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 if __name__ == "__main__": |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 if len(sys.argv) < 2: |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 print "Need at least one file to plot" |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 sys.exit(1) |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 for fn in sys.argv[1:]: |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 doplot(fn) |
e80c2ff5fa87
Add program to plot data files from sitesurvey.py
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 |