Source
xxxxxxxxxx
# antenna=selection_ids['baseline'],
# sd task for imaging
import os
import re
import shutil
import numpy
from casatasks import casalog
from casatools import image, ms, msmetadata, quanta, table
from . import sdbeamutil, sdutil
from .cleanhelper import cleanhelper
sdtask_decorator .
def sdimaging(infiles, outfile, overwrite, field, spw, antenna, scan, intent,
mode, nchan, start, width, veltype, outframe,
gridfunction, convsupport, truncate, gwidth, jwidth,
imsize, cell, phasecenter, projection, ephemsrcname,
pointingcolumn, restfreq, stokes, minweight, brightnessunit, clipminmax):
with sdimaging_worker(**locals()) as worker:
worker.initialize()
worker.execute()
worker.finalize()
def is_string_type(val):
"""Return True if the argument is string type."""
return type(val) in [str, numpy.string_]
def smart_remove(path):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
class sdimaging_worker(sdutil.sdtask_template_imaging):
def __init__(self, **kwargs):
super(sdimaging_worker, self).__init__(**kwargs)
self.imager_param = {}
self.sorted_idx = []
self.image_unit = ""
def __exit__(self, exc_type, exc_val, exc_tb):
self.__del__()
if exc_type:
return False
else:
return True
def parameter_check(self):
# outfile check
sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outfile,
'im',
self.overwrite)
sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outfile + '.weight',
'im',
self.overwrite)
# fix spw
if type(self.spw) == str:
self.spw = self.__format_spw_string(self.spw)
# check unit of start and width
# fix default
if self.mode == 'channel':
if self.start == '':
self.start = 0
if self.width == '':
self.width = 1
else:
if self.start == 0:
self.start = ''
if self.width == 1:
self.width = ''
# fix unit
if self.mode == 'frequency':
myunit = 'Hz'
elif self.mode == 'velocity':
myunit = 'km/s'
else: # channel
myunit = ''
for name in ['start', 'width']:
param = getattr(self, name)
new_param = self.__format_quantum_unit(param, myunit)
if new_param is None:
raise ValueError("Invalid unit for %s in mode %s: %s" %
(name, self.mode, param))
setattr(self, name, new_param)