from __future__ import absolute_import
import os
from casatasks.private.casa_transition import *
if is_CASA6:
from casatools import calibrater, table, ms
from casatasks import casalog
from .mstools import write_history
from .parallel.parallel_data_helper import ParallelDataHelper
from .parallel.parallel_task_helper import ParallelTaskHelper
else:
from taskinit import cbtool as calibrater
from taskinit import tbtool as table
from taskinit import mstool as ms
from taskinit import casalog
from mstools import write_history
from parallel.parallel_data_helper import ParallelDataHelper
from parallel.parallel_task_helper import ParallelTaskHelper
def clearcal(
vis=None,
field=None,
spw=None,
intent=None,
addmodel=None,
):
casalog.origin('clearcal')
if ParallelDataHelper.isMMSAndNotServer(vis):
helper = ParallelTaskHelper('clearcal', locals())
helper.go()
return
tblocal = table()
cblocal = calibrater()
mslocal = ms()
doinit = False
if (type(vis) == str) & os.path.exists(vis):
tblocal.open(vis)
doinit = tblocal.colnames().count('CORRECTED_DATA') > 0
tblocal.close()
if not doinit:
casalog.post('Need to create scratch columns; ignoring selection.')
cblocal.setvi(old=True,quiet=False);
cblocal.open(vis, addmodel=addmodel)
else:
raise Exception('Visibility data set not found - please verify the name')
if doinit:
cblocal.selectvis(field=field, spw=spw, intent=intent)
cblocal.initcalset(1)
cblocal.close()
if is_python3:
vars = locals( )
param_names = clearcal.__code__.co_varnames[:clearcal.__code__.co_argcount]
param_vals = [vars[p] for p in param_names]
else:
param_names = clearcal.__code__.co_varnames[:clearcal.__code__.co_argcount]
param_vals = [eval(p) for p in param_names]
casalog.post('Updating the history in the output', 'DEBUG1')
write_history(mslocal, vis, 'clearcal', param_names,
param_vals, casalog)