source: branches/asap-3.x/python/lagflagger.py@ 3150

Last change on this file since 3150 was 1697, checked in by Malte Marquarding, 15 years ago

Some minor tidy up and documentation

File size: 2.6 KB
Line 
1from asap import scantable
2from matplotlib.pylab import *
3from numpy import array, ma, logical_not
4from numpy.fft import fft, ifft
5
6class lagplotter(object):
7 def __init__(self, stable):
8 if not isinstance(stable, scantable):
9 raise TypeError("This works only on scantables")
10 self._scan = stable
11 self.figure = None
12 self.dataaxes = None
13 self.fftaxes = None
14 self.resultaxes = None
15 self.flags = []
16
17 def _init_plot(self):
18 if not self.figure:
19 self.figure = figure()
20 self.dataaxes = self.figure.add_subplot(3,1,1)
21 self.fftaxes = self.figure.add_subplot(3,1,2)
22 self.resultaxes = self.figure.add_subplot(3,1,3)
23 else:
24 self.dataaxes.cla()
25 self.fftaxes.cla()
26 self.resultaxes.cla()
27
28
29 def flag(self):
30 self._init_plot()
31 for i in xrange(len(self._scan)):
32 self.dataaxes.cla()
33 self.fftaxes.cla()
34 self.resultaxes.cla()
35 x = array(self._scan.get_abcissa(i)[0])
36 y = array(self._scan.get_spectrum(i))
37 msk = self._scan.get_mask(i)
38 marr = ma.MaskedArray(y, logical_not(msk), fill_value=0.0)
39 self.dataaxes.plot(x, marr)
40 nfft = len(marr)/2+1
41 yfft = fft(marr.filled())
42 self.fftaxes.semilogy(abs(yfft)[0:nfft])
43 self.figure.show()
44 raw_input("Press any key to continue...")
45 print "Now select a start and end point by clicking on the middle plot"
46 print "Start point ..."
47 flagstart = int(ginput(show_clicks=False)[0][0]+0.5)
48 print "End point ..."
49 flagend = int(ginput(show_clicks=False)[0][0]+0.5)
50 xfft = range(len(yfft))
51 self.fftaxes.axvspan(flagstart, flagend, alpha=0.3)
52 yfft[flagstart:flagend] = 0+0j
53 yfft[-flagend:-flagstart] = 0+0j
54 yi = ifft(yfft)
55 self.resultaxes.plot(x, yi)
56 self.figure.show()
57 inp = raw_input("Commit flags (c), keep (k) or ignore(i)? ")\
58 .lower()
59 if inp.startswith("c"):
60 self.flags.append([flagstart, flagend])
61 self._scan.set_spectrum(yi.real, i)
62 elif inp.startswith("k"):
63 self.flags.append([flagstart, flagend])
64 else:
65 del self.fftaxes.patches[-1]
66 cont = raw_input("Continue (c) or quit (q)? ")
67 if not cont == "c":
68 return self.flags
69 return self.flags
Note: See TracBrowser for help on using the repository browser.