from __future__ import absolute_import
import os
import sys
import shutil
from casatasks.private.casa_transition import *
if is_CASA6:
from casatools import image, coordsys, quanta
from casatasks import casalog
from .ialib import write_image_history
else:
from taskinit import *
from ialib import write_image_history
image = iatool
coordsys = cstool
quanta = qatool
def imregrid(
imagename, template, output, asvelocity, axes, shape,
interpolation, decimate, replicate, overwrite
):
_myia = None
outia = None
csys = None
try:
casalog.origin('imregrid')
if hasattr(template, 'lower') and not template.lower() == "get":
if len(output) < 1:
output = imagename + '.regridded'
casalog.post("output was not specified - defaulting to\n\t"
+ output, 'INFO')
_myia = image()
_myia.dohistory(False)
if not isinstance(template, dict):
if template.lower() == 'get':
_myia.open(imagename)
csys = _myia.coordsys()
shape = _myia.shape()
_myia.done()
return {'csys': csys.torecord(), 'shap': shape}
elif template.upper() in (
'J2000', 'B1950', 'B1950_VLA', 'GALACTIC',
'HADEC', 'AZEL', 'AZELSW', 'AZELNE', 'ECLIPTIC',
'MECLIPTIC', 'TECLIPTIC', 'SUPERGAL'
):
outia = _imregrid_to_new_ref_frame(
_myia, imagename, template, output, axes,
shape, overwrite, interpolation, decimate
)
try:
param_names = imregrid.__code__.co_varnames[:imregrid.__code__.co_argcount]
if is_python3:
vars = locals( )
param_vals = [vars[p] for p in param_names]
else:
param_vals = [eval(p) for p in param_names]
write_image_history(
outia, sys._getframe().f_code.co_name,
param_names, param_vals, casalog
)
except Exception as instance:
casalog.post(
"*** Error \'%s\' updating HISTORY" % (instance), 'WARN'
)
outia.done()
return
else:
if (
not os.path.isdir(template)
or not os.access(template, os.R_OK)
):
raise TypeError('Cannot read template image %s' % template)
template_ia = image()
template_ia.open(template)
template_csys = template_ia.coordsys()
image_ia = image()
image_ia.open(imagename)
image_csys = image_ia.coordsys()
tempshape = template_ia.shape()
imshape = image_ia.shape()
axestoregrid = axes
if (axes[0] < 0):
axestoregrid = []