from __future__ import absolute_import
from collections import Counter
from casatasks.private.casa_transition import *
from casatools import singledishms, table, msmetadata
from casatools import ms as mstool
from casatasks import casalog
from .mstools import write_history
from taskinit import gentools, casalog
from mstools import write_history
ms, sdms, tb, msmd = gentools(['ms', 'sdms', 'tb', 'msmd'])
def sdbaseline(infile=None, datacolumn=None, antenna=None, field=None,
spw=None, timerange=None, scan=None, pol=None, intent=None,
reindex=None, maskmode=None, thresh=None, avg_limit=None,
minwidth=None, edge=None, blmode=None, dosubtract=None,
blformat=None, bloutput=None, bltable=None, blfunc=None,
order=None, npiece=None, applyfft=None, fftmethod=None,
fftthresh=None, addwn=None, rejwn=None, clipthresh=None,
clipniter=None, blparam=None, verbose=None,
updateweight=None, sigmavalue=None,
showprogress=None, minnrow=None,
outfile=None, overwrite=None):
casalog.origin('sdbaseline')
fftmethod = fftmethod.lower()
if isinstance(fftthresh, str):
fftthresh = fftthresh.lower()
if not os.path.exists(infile):
raise Exception("infile='" + str(infile) + "' does not exist.")
if (outfile == '') or not isinstance(outfile, str):
outfile = infile.rstrip('/') + '_bs'
casalog.post("outfile is empty or non-string. set to '" + outfile + "'")
if os.path.exists(outfile) and not overwrite:
raise Exception("outfile='%s' exists, and cannot overwrite it." % (outfile))
if (maskmode == 'interact'):
raise ValueError("maskmode='%s' is not supported yet" % maskmode)
if (blfunc == 'variable' and not os.path.exists(blparam)):
raise ValueError("input file '%s' does not exists" % blparam)
blparam_file = infile + '_blparam.txt'
if os.path.exists(blparam_file):
remove_data(blparam_file)
if (spw == ''): spw = '*'
if not os.path.exists(bltable):
raise ValueError("file specified in bltable '%s' does not exist." % bltable)
sorttab_info = remove_sorted_table_keyword(infile)
if overwrite and os.path.exists(outfile) and (infile != outfile):
os.system('rm -rf %s' % outfile)
selection = ms.msseltoindex(vis=infile, spw=spw, field=field,
baseline=antenna, time=timerange,
sdms.set_selection(spw=sdutil.get_spwids(selection), field=field,
antenna=antenna, timerange=timerange,
scan=scan, polarization=pol, intent=intent,
sdms.apply_baseline_table(bltable=bltable,
updateweight=updateweight,