flagcmd
- flagcmd(vis, inpmode='table', inpfile='', tablerows='', reason='any', useapplied=False, tbuff=0.0, ants='', action='apply', flagbackup=True, clearall=False, rowlist='', plotfile='', savepars=False, outfile='', overwrite=True)[source]
Flagging task based on batches of flag-commands
[Description] [Examples] [Development] [Details]
- Parameters
vis (path) - Name of MS file or calibration table to flag
inpmode (string=’table’) - Input mode for flag commands(table/list/xml)
inpmode = table
inpfile ({string, stringVec}=’’) - Source of flag commands
tablerows (intVec=’’) - Rows of inpfile to read
reason ({string, stringVec}=’any’) - Select by REASON types
useapplied (bool=False) - Select commands whose rows have APPLIED column set to True
inpmode = list
action (string=’apply’) - Action to perform in MS and/or in inpfile (apply/unapply/list/plot/clear/extract)
action = apply
flagbackup (bool=True) - Automatically backup the FLAG column before execution
action = unapply
flagbackup (bool=True) - Automatically backup the FLAG column before execution
action = plot
plotfile (string=’’) - Name of output file to save plot
savepars (bool=False) - Save flag commands to the MS or file
- Returns
out (dict) - names of plot files for action=’plot’, internal flagging dictionary for action=’extract’
- Description
The flagcmd task will flag the visibility data or the calibration table based on several batch-operations using flag commands. There is an extensive and detailed description of this task on the Data Examination and Editing chapter.
Flag commands follow the mode and parameter names from the flagdata task. Please refer to the flagdata task for a detailed explanation.
The flagcmd task will flag data based on the commands input on inpmode such as:
‘table’ = input from FLAG_CMD table in MS
‘list’ = input from text file or list of strings given in inpfile
‘xml’ = input from Flag.xml in the MS given by vis (largely obsolete with the deprecation of importevla in CASA 5.4)
Warning
WARNING: The option to import XML files with online flag in flagcmd has largely become obsolete with the deprecation of task importevla in CASA 5.4, because the recommended importasdm task cannot copy the actual XML tables from the original SDM to the newly created MS (it can only apply the online flags directly, or write them into ascii tables). The Flag.xml, Antenna.xml and SpectralWindow.xml tables must first be copied manually into the top-level MS directory for use by flagcmd (not the recommended approach). Consider the use of the recommended task flagdata instead, as explained in the CASA Docs chapters on “importasdm” and “importing uv-data”.
IMPORTANT: The FLAG_CMD sub-table is meant only for meta-data selections such as online flags. Using it to save other parameters (from modes such as clip, quack, shadow, etc) is possible but carries a risk that in future releases these parameters maybe renamed or changed their default values. Use it at your own risk! There will be no automatic way to rename any parameter that changes in the future.
There is no way to guarantee that a command from the COMMAND column has been applied or not to the MS, even if the APPLIED column is set to True. If you use other ways to flag such as interactive flagging in plotms, the FLAG_CMD will not be updated! Use at your own risk.
Note
NOTE on flagging calibration tables:
It is possible to flag cal tables using this task, although we recommend using the flagdata task for this.
When using this task to flag cal tables, only the ‘apply’ and ‘list’ actions are supported. Because cal tables do not have a FLAG_CMD sub-table, the default inpmode=’table’ can only be used if an MS is given in the inpfile parameter, so that flags from the MS are applied to the cal table. Otherwise the flag commands must be given using inpmode=’list’, either from a file(s) or from a list of strings. See the parameters tab for more information. Data selection for calibration tables is limited to field, scan, antenna, time, spw and observation. If the calibration table was created before CASA 4.1, this task will create a dummy OBSERVATION column and OBSERVATION sub-table in the input calibration table to adapt it to the new cal table format.
- Examples
More examples of using the flagcmd task can be found here.
Use inpmode=’table’
Use action=’list’ first to see what is in the MS before doing anything else.
flagcmd(vis='example.ms', inpmode='table', action='list')
Apply the flags stored in the FLAG_CMD table in the MS. This is the default setup of flagcmd. Note that when a flag command is applied, the corresponding APPLIED column cell will be updated to True.
flagcmd(vis='example.ms', inpmode='table', action='apply', useapplied=False)
To re-apply the flags stored in the FLAG_CMD table in the MS.
flagcmd(vis='example.ms', inpmode='table', action='apply', useapplied=True)
To save flag commands from one MS to another without applying them. Flag commands will be copied from “other.ms” to the FLAG_CMD of “example.ms”.
flagcmd(vis='example.ms', inpmode='table', inpfile='other.ms', action='list')
To save flag commands from a file into the MS without applying.
flagcmd(vis='example.ms', inpmode='list', inpfile='flags.txt', action='list')
Select only certain rows from the FLAG_CMD table. Currently this must be a list of individual row numbers (0-based).
flagcmd(vis='example.ms', inpmode='table', action='apply', useapplied=False, tablerows=[0,1,2,3,10,11]) flagcmd(vis='example.ms', inpmode='table', action='apply', useapplied=False, tablerows=range(29))
Note
NOTE: The useapplied=True/False parameter is important if you are going to (re)apply flags marked as APPLIED True in FLAG_CMD. It is common to have a “failed” flagging operation mark the flags as already applied and then they don’t show up when you re-run (e.g. in ‘list’). Set useapplied=True so that it will use these anyway.
To apply the flag commands from an MS to a calibration table, recall that inpmode=’table’ can only be used if an MS is given in the inpfile parameter, so that flags from the MS are applied to the cal table.
flagcmd(vis='mycaltable', inpmode='table', inpfile='example.ms', action='apply')
Use inpmode=’xml’
List the online flags stored in the Flag.xml file of a VLA MS.
flagcmd(vis='example.ms', inpmode='xml', action='list')
Directly apply the online flags stored in the Flag.xml file in the MS, set inpmode=’xml’ and desired buffer.
flagcmd(vis='example.ms', inpmode='xml', action='apply', tbuff=1.0)
Apply the flags using a specific set of reasons (a comma separated list).
flagcmd(vis='example.ms', inpmode='xml', action='apply', reason='FOCUS_ERROR,SUBREFLECTOR_ERROR')
Note
NOTE: The online flag time buffer tbuff is specified in seconds, but in fact should be keyed to the intrinsic online integration time. This is particularly true for EVLA data, were a tbuff value of 0.5x to 1.5x the integration time is needed (currently you should use 1.5x for data taken in early 2011 or before).
Use inpmode=’list’
Apply the flags given in an ASCII file such as the one below, which will be saved in a file called “myflags.txt”:
antenna='ea01' timerange='00:00:00~01:00:00' antenna='ea11' timerange='00:00:00~03:00:00' spw='0~4' mode='clip' clipminmax=[0,5] correlation='ABS_ALL' mode='quack' quackmode='end' quackinterval=1.0 mode='shadow' antenna='ea01,ea02,ea03'
flagcmd(vis='example.ms',inpmode='list',inpfile='myflags.txt')
Or the flag commands can be given in the interface of the task, using a Python list.
flagcmd(vis='example.ms',inpmode='list',inpfile=["mode='shadow'", "mode='clip' clipminmax=[0,5] correlation='ABS_ALL'", "mode='quack' quackmode='end' quackinterval=1.0", "antenna='ea01' timerange='00:00:00~01:00:00'", "antenna='ea11' timerange='00:00:00~03:00:00' spw='0~4'"])
- Development
No additional development details
- Parameter Details
Detailed descriptions of each function parameter
vis (path)
- Name of input visibility file or calibration table.default: ‘’ (none)example: vis=’uid___A002_X2a5c2f_X54.ms’inpmode (string='table')
- Input mode for flag commands(table/list/xml)options: ‘table’,’list’,’xml’default: ‘table’ (the input commands fromFLAG_CMD table of the MS)inpmode=’xml’ inputs online flags from Flag.xmlfile in the MS. This mode has become largelyobsolete with the deprecation of the importevlatask (see the flagcmd task pages in CASA Docs formore information). This mode will not work forALMA MS or cal tables.NOTE: You can only apply the flags from a list orxml; you will not be able to unapplythem. Transfer the flag commands to the FLAG_CMDtable if you want to unapply the flags (see‘inpfile’ description below).inpfile ({string, stringVec}='')
- Source of flag commands. Subparameter ofinpmode=’table/list’.Path to MS containing FLAG_CMD (table), or nameof an ASCII file, list of files or a list ofPython strings to apply to MS or cal table(list).options: [] with flag commands or [] withfilenames or ‘’ with a filename. (String valuesmust contain quotes around them or the parserwill not work.)default: ‘’ (read from FLAG_CMD table in the MSspecified via ‘vis’)Main use is to read flags from internal FLAG_CMD,but one use case is to read the flag commandsfrom an MS given in inpfile and apply them toanother MS or cal table given in vis.tablerows (intVec='')
- List of rows of the FLAG_CMD table to read. Subparameterof inpmode=’table/list’.default: [] (read all rows)example: [0,1,2,10]NOTE: currently only takes integer lists, notparseable strings with ranges. Use the Pythonrange function to generate ranges, e.g. tablerows= range(0,30) + range(50,55) instead of‘0~29,50~54’ for now.reason ({string, stringVec}='any')
- Select flag commands based on REASON(s). Subparameter ofinpmode.default: ‘any’ (all flags regardless of reason)Examples:reason=’FOCUS_ERROR’reason=[‘FOCUS_ERROR’,’SUBREFLECTOR_ERROR’]If inpfile is a list of files, the reasons givenin this parameter will apply to all the files.NOTE: what is within the string is literallymatched, e.g. reason=’’ matches only blankreasons, and reason=’FOCUS_ERROR,SUBREFLECTOR_ERROR’ matches thiscompound reason string onlyuseapplied (bool=False)
- Select commands whose rows have APPLIED column set toTrue. Subparameter of inpmode=’table’.options: True,Falsedefault: FalseIf useapplied=True it will read in both appliedand unapplied flags.IMPORTANT: The APPLIED column is set to Trueafter a flag command is applied to the MS. Inorder to re-apply the same flag command, thisparameter should be set to True.tbuff (double=0.0)
- Time buffer (sec) to pad flags. Subparameter ofinpmode=’xml’.default: 0.0ants (string='')
- Allowed flag antenna names to select by. Subparameter ofinpmode=’xml’.action (string='apply')
- Action to perform in MS and/or in inpfileoptions: apply/unapply/list/plot/clear/extractdefault: ‘apply’Examples:– action=’apply’: This operation will applythe commands chosen by inpmode. Ifinpmode=’table’ and inpfile=’’ then theAPPLIED column in FLAG_CMD will be set toTrue.– action=’unapply’: unapply flags in MS. (Notavailable for cal tables). This operation willunapply the commands chosen by inpmode=’table’ONLY. After unapplying the commands, the taskwill update the APPLIED column to False.– action=’list’: list and/or save flagcommands. This operation will list thecommands chosen by inpmode on the screen andsave them to the MS or to a file withoutapplying. It will save the commands to outfileif the parameter savepars is set to True. Ifoutfile is None, it will save the commands tothe MS given in ‘vis’.– action=’plot’: plot flags (antvs. time). (Not available for caltables). This operation will plot the flagschosen by inpmode to a matplotlib gui or to afile. These will be sorted by antennavs. time. Most useful for showing the onlineflags.– action=’clear’: clear flags from FLAG_CMDin the MS. (Not available for cal tables) Thisoperation will delete the selected flag rowsfrom the internal FLAG_CMD table of the MS.– action=’extract’: extract internal flagdictionary. (Not available for cal tables)This option will return the internal flaggingdictionary to python. There is no extantdescription of the format of this dictionary,as it is an internal device used by theflagcmd task. This action is provided for theconvenience of advanced users.WARNING: choosing this action=’clear’ willdisregard anything you set in inpmode and willalways work on the FLAG_CMD table in vis. This canbe used to totally delete rows from the FLAG_CMDtable, when setting clearall=True.flagbackup (bool=True)
- Automatically backup the FLAG column beforeexecution. Subparameter of action=’apply/unapply’.options: True,Falsedefault: Trueclearall (bool=False)
- Delete all rows from FLAG_CMD. Subparameter ofaction=’clear’.default: False (will not clear)rowlist (intVec='')
- FLAG_CMD rows to clear. Subparameter of action=’clear’.default: [] (all flags in table)example: [0,1,2,10]WARNING: this can be dangerous, and you must setclearall=True to use this!!! This will deletethe specified rows from the internal FLAG_CMDtable for vis regardless of what mode is set to(useful for when you import from xml or file),and decide to redo it). This action will NOTunapply the commands.NOTE: currently only takes integer lists, notparseable strings with ranges. Use the Pythonrange function to generate ranges, e.g. rowlist =range(0,30) + range(50,55) instead of‘0~29,50~54’ for now.plotfile (string='')
- Name of output file to save plotdefault: ‘’ (plot to matplotlib window)WARNING: will only reliably plot individual flagsper antenna and timerange (e.g. direct from xml)savepars (bool=False)
- Save the flag commands to the FLAG_CMD table of the MS orto an output text file.options: True/Falsedefault: Falseoutfile (string='')
- Name of output file to save commands. Subparameter ofsavepars=True.default: ‘ ‘; it will save the commands in theFLAG_CMD table of the MS.example: outfile=’flags.txt’ will save theparameters in a text file.overwrite (bool=True)
- Overwrite an existing file given in ‘outfile’ to save theflag commands. Subparameter of savepars=True.options: True/Falsedefault: True; it will remove the existing filegiven in ‘outfile’ and save the current flagcommands to a new file with the same name. Whenset to False, the task will exit with an errormessage if the file exist.