NOTE: The vector mode of the flagdata task (pre-dating CASA 3.4) can be achieved with this task
          by using it with mode='list' and the commands given in a list in inpmode=[]. Example:  

flagdata('my.ms', inpmode='list', inpfile=["mode='clip' clipzeros=True","mode='shadow'])

    Manually flag scans 1~3 and save the parameters to the FLAG_CMD sub-table.

flagdata('my.ms', scan='1~3, mode='manual', savepars=True)

    Save the parameters to a file that is open in append mode.

flagdata('my.ms', scan='1~3, mode='manual', savepars=True, outfile='flags.txt')

    Flag all the commands given in the Python list of strings.

cmd = ["scan='1~3' mode='manual'",
               "spw='9' mode='tfcrop' correlation='ABS_RR,LL' ntime=51.0",
               "mode='extend' extendpols=True"]
flagdata('my.ms', mode='list', inpfile=cmd)

    Flag all the commands given in the file called flags.txt.   

cat flags.txt
        scan='1~3' mode='manual'
        spw='9' mode='tfcrop' correlation='ABS_RR,LL' ntime=51.0
        mode='extend' extendpols=True
flagdata('my.ms', mode='list', inpfile='flags.txt')

    Display the data and flags per-chunk and do not write flags to the MS.

flagdata('my.ms', mode='list', inpfile='flags.txt', action='calculate', display='data')

    Flag all the antennas except antenna=5.

flagdata(vis='my.ms', antenna='!5', mode='manual)

    Clip the NaN in the data. An empty clipminmax will flag only NaN.

flagdata('my.ms', mode='clip')

    Clip only the water vapour radiometer data.

flagdata('my.ms',mode='clip',clipminmax=[0,50], correlation='ABS_WVR')

    Clip only zero-value data.


    Flag only auto-correlations of non-radiometer data using the autocorr parameter.

flagdata('my.ms', autocorr=True)

     Flag only auto-correlations using the antenna selection.

flagdata('my.ms', mode='manual', antenna='*&&&')

    Flag based on selected reasons from a file.

This box is intended for CASA Inputs. Insert your text here.> cat flags.txt
scan='1~3' mode='manual' reason='MYREASON'
spw='9' mode='clip' clipzeros=True reason='CLIPZEROS'
mode='manual' scan='4' reason='MYREASON'


flagdata('my.ms', mode='list', inpfile='flags.txt', reason='MYREASON').

    The same result of 10a can be achieved using the task flagcmd.

flagcmd('my.ms', inpmode='file', inpfile='flags.txt', action='apply', reason='MYREASON')

    Automatic flagging using 'rflag', using auto-thresholds, and specifying
          a threshold scale-factor to use for flagging.

flagdata('my.ms', mode='rflag',spw='9',timedevscale=4.0,action='apply')

    Save the interface parameters to the FLAG_CMD sub-table of the MS. Add a reason
        to the flag command. This cmdreason will be added to the REASON column of the
        FLAG_CMD sub-table. Apply flags in flagcmd.

flagdata('my.ms', mode='clip',channelavg=False, clipminmax=[30., 60.], spw='0:0~10',
                  correlation='ABS_XX,XY', action='', savepars=True, cmdreason='CLIPXX_XY')

#Select based on the reason.
flagcmd('my.ms', action='apply', reason='CLIPXX_XY')

    Flag antennas that are shadowed by antennas not present in the MS.

> Create a text file with information about the antennas.
> cat ant.txt
          position=[-1601144.96146691, -5041998.01971858, 3554864.76811967]
          position=[-1601105.7664601889, -5042022.3917835914, 3554847.245159178]
          position=[-1601197.2182404203, -5041974.3604805721, 3554875.1995636248]

flagdata('my.vis', mode='shadow', tolerance=10.0, addantenna='ant.txt')

The antenna information can also be given as a Python dictionary. To create the
dictionary using the flaghelper functions, do the following inside casapy:

> import flaghelper as fh
> antdic = fh.readAntennaList(antfile)

flagdata('my.vis', mode='shadow', tolerance=10.0, addantenna=antdic)

    Apply the online flags that come from importasdm.

> In importasdm, save the online flags to a file.
importasdm('myasdm', 'asdm.ms', process_flags=True, savecmds=True, outfile='online_flags.txt')

> You can edit the online_flags.txt to add other flagging commands or apply it directly.
flagdata('asdm.ms', mode='list', inpfile='online_flags.txt')

> The same result can be achieved using the task flagcmd.
flagcmd('asdm.ms', inpmode='file', inpfile='online_flags.txt', action='apply')

    Clip mode pre-averaging data across channels and across time

flagdata(vis='Four_ants_3C286.ms', flagbackup=False, mode='clip', datacolumn='DATA',
        timeavg=True, timebin='2s', channelavg=True, chanbin=2)



    Clip zero data from a bandpass calibration table.

flagdata('cal-X54.B1', mode='clip', clipzeros=True, datacolumn='CPARAM')

    Clip data from a cal table with SNR <4.0.

flagdata('cal-X54.B1', mode='clip', clipminmax=[0.0,4.0], clipoutside=False, datacolumn='SNR')

    Clip the g values of a switched power caltable created using the gencal task. The g values are
        usually < 1.0.


    Now, clip the Tsys values of the same table from above. The Tsys solutions have values between 10 -- 100s.