from __future__ import absolute_import
import numpy.random as random
from casatasks.private.casa_transition import *
from casatools import calibrater, table, ms
from casatasks import casalog, applycal
from .mstools import write_history
from applycal import applycal
from mstools import write_history
(cb,myms) = gentools(['cb','ms'])
def sdcal(infile=None, calmode='tsys', fraction='10%', noff=-1,
width=0.5, elongated=False, applytable='',interp='', spwmap={},
outfile='', overwrite=False, field='', spw='', scan='',intent=''):
""" Externally specify calibration solutions of various types
handle_composite_mode(locals())
raise UserWarning("Scan input must be ''(=all) in calmode='tsys'.")
raise UserWarning("Spw input must be ''(=all) in calmode='tsys'.")
if isinstance(infile,str) and os.path.exists(infile):
addcorr = calmode == 'apply'
cb.open(filename=infile,compress=False,addcorr=addcorr,addmodel=False)
cb.selectvis(spw=spw, scan=scan, field=field)
raise Exception('Infile data set not found - please verify the name')
if not isinstance(calmode,str):
raise Exception("Calmode must be a string")
if calmode.lower() not in ['tsys', 'ps', 'otfraster', 'otf', 'apply']:
raise Exception("Calmode must be either 'ps' or 'otfraster' or 'otf' or 'tsys' or 'apply'.")
if (not overwrite) and os.path.exists(outfile):
raise RuntimeError("overwrite is False and output file exists: {}".format(outfile))
if isinstance(applytable, str):
_table_list = [applytable]
if isinstance(applytable, list) or isinstance(applytable, numpy.ndarray):
if len(_table_list) == 0:
raise Exception('Applytable name must be specified.')
for table in _table_list:
raise Exception('Applytable name must be specified.')
if not os.path.exists(table):
raise Exception("Table doesn't exist: {}".format(table))