from collections import Counter
from casatasks import casalog
from casatools import ms as mstool
from casatools import singledishms
from .mstools import write_history
@sdutil.callable_sdtask_decorator
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):
fftmethod = fftmethod.lower()
if isinstance(fftthresh, str):
fftthresh = fftthresh.lower()
if not os.path.exists(infile):
raise ValueError("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 (not overwrite) and dosubtract and os.path.exists(outfile):
raise ValueError("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)
temp_outfile = _do_fit(infile, datacolumn, antenna, field, spw, timerange, scan,
pol, intent, reindex, maskmode, thresh, avg_limit, minwidth,
edge, dosubtract, blformat, bloutput, blfunc, order, npiece,
applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh,
clipniter, blparam, verbose, updateweight, sigmavalue,
elif (blmode == 'apply'):
_do_apply(infile, datacolumn, antenna, field, spw, timerange, scan, pol, intent,
reindex, bltable, updateweight, sigmavalue, outfile, overwrite)
with sdutil.table_manager(outfile, nomodify=False) as mytb:
cols_spectrum = ['WEIGHT_SPECTRUM', 'SIGMA_SPECTRUM']
cols_remove = [col for col in cols_spectrum if col in mytb.colnames()]
mytb.removecols(' '.join(cols_remove))
param_names = sdbaseline.__code__.co_varnames[:sdbaseline.__code__.co_argcount]
param_vals = [var_local[p] for p in param_names]
write_history(ms, outfile, 'sdbaseline', param_names,
blformat_item = ['csv', 'text', 'table']