from __future__ import absolute_import
from numpy import ma, array, logical_not, logical_and
from casatasks.private.casa_transition import is_CASA6
from casatools import table, singledishms
from casatools import ms as mstool
from casatasks import casalog
from taskinit import gentools, casalog
ms, sdms, tb = gentools(['ms','sdms','tb'])
def sdfit(infile=None, datacolumn=None, antenna=None, field=None, spw=None,
timerange=None, scan=None, pol=None, intent=None,
timebin=None, timespan=None,
fitfunc=None, fitmode=None, nfit=None, thresh=None, avg_limit=None,
minwidth=None, edge=None, outfile=None, overwrite=None):
if os.path.exists(outfile):
os.system('rm -rf %s' % outfile)
raise ValueError(outfile + ' exists.')
if (fitmode not in ['list', 'auto']):
raise ValueError("fitmode='%s' is not supported yet" % fitmode)
if (spw == ''): spw = '*'
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)
tempfile = 'temp_sdfit_'+str(datetime.datetime.fromtimestamp(time.time())).replace('-','').replace(' ','').replace(':','')
if os.path.exists(tempfile):
tempfile += str(datetime.datetime.fromtimestamp(time.time())).replace('-','').replace(' ','').replace(':','')
if os.path.exists(tempfile):
raise Exception('temporary file ' + tempfile + ' exists...')
tempoutfile = tempfile + '_temp_output_ms'
if os.path.exists(tempoutfile):
tempoutfile += str(datetime.datetime.fromtimestamp(time.time())).replace('-','').replace(' ','').replace(':','')
if os.path.exists(tempoutfile):
raise Exception('temporary ms file ' + tempoutfile + ' exists...')
if fitmode=='auto': nfit = [-1]
num_fit_str = str(',').join(map(str, nfit))