Source
dd = abs((float(ix) - halfwx) * tand - (float(iy) - halfwy)) # for CAS-9434
# sd task for image processing (fft_mask or model)
import os
import time
import numpy
import numpy.fft as npfft
from casatasks import casalog
from casatools import ctsys
from casatools import image as iatool
from casatools import quanta
from . import sdutil
def create_4d_image(infile, outfile):
ia = iatool()
ia.open(infile)
image_shape = ia.shape()
try:
if len(image_shape) < 4:
# add degenerate axes
cs = ia.coordsys()
axistypes = cs.axiscoordinatetypes()
no_stokes = 'Stokes' not in axistypes
no_spectral = 'Spectral' not in axistypes
stokes_axis = 'I' if no_stokes else ''
outimage = ia.adddegaxes(outfile=outfile, spectral=no_spectral,
stokes=stokes_axis)
else:
# generage complete copy of input image using subimage
outimage = ia.subimage(outfile=outfile)
finally:
if len(image_shape) < 4:
cs.done()
ia.close()
return outimage
sdtask_decorator .
def sdfixscan(infiles, mode, numpoly, beamsize, smoothsize, direction, maskwidth,
tmax, tmin, outfile, overwrite):
with sdfixscan_worker(**locals()) as worker:
worker.initialize()
worker.execute()
worker.finalize()
class sdfixscan_worker(sdutil.sdtask_interface):
def __init__(self, **kwargs):
super(sdfixscan_worker, self).__init__(**kwargs)
def __del__(self, base=sdutil.sdtask_interface):
# cleanup method must be called when the instance is
# deleted
self.cleanup()
super(sdfixscan_worker, self).__del__()
def initialize(self):
self.parameter_check()
# temporary filename
tmpstr = time.ctime().replace(' ', '_').replace(':', '_')
self.tmpmskname = 'masked.' + tmpstr + '.im'
self.tmpconvname = 'convolve2d.' + tmpstr + '.im'
self.tmppolyname = 'polyfit.' + tmpstr + '.im'
# set tempolary filename
self.tmprealname = []
self.tmpimagname = []
self.image = None
self.convimage = None
self.polyimage = None
self.imageorg = None
self.realimage = None
self.imagimage = None
if type(self.infiles) == str:
self.tmprealname.append('fft.' + tmpstr + '.real..0.im')
self.tmpimagname.append('fft.' + tmpstr + '.imag.0.im')
else:
for i in range(len(self.infiles)):
self.tmprealname.append('fft.%s.%s.real.im' % (tmpstr, i))
self.tmpimagname.append('fft.%s.%s.imag.im' % (tmpstr, i))
# default output filename
if self.outfile == '':
self.outfile = 'sdfixscan.out.im'
casalog.post('outfile=%s' % self.outfile)
# threshold