Ticket #233: guiflag.py

File guiflag.py, 1.4 KB (added by Kana Sugimoto, 13 years ago)

guiflag.py

Line 
1import os
2from asap.parameters import rcParams
3from asap import scantable
4
5def guiflag(sdfile=None,outfile=None,outform='ASAP', overwrite=False):
6    """
7    GUI flagging method
8    Parameters
9        sdfile:    input filename
10        outfile:   output filename
11        outform:   output file format, should be either 'ASAP', 'MS2',
12                   'ASCII', or 'STDIFTS'. Default: 'ASAP'
13        overwrite: whether or not overwrite output file if exists.
14                   Default False
15    """
16    if not rcParams['plotter.gui']:
17        print "ERROR - GUI is not available"
18        return
19    from asap.flagplotter import flagplotter
20    if not (sdfile and outfile):
21        print "ERROR - sdfile and outfile is necessary"
22        return
23    if not os.path.exists(sdfile):
24        print "ERROR - invalid input filename '"+sdfile+"'"
25        return
26    if not overwrite and  os.path.exists(outfile):
27        print "ERROR - output file '"+outfile+"' already exists"
28        return
29    scan = scantable(filename=sdfile,average=False)
30    guiflagger = flagplotter(visible=True)
31    guiflagger._plotter.legend(loc=0)
32    guiflagger.plot(scan)
33    finish=raw_input("Press enter to finish interactive flagging:")
34    guiflagger._plotter.unmap()
35    guiflagger._plotter = None
36    del guiflagger
37    scan.save(outfile,outform.upper(),overwrite)
38    if outform!='ASCII':
39        print "Wrote output "+outform+" file "+outfile
40