Go to the documentation of this file.00001 __all_ = ['lagplotter']
00002
00003 from asap.scantable import scantable
00004 from matplotlib.pylab import *
00005 from numpy import array, ma, logical_not
00006 from numpy.fft import fft, ifft
00007
00008 class lagplotter(object):
00009 def __init__(self, stable):
00010 if not isinstance(stable, scantable):
00011 raise TypeError("This works only on scantables")
00012 self._scan = stable
00013 self.figure = None
00014 self.dataaxes = None
00015 self.fftaxes = None
00016 self.resultaxes = None
00017 self.flags = []
00018
00019 def _init_plot(self):
00020 if not self.figure:
00021 self.figure = figure()
00022 self.dataaxes = self.figure.add_subplot(3,1,1)
00023 self.fftaxes = self.figure.add_subplot(3,1,2)
00024 self.resultaxes = self.figure.add_subplot(3,1,3)
00025 else:
00026 self.dataaxes.cla()
00027 self.fftaxes.cla()
00028 self.resultaxes.cla()
00029
00030
00031 def flag(self):
00032 self._init_plot()
00033 for i in xrange(len(self._scan)):
00034 self.dataaxes.cla()
00035 self.fftaxes.cla()
00036 self.resultaxes.cla()
00037 x = array(self._scan.get_abcissa(i)[0])
00038 y = array(self._scan.get_spectrum(i))
00039 msk = self._scan.get_mask(i)
00040 marr = ma.MaskedArray(y, logical_not(msk), fill_value=0.0)
00041 self.dataaxes.plot(x, marr)
00042 nfft = len(marr)/2+1
00043 yfft = fft(marr.filled())
00044 self.fftaxes.semilogy(abs(yfft)[0:nfft])
00045 self.figure.show()
00046 raw_input("Press any key to continue...")
00047 print "Now select a start and end point by clicking on the middle plot"
00048 print "Start point ..."
00049 flagstart = int(ginput(show_clicks=False)[0][0]+0.5)
00050 print "End point ..."
00051 flagend = int(ginput(show_clicks=False)[0][0]+0.5)
00052 xfft = range(len(yfft))
00053 self.fftaxes.axvspan(flagstart, flagend, alpha=0.3)
00054 yfft[flagstart:flagend] = 0+0j
00055 yfft[-flagend:-flagstart] = 0+0j
00056 yi = ifft(yfft)
00057 self.resultaxes.plot(x, yi)
00058 self.figure.show()
00059 inp = raw_input("Commit flags (c), keep (k) or ignore(i)? ")\
00060 .lower()
00061 if inp.startswith("c"):
00062 self.flags.append([flagstart, flagend])
00063 self._scan.set_spectrum(yi.real, i)
00064 elif inp.startswith("k"):
00065 self.flags.append([flagstart, flagend])
00066 else:
00067 del self.fftaxes.patches[-1]
00068 cont = raw_input("Continue (c) or quit (q)? ")
00069 if not cont == "c":
00070 return self.flags
00071 return self.flags