Source
raise RuntimeError( 'There are no unapplied flags in the input. Set useapplied=True to also use the previously-applied flags.' )
import os
import copy
import numpy as np
from collections import defaultdict
from casatasks import casalog
from casatools import ms, quanta, table, agentflagger
from .mstools import write_history
from . import flaghelper as fh
qalocal = quanta( )
tblocal = table( )
def flagcmd(
vis=None,
inpmode=None,
inpfile=None,
tablerows=None,
reason=None,
useapplied=None,
tbuff=None,
ants=None,
action=None,
flagbackup=None,
clearall=None,
rowlist=None,
plotfile=None,
savepars=None,
outfile=None,
overwrite=None
):
#
# Task flagcmd
# Reads flag commands from file or string and applies to MS
try:
from xml.dom import minidom
except Exception as exc:
raise ImportError('Failed to load xml.dom.minidom into python: {}'.format(exc))
casalog.origin('flagcmd')
aflocal = agentflagger()
mslocal = ms()
mslocal2 = ms()
try:
# Use a default ntime to open the MS. The user-set ntime will be
# used in the tool later
ntime = 0.0
# Open the MS and attach it to the tool
if (type(vis) == str) & os.path.exists(vis):
aflocal.open(vis, ntime)
else:
raise ValueError( 'Visibility data set not found - please verify the name' )
# Check if vis is a cal table:
# typevis = 1 --> cal table
# typevis = 0 --> MS
# typevis = 2 --> MMS
iscal = False
typevis = fh.isCalTable(vis)
if typevis == 1:
iscal = True
if action != 'apply' and action != 'list':
raise ValueError( 'Unsupported action for cal tables. Only apply and list are supported.' )
if inpmode == 'table' and isinstance(inpfile, str) and inpfile == '':
raise ValueError( 'inpmode=\'table\' needs an MS as inpfile' )
flagcmds = {}
if inpmode == 'table' and fh.isCalTable(inpfile) == 0:
# Read flag cmds from the MS
flagcmds = readCalCmds(vis, inpfile, [], tablerows, reason, useapplied)
listmode = 'cmd'
elif inpmode == 'list':
# Read flag cmds from a list
flagcmds = readCalCmds(vis, '', inpfile, [], reason, True)
listmode = ''
else:
raise ValueError( 'Unsupported inpmode for cal tables' )
# Apply flag cmds
if len(flagcmds.keys( )) == 0:
raise RuntimeError( 'There are no unapplied flags in the input. '\
'Set useapplied=True to also use the previously-applied flags.' )