source: trunk/python/lagflagger.py@ 1584

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

Some instructions via print, change behaviour to also just keep flags without appplting them to the data

File size: 2.5 KB
RevLine 
[1578]1from asap import scantable
2from 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...")
[1583]45 print "Now select a start and end point by clicking on the middle plot"
46 print
[1578]47 flagstart = int(ginput(show_clicks=False)[0][0]+0.5)
48 flagend = int(ginput(show_clicks=False)[0][0]+0.5)
49 xfft = range(len(yfft))
50 self.fftaxes.axvspan(flagstart, flagend, alpha=0.3)
51 yfft[flagstart:flagend] = 0+0j
52 yfft[-flagend:-flagstart] = 0+0j
53 yi = ifft(yfft)
54 self.resultaxes.plot(x, yi)
55 self.figure.show()
[1583]56 inp = raw_input("Commit flags (c), keep (k) or ignore(i)? ").lower()
57 if inp.startswith("c")
[1578]58 self.flags.append([flagstart, flagend])
59 self._scan.set_spectrum(yi.real, i)
[1583]60 elif inp.startswith("k"):
61 self.flags.append([flagstart, flagend])
[1578]62 else:
63 del self.fftaxes.patches[-1]
64 cont = raw_input("Continue (c) or quit (q)? ")
65 if not cont == "c":
66 return self.flags
67 return self.flags
Note: See TracBrowser for help on using the repository browser.