################################################
# v1.0: 2012.10.05, U.R.V.
################################################
from __future__ import absolute_import
from __future__ import print_function
#from refimagerhelper import PySynthesisImager
#from refimagerhelper import PyParallelContSynthesisImager,PyParallelCubeSynthesisImager
#from refimagerhelper import ImagerParameters
from imagerhelpers.imager_base import PySynthesisImager
from imagerhelpers.imager_parallel_continuum import PyParallelContSynthesisImager
from imagerhelpers.imager_parallel_cube import PyParallelCubeSynthesisImager
from imagerhelpers.input_parameters import ImagerParameters
# get is_CASA6 and is_python3
from casatasks.private.casa_transition import *
from casatasks import casalog
from .imagerhelpers.imager_base import PySynthesisImager
from .imagerhelpers.imager_parallel_continuum import PyParallelContSynthesisImager
from .imagerhelpers.imager_parallel_cube import PyParallelCubeSynthesisImager
from .imagerhelpers.input_parameters import ImagerParameters
#from refimagerhelper import PySynthesisImager
#from refimagerhelper import PyParallelContSynthesisImager,PyParallelCubeSynthesisImager
#from refimagerhelper import ImagerParameters
from imagerhelpers.imager_base import PySynthesisImager
from imagerhelpers.imager_parallel_continuum import PyParallelContSynthesisImager
from imagerhelpers.imager_parallel_cube import PyParallelCubeSynthesisImager
from imagerhelpers.input_parameters import ImagerParameters
####### Gridding parameters
### Move these checks elsewhere ?
inpparams=locals().copy()
###now deal with parameters which are not the same name
inpparams['msname']= inpparams.pop('vis')
inpparams['timestr']= inpparams.pop('timerange')
inpparams['uvdist']= inpparams.pop('uvrange')
inpparams['obs']= inpparams.pop('observation')
inpparams['state']= inpparams.pop('intent')
inpparams['loopgain']=inpparams.pop('gain')
inpparams['scalebias']=inpparams.pop('smallscalebias')
inpparams['specmode']='mfs'
# if specmode=='mfs' and nterms==1 and deconvolver == "mtmfs":
# casalog.post( "The MTMFS deconvolution algorithm (deconvolver='mtmfs') needs nterms>1.Please set nterms=2 (or more). ", "WARN", "task_tclean" )
if specmode!='mfs' and deconvolver=="mtmfs":
casalog.post( "The MSMFS algorithm (deconvolver='mtmfs') applies only to specmode='mfs'.", "WARN", "task_tclean" )
#####################################################
#### Construct ImagerParameters object
#####################################################
# Put all parameters into dictionaries and check them.
##make a dictionary of parameters that ImagerParameters take
defparm=dict(zip(ImagerParameters.__init__.__func__.__code__.co_varnames[1:], ImagerParameters.__init__.__defaults__))
###assign values to the ones passed to tclean and if not defined yet in tclean...
###assign them the default value of the constructor
bparm={k: inpparams[k] if k in inpparams else defparm[k] for k in ImagerParameters.__init__.__func__.__code__.co_varnames[1:-1]}
defparm=dict(list(zip(ImagerParameters.__init__.__code__.co_varnames[1:], ImagerParameters.__init__.__defaults__)))
###assign values to the ones passed to tclean and if not defined yet in tclean...
###assign them the default value of the constructor
#bparm={k: inpparams[k] if inpparams.has_key(k) else defparm[k] for k in ImagerParameters.__init__.__code__.co_varnames[1:-1]}
bparm={k: inpparams[k] if k in inpparams else defparm[k] for k in ImagerParameters.__init__.__code__.co_varnames[1:-1]}
defparm=dict(zip(ImagerParameters.__init__.__func__.__code__.co_varnames[1:], ImagerParameters.__init__.__defaults__))
###assign values to the ones passed to tclean and if not defined yet in tclean...
###assign them the default value of the constructor
bparm={k: inpparams[k] if k in inpparams else defparm[k] for k in ImagerParameters.__init__.__func__.__code__.co_varnames[1:-1]}
###default mosweight=True is tripping other gridders as they are not
###expecting it to be true
if(bparm['mosweight']==True and bparm['gridder'].find("mosaic") == -1):
paramList=ImagerParameters(**bparm)
if usemask=='auto-thresh' or usemask=='auto-thresh2':
casalog.post(usemask+" is deprecated, will be removed in CASA 5.4. It is recommended to use auto-multithresh instead", "WARN")