Source code for pipeline.hif.cli.gotasks.hif_makeimlist

##################### generated by xml-casa (v2) from hif_makeimlist.xml ############
##################### a986d92169339078a04432f0d8abc957 ##############################
from __future__ import absolute_import
from casashell.private.stack_manip import find_local as __sf__
from casashell.private.stack_manip import find_frame as _find_frame
from casatools.typecheck import validator as _pc
from casatools.coercetype import coerce as _coerce
from pipeline.hif.cli import hif_makeimlist as _hif_makeimlist_t
from collections import OrderedDict
import numpy
import sys
import os

import shutil

[docs]def static_var(varname, value): def decorate(func): setattr(func, varname, value) return func return decorate
class _hif_makeimlist: """ hif_makeimlist ---- Compute list of clean images to be produced Create a a list of images to be cleaned. Generate a list of images to be cleaned. By default the list will include one image per science target per spw. Calibrator targets can be selected by setting appropriate values for intent. By default the output image cell size is set to the minimum cell size consistent with the UV coverage. By default the image size in pixels is set to values determined by the cell size and the single dish beam size. If a calibrator is being imaged (intents 'PHASE', 'BANDPASS', 'FLUX' or 'AMPLITUDE') then the image dimensions are limited to 'calmaxpix' pixels. By default science target images are cubes and calibrator target images are single channel. Science target images may be mosaics or single fields. Output results -- If pipeline mode is 'getinputs' then None is returned. Otherwise the results object for the pipeline task is returned. --------- parameter descriptions --------------------------------------------- vis The list of input MeasurementSets. Defaults to the list of MeasurementSets specified in the h_init or hif_importdata task. "": use all MeasurementSets in the context Examples: 'ngc5921.ms', ['ngc5921a.ms', ngc5921b.ms', 'ngc5921c.ms'] imagename Prefix for output image names, "" for automatic. intent Select intents for which associated fields will be imaged. Possible choices are PHASE, BANDPASS, AMPLITUDE, CHECK and TARGET or combinations thereof. Examples: 'PHASE,BANDPASS', 'TARGET' field Select fields to image. Use field name(s) NOT id(s). Mosaics are assumed to have common source / field names. If intent is specified only fields with data matching the intent will be selected. The fields will be selected from MeasurementSets in "vis". "" Fields matching intent, one image per target source. spw Select spectral windows to image. "": Images will be computed for all science spectral windows. contfile Name of file with frequency ranges to use for continuum images. linesfile Name of file with line frequency ranges to exclude for continuum images. uvrange Select a set of uv ranges to image. "": All uv data is included Examples: '0~1000klambda', ['0~100klambda', 100~1000klambda] specmode Frequency imaging mode, 'mfs', 'cont', 'cube', 'repBW'. '' defaults to 'cube' if intent parameter includes 'TARGET' otherwise 'mfs'. specmode='mfs' produce one image per source and spw specmode='cont' produce one image per source and aggregate over all specified spws specmode='cube' produce an LSRK frequency cube, channels are specified in frequency specmode='repBW' produce an LSRK frequency cube at representative channel width outframe velocity frame of output image (LSRK, '' for automatic) hm_imsize Image X and Y size in pixels or PB level for single fields. The explicit sizes must be even and divisible by 2,3,5,7 only. The default values are derived as follows: 1. Determine phase center and spread of field centers around it. 2. Set the size of the image to cover the spread of field centers plus a border of width 0.75 * beam radius, to first null. 3. Divide X and Y extents by cell size to arrive at the number of pixels required. The PB level setting for single fields leads to an imsize extending to the specified level plus 5% padding in all directions. Examples: '0.3pb', [120, 120] hm_cell Image X and Y cell sizes. "" computes the cell size based on the UV coverage of all the fields to be imaged and uses a 5 pix per beam sampling. The pix per beam specification ('<number>ppb') uses the above default cell size ('5ppb') and scales it accordingly. The cells can also be specified as explicit measures. Examples: '3ppb', ['0.5arcsec', '0.5arcsec'] calmaxpix Maximum image X or Y size in pixels if a calibrator is being imaged ('PHASE', 'BANDPASS', 'AMPLITUDE' or 'FLUX' intent). phasecenter Direction measure or field id of the image center. The default phase center is set to the mean of the field directions of all fields that are to be image together. Examples: 'J2000 19h30m00 -40d00m00', 0 nchan Total number of channels in the output image(s) -1 selects enough channels to cover the data selected by spw consistent with start and width. start Start of image frequency axis as frequency or velocity. "" selects start frequency automatically. width Output channel width. Difference in frequency between 2 selected channels for frequency mode images. 'pilotimage' for 15 MHz / 8 channel heuristic nbins Channel binning factors for each spw. Format: 'spw1:nb1,spw2:nb2,...' with optional wildcards: '*:nb' Examples: '9:2,11:4,13:2,15:8', '*:2' robust Briggs robustness parameter Values range from -2.0 (uniform) to 2.0 (natural) uvtaper uv-taper on outer baselines clearlist Clear any existing target list per_eb Make an image target per EB calcsb Force (re-)calculation of sensitivities and beams parallel Use MPI cluster where possible pipelinemode The pipeline operating mode. In 'automatic' mode the pipeline determines the values of all context defined pipeline inputs automatically. In 'interactive' mode the user can set the pipeline context defined parameters manually. In 'getinputs' mode the user can check the settings of all pipeline parameters without running the task. dryrun Run the task (False) or just display the command (True) acceptresults Add the results of the task to the pipeline context (True) or reject them (False). --------- examples ----------------------------------------------------------- 1. Make a list of science target images to be cleaned, one image per science spw. hif_makeimlist() 2. Make a list of PHASE and BANDPASS calibrator targets to be imaged, one image per science spw. hif_makeimlist(intent='PHASE,BANDPASS') 3. Make a list of PHASE calibrator images observed in spw 1, images limited to 50 pixels on a side. hif_makeimlist(intent='PHASE',spw='1',calmaxpix=50) """ _info_group_ = """pipeline""" _info_desc_ = """Compute list of clean images to be produced""" __schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'imagename': {'type': 'cStr', 'coerce': _coerce.to_str}, 'intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'field': {'type': 'cStr', 'coerce': _coerce.to_str}, 'spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'contfile': {'type': 'cStr', 'coerce': _coerce.to_str}, 'linesfile': {'type': 'cStr', 'coerce': _coerce.to_str}, 'uvrange': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}]}, 'specmode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'cont', 'repBW', 'cube', 'mfs', '' ]}, 'outframe': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ '', 'LSRK' ]}, 'hm_imsize': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'hm_cell': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'calmaxpix': {'type': 'cInt'}, 'phasecenter': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'nchan': {'type': 'cInt'}, 'start': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'width': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'nbins': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'robust': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'uvtaper': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'clearlist': {'type': 'cBool'}, 'per_eb': {'type': 'cBool'}, 'calcsb': {'type': 'cBool'}, 'parallel': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'true', 'false' ]}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}} def __init__(self): self.__stdout = None self.__stderr = None self.__root_frame_ = None def __globals_(self): if self.__root_frame_ is None: self.__root_frame_ = _find_frame( ) assert self.__root_frame_ is not None, "could not find CASAshell global frame" return self.__root_frame_ def __to_string_(self,value): if type(value) is str: return "'%s'" % value else: return str(value) def __validate_(self,doc,schema): return _pc.validate(doc,schema) def __do_inp_output(self,param_prefix,description_str,formatting_chars): out = self.__stdout or sys.stdout description = description_str.split( ) prefix_width = 23 + 16 + 4 output = [ ] addon = '' first_addon = True while len(description) > 0: ## starting a new line..................................................................... if len(output) == 0: ## for first line add parameter information............................................ if len(param_prefix)-formatting_chars > prefix_width - 1: output.append(param_prefix) continue addon = param_prefix + ' #' first_addon = True addon_formatting = formatting_chars else: ## for subsequent lines space over prefix width........................................ addon = (' ' * prefix_width) + '#' first_addon = False addon_formatting = 0 ## if first word of description puts us over the screen width, bail........................ if len(addon + description[0]) - addon_formatting + 1 > self.term_width: ## if we're doing the first line make sure it's output................................. if first_addon: output.append(addon) break while len(description) > 0: ## if the next description word puts us over break for the next line................... if len(addon + description[0]) - addon_formatting + 1 > self.term_width: break addon = addon + ' ' + description[0] description.pop(0) output.append(addon) out.write('\n'.join(output) + '\n') #--------- return nonsubparam values ---------------------------------------------- def __calmaxpix_dflt( self, glb ): return int(300) def __calmaxpix( self, glb ): if 'calmaxpix' in glb: return glb['calmaxpix'] return int(300) def __parallel_dflt( self, glb ): return 'automatic' def __parallel( self, glb ): if 'parallel' in glb: return glb['parallel'] return 'automatic' def __calcsb_dflt( self, glb ): return False def __calcsb( self, glb ): if 'calcsb' in glb: return glb['calcsb'] return False def __pipelinemode_dflt( self, glb ): return 'automatic' def __pipelinemode( self, glb ): if 'pipelinemode' in glb: return glb['pipelinemode'] return 'automatic' def __specmode_dflt( self, glb ): return '' def __specmode( self, glb ): if 'specmode' in glb: return glb['specmode'] return '' #--------- return inp/go default -------------------------------------------------- def __nbins_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" return None def __dryrun_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(False) return None def __field_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __intent_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __nchan_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return int(-1) if self.__pipelinemode( glb ) == "getinputs": return int(-1) return None def __per_eb_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(False) return None def __imagename_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __linesfile_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __vis_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] return None def __acceptresults_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(True) return None def __uvtaper_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] return None def __contfile_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __robust_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return float(-999.0) return None def __hm_cell_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] return None def __outframe_dflt( self, glb ): if self.__specmode( glb ) == "cube": return "" return None def __uvrange_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __phasecenter_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __hm_imsize_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] return None def __start_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __width_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" return None def __spw_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __clearlist_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(True) return None #--------- return subparam values ------------------------------------------------- def __vis( self, glb ): if 'vis' in glb: return glb['vis'] dflt = self.__vis_dflt( glb ) if dflt is not None: return dflt return [ ] def __imagename( self, glb ): if 'imagename' in glb: return glb['imagename'] dflt = self.__imagename_dflt( glb ) if dflt is not None: return dflt return '' def __intent( self, glb ): if 'intent' in glb: return glb['intent'] dflt = self.__intent_dflt( glb ) if dflt is not None: return dflt return 'TARGET' def __field( self, glb ): if 'field' in glb: return glb['field'] dflt = self.__field_dflt( glb ) if dflt is not None: return dflt return '' def __spw( self, glb ): if 'spw' in glb: return glb['spw'] dflt = self.__spw_dflt( glb ) if dflt is not None: return dflt return '' def __contfile( self, glb ): if 'contfile' in glb: return glb['contfile'] dflt = self.__contfile_dflt( glb ) if dflt is not None: return dflt return '' def __linesfile( self, glb ): if 'linesfile' in glb: return glb['linesfile'] dflt = self.__linesfile_dflt( glb ) if dflt is not None: return dflt return '' def __uvrange( self, glb ): if 'uvrange' in glb: return glb['uvrange'] dflt = self.__uvrange_dflt( glb ) if dflt is not None: return dflt return '' def __outframe( self, glb ): if 'outframe' in glb: return glb['outframe'] dflt = self.__outframe_dflt( glb ) if dflt is not None: return dflt return '' def __hm_imsize( self, glb ): if 'hm_imsize' in glb: return glb['hm_imsize'] dflt = self.__hm_imsize_dflt( glb ) if dflt is not None: return dflt return '' def __hm_cell( self, glb ): if 'hm_cell' in glb: return glb['hm_cell'] dflt = self.__hm_cell_dflt( glb ) if dflt is not None: return dflt return [ ] def __calmaxpix( self, glb ): if 'calmaxpix' in glb: return glb['calmaxpix'] dflt = self.__calmaxpix_dflt( glb ) if dflt is not None: return dflt return int(300) def __phasecenter( self, glb ): if 'phasecenter' in glb: return glb['phasecenter'] dflt = self.__phasecenter_dflt( glb ) if dflt is not None: return dflt return '' def __nchan( self, glb ): if 'nchan' in glb: return glb['nchan'] dflt = self.__nchan_dflt( glb ) if dflt is not None: return dflt return int(-1) def __start( self, glb ): if 'start' in glb: return glb['start'] dflt = self.__start_dflt( glb ) if dflt is not None: return dflt return '' def __width( self, glb ): if 'width' in glb: return glb['width'] dflt = self.__width_dflt( glb ) if dflt is not None: return dflt return '' def __nbins( self, glb ): if 'nbins' in glb: return glb['nbins'] dflt = self.__nbins_dflt( glb ) if dflt is not None: return dflt return '' def __robust( self, glb ): if 'robust' in glb: return glb['robust'] dflt = self.__robust_dflt( glb ) if dflt is not None: return dflt return float(-999.0) def __uvtaper( self, glb ): if 'uvtaper' in glb: return glb['uvtaper'] dflt = self.__uvtaper_dflt( glb ) if dflt is not None: return dflt return [ ] def __clearlist( self, glb ): if 'clearlist' in glb: return glb['clearlist'] dflt = self.__clearlist_dflt( glb ) if dflt is not None: return dflt return True def __per_eb( self, glb ): if 'per_eb' in glb: return glb['per_eb'] dflt = self.__per_eb_dflt( glb ) if dflt is not None: return dflt return False def __dryrun( self, glb ): if 'dryrun' in glb: return glb['dryrun'] dflt = self.__dryrun_dflt( glb ) if dflt is not None: return dflt return False def __acceptresults( self, glb ): if 'acceptresults' in glb: return glb['acceptresults'] dflt = self.__acceptresults_dflt( glb ) if dflt is not None: return dflt return True #--------- subparam inp output ---------------------------------------------------- def __vis_inp(self): if self.__vis_dflt( self.__globals_( ) ) is not None: description = 'List of input MeasurementSets' value = self.__vis( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'vis': value},{'vis': self.__schema['vis']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('vis',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __imagename_inp(self): if self.__imagename_dflt( self.__globals_( ) ) is not None: description = 'Prefix for output image names, "" for automatic.' value = self.__imagename( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'imagename': value},{'imagename': self.__schema['imagename']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('imagename',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __intent_inp(self): if self.__intent_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection intents' value = self.__intent( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'intent': value},{'intent': self.__schema['intent']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('intent',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __field_inp(self): if self.__field_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection field names or ids, "" for all' value = self.__field( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'field': value},{'field': self.__schema['field']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('field',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __spw_inp(self): if self.__spw_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection spectral window/channels, "" for automatic' value = self.__spw( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'spw': value},{'spw': self.__schema['spw']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('spw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __contfile_inp(self): if self.__contfile_dflt( self.__globals_( ) ) is not None: description = 'Name of file with frequency ranges to use for continuum images.' value = self.__contfile( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'contfile': value},{'contfile': self.__schema['contfile']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('contfile',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __linesfile_inp(self): if self.__linesfile_dflt( self.__globals_( ) ) is not None: description = 'Name of file with line frequency ranges to exclude for continuum images.' value = self.__linesfile( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'linesfile': value},{'linesfile': self.__schema['linesfile']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('linesfile',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __uvrange_inp(self): if self.__uvrange_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection uv ranges, "" for all.' value = self.__uvrange( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'uvrange': value},{'uvrange': self.__schema['uvrange']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('uvrange',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __specmode_inp(self): description = 'Spectral gridding type (mfs, cont, cube, repBW, '' for automatic defaults)' value = self.__specmode( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'specmode': value},{'specmode': self.__schema['specmode']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('specmode',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __outframe_inp(self): if self.__outframe_dflt( self.__globals_( ) ) is not None: description = 'velocity frame of output image (LSRK, \'\' for automatic)' value = self.__outframe( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'outframe': value},{'outframe': self.__schema['outframe']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('outframe',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_imsize_inp(self): if self.__hm_imsize_dflt( self.__globals_( ) ) is not None: description = 'Image X and Y size(s) in pixels or PB level (single fields), "" for automatic. Single value same for both. "<number>pb" for PB level.' value = self.__hm_imsize( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_imsize': value},{'hm_imsize': self.__schema['hm_imsize']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('hm_imsize',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_cell_inp(self): if self.__hm_cell_dflt( self.__globals_( ) ) is not None: description = 'Image X and Y cell size(s) with units or pixels per beam, "" for automatic. Single value same for both. "<number>ppb" for pixels per beam.' value = self.__hm_cell( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_cell': value},{'hm_cell': self.__schema['hm_cell']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('hm_cell',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __calmaxpix_inp(self): if self.__calmaxpix_dflt( self.__globals_( ) ) is not None: description = 'Maximum X and Y size of calibrator images in pixels' value = self.__calmaxpix( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'calmaxpix': value},{'calmaxpix': self.__schema['calmaxpix']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('calmaxpix',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __phasecenter_inp(self): if self.__phasecenter_dflt( self.__globals_( ) ) is not None: description = 'Image center (direction or field index, "" for automatic)' value = self.__phasecenter( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'phasecenter': value},{'phasecenter': self.__schema['phasecenter']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('phasecenter',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __nchan_inp(self): if self.__nchan_dflt( self.__globals_( ) ) is not None: description = 'Number of channels, -1 = all' value = self.__nchan( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'nchan': value},{'nchan': self.__schema['nchan']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('nchan',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __start_inp(self): if self.__start_dflt( self.__globals_( ) ) is not None: description = 'Channel start, "" for automatic' value = self.__start( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'start': value},{'start': self.__schema['start']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('start',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __width_inp(self): if self.__width_dflt( self.__globals_( ) ) is not None: description = 'Channel width, "" for automatic.' value = self.__width( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'width': value},{'width': self.__schema['width']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('width',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __nbins_inp(self): if self.__nbins_dflt( self.__globals_( ) ) is not None: description = 'Channel binning factors per spw, "" for automatic.' value = self.__nbins( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'nbins': value},{'nbins': self.__schema['nbins']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('nbins',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __robust_inp(self): if self.__robust_dflt( self.__globals_( ) ) is not None: description = 'Briggs robustness parameter' value = self.__robust( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'robust': value},{'robust': self.__schema['robust']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('robust',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __uvtaper_inp(self): if self.__uvtaper_dflt( self.__globals_( ) ) is not None: description = 'uv-taper on outer baselines' value = self.__uvtaper( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'uvtaper': value},{'uvtaper': self.__schema['uvtaper']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('uvtaper',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __clearlist_inp(self): if self.__clearlist_dflt( self.__globals_( ) ) is not None: description = 'Clear any existing target list' value = self.__clearlist( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'clearlist': value},{'clearlist': self.__schema['clearlist']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('clearlist',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __per_eb_inp(self): if self.__per_eb_dflt( self.__globals_( ) ) is not None: description = 'Make an image target per EB' value = self.__per_eb( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'per_eb': value},{'per_eb': self.__schema['per_eb']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('per_eb',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __calcsb_inp(self): description = 'Force (re-)calculation of sensitivities and beams' value = self.__calcsb( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'calcsb': value},{'calcsb': self.__schema['calcsb']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-16.16s = %s%-23s%s' % ('calcsb',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __parallel_inp(self): description = 'Use MPI cluster where possible' value = self.__parallel( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'parallel': value},{'parallel': self.__schema['parallel']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-16.16s = %s%-23s%s' % ('parallel',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __pipelinemode_inp(self): description = 'The pipeline operating mode' value = self.__pipelinemode( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'pipelinemode': value},{'pipelinemode': self.__schema['pipelinemode']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('pipelinemode',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __dryrun_inp(self): if self.__dryrun_dflt( self.__globals_( ) ) is not None: description = 'Run the task (False) or just display the command (True)' value = self.__dryrun( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'dryrun': value},{'dryrun': self.__schema['dryrun']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('dryrun',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __acceptresults_inp(self): if self.__acceptresults_dflt( self.__globals_( ) ) is not None: description = 'Add the results to the pipeline context' value = self.__acceptresults( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'acceptresults': value},{'acceptresults': self.__schema['acceptresults']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('acceptresults',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) #--------- global default implementation------------------------------------------- @static_var('state', __sf__('casa_inp_go_state')) def set_global_defaults(self): self.set_global_defaults.state['last'] = self glb = self.__globals_( ) if 'nbins' in glb: del glb['nbins'] if 'dryrun' in glb: del glb['dryrun'] if 'field' in glb: del glb['field'] if 'pipelinemode' in glb: del glb['pipelinemode'] if 'intent' in glb: del glb['intent'] if 'nchan' in glb: del glb['nchan'] if 'per_eb' in glb: del glb['per_eb'] if 'imagename' in glb: del glb['imagename'] if 'linesfile' in glb: del glb['linesfile'] if 'vis' in glb: del glb['vis'] if 'acceptresults' in glb: del glb['acceptresults'] if 'calcsb' in glb: del glb['calcsb'] if 'specmode' in glb: del glb['specmode'] if 'uvtaper' in glb: del glb['uvtaper'] if 'contfile' in glb: del glb['contfile'] if 'robust' in glb: del glb['robust'] if 'hm_cell' in glb: del glb['hm_cell'] if 'outframe' in glb: del glb['outframe'] if 'uvrange' in glb: del glb['uvrange'] if 'phasecenter' in glb: del glb['phasecenter'] if 'hm_imsize' in glb: del glb['hm_imsize'] if 'start' in glb: del glb['start'] if 'width' in glb: del glb['width'] if 'calmaxpix' in glb: del glb['calmaxpix'] if 'spw' in glb: del glb['spw'] if 'parallel' in glb: del glb['parallel'] if 'clearlist' in glb: del glb['clearlist'] #--------- inp function ----------------------------------------------------------- def inp(self): print("# hif_makeimlist -- %s" % self._info_desc_) self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24)) self.__vis_inp( ) self.__imagename_inp( ) self.__intent_inp( ) self.__field_inp( ) self.__spw_inp( ) self.__contfile_inp( ) self.__linesfile_inp( ) self.__uvrange_inp( ) self.__specmode_inp( ) self.__outframe_inp( ) self.__hm_imsize_inp( ) self.__hm_cell_inp( ) self.__calmaxpix_inp( ) self.__phasecenter_inp( ) self.__nchan_inp( ) self.__start_inp( ) self.__width_inp( ) self.__nbins_inp( ) self.__robust_inp( ) self.__uvtaper_inp( ) self.__clearlist_inp( ) self.__per_eb_inp( ) self.__calcsb_inp( ) self.__parallel_inp( ) self.__pipelinemode_inp( ) self.__dryrun_inp( ) self.__acceptresults_inp( ) #--------- tget function ---------------------------------------------------------- @static_var('state', __sf__('casa_inp_go_state')) def tget(self,file=None): from casashell.private.stack_manip import find_frame from runpy import run_path filename = None if file is None: if os.path.isfile("hif_makeimlist.last"): filename = "hif_makeimlist.last" elif isinstance(file, str): if os.path.isfile(file): filename = file if filename is not None: glob = find_frame( ) newglob = run_path( filename, init_globals={ } ) for i in newglob: glob[i] = newglob[i] self.tget.state['last'] = self else: print("could not find last file, setting defaults instead...") self.set_global_defaults( ) def __call__( self, vis=None, imagename=None, intent=None, field=None, spw=None, contfile=None, linesfile=None, uvrange=None, specmode=None, outframe=None, hm_imsize=None, hm_cell=None, calmaxpix=None, phasecenter=None, nchan=None, start=None, width=None, nbins=None, robust=None, uvtaper=None, clearlist=None, per_eb=None, calcsb=None, parallel=None, pipelinemode=None, dryrun=None, acceptresults=None ): def noobj(s): if s.startswith('<') and s.endswith('>'): return "None" else: return s _prefile = os.path.realpath('hif_makeimlist.pre') _postfile = os.path.realpath('hif_makeimlist.last') _return_result_ = None _arguments = [vis,imagename,intent,field,spw,contfile,linesfile,uvrange,specmode,outframe,hm_imsize,hm_cell,calmaxpix,phasecenter,nchan,start,width,nbins,robust,uvtaper,clearlist,per_eb,calcsb,parallel,pipelinemode,dryrun,acceptresults] _invocation_parameters = OrderedDict( ) if any(map(lambda x: x is not None,_arguments)): # invoke python style # set the non sub-parameters that are not None local_global = { } if specmode is not None: local_global['specmode'] = specmode if calcsb is not None: local_global['calcsb'] = calcsb if parallel is not None: local_global['parallel'] = parallel if pipelinemode is not None: local_global['pipelinemode'] = pipelinemode # the invocation parameters for the non-subparameters can now be set - this picks up those defaults _invocation_parameters['specmode'] = self.__specmode( local_global ) _invocation_parameters['calcsb'] = self.__calcsb( local_global ) _invocation_parameters['parallel'] = self.__parallel( local_global ) _invocation_parameters['pipelinemode'] = self.__pipelinemode( local_global ) # the sub-parameters can then be set. Use the supplied value if not None, else the function, which gets the appropriate default _invocation_parameters['vis'] = self.__vis( _invocation_parameters ) if vis is None else vis _invocation_parameters['imagename'] = self.__imagename( _invocation_parameters ) if imagename is None else imagename _invocation_parameters['intent'] = self.__intent( _invocation_parameters ) if intent is None else intent _invocation_parameters['field'] = self.__field( _invocation_parameters ) if field is None else field _invocation_parameters['spw'] = self.__spw( _invocation_parameters ) if spw is None else spw _invocation_parameters['contfile'] = self.__contfile( _invocation_parameters ) if contfile is None else contfile _invocation_parameters['linesfile'] = self.__linesfile( _invocation_parameters ) if linesfile is None else linesfile _invocation_parameters['uvrange'] = self.__uvrange( _invocation_parameters ) if uvrange is None else uvrange _invocation_parameters['outframe'] = self.__outframe( _invocation_parameters ) if outframe is None else outframe _invocation_parameters['hm_imsize'] = self.__hm_imsize( _invocation_parameters ) if hm_imsize is None else hm_imsize _invocation_parameters['hm_cell'] = self.__hm_cell( _invocation_parameters ) if hm_cell is None else hm_cell _invocation_parameters['calmaxpix'] = self.__calmaxpix( _invocation_parameters ) if calmaxpix is None else calmaxpix _invocation_parameters['phasecenter'] = self.__phasecenter( _invocation_parameters ) if phasecenter is None else phasecenter _invocation_parameters['nchan'] = self.__nchan( _invocation_parameters ) if nchan is None else nchan _invocation_parameters['start'] = self.__start( _invocation_parameters ) if start is None else start _invocation_parameters['width'] = self.__width( _invocation_parameters ) if width is None else width _invocation_parameters['nbins'] = self.__nbins( _invocation_parameters ) if nbins is None else nbins _invocation_parameters['robust'] = self.__robust( _invocation_parameters ) if robust is None else robust _invocation_parameters['uvtaper'] = self.__uvtaper( _invocation_parameters ) if uvtaper is None else uvtaper _invocation_parameters['clearlist'] = self.__clearlist( _invocation_parameters ) if clearlist is None else clearlist _invocation_parameters['per_eb'] = self.__per_eb( _invocation_parameters ) if per_eb is None else per_eb _invocation_parameters['dryrun'] = self.__dryrun( _invocation_parameters ) if dryrun is None else dryrun _invocation_parameters['acceptresults'] = self.__acceptresults( _invocation_parameters ) if acceptresults is None else acceptresults else: # invoke with inp/go semantics _invocation_parameters['vis'] = self.__vis( self.__globals_( ) ) _invocation_parameters['imagename'] = self.__imagename( self.__globals_( ) ) _invocation_parameters['intent'] = self.__intent( self.__globals_( ) ) _invocation_parameters['field'] = self.__field( self.__globals_( ) ) _invocation_parameters['spw'] = self.__spw( self.__globals_( ) ) _invocation_parameters['contfile'] = self.__contfile( self.__globals_( ) ) _invocation_parameters['linesfile'] = self.__linesfile( self.__globals_( ) ) _invocation_parameters['uvrange'] = self.__uvrange( self.__globals_( ) ) _invocation_parameters['specmode'] = self.__specmode( self.__globals_( ) ) _invocation_parameters['outframe'] = self.__outframe( self.__globals_( ) ) _invocation_parameters['hm_imsize'] = self.__hm_imsize( self.__globals_( ) ) _invocation_parameters['hm_cell'] = self.__hm_cell( self.__globals_( ) ) _invocation_parameters['calmaxpix'] = self.__calmaxpix( self.__globals_( ) ) _invocation_parameters['phasecenter'] = self.__phasecenter( self.__globals_( ) ) _invocation_parameters['nchan'] = self.__nchan( self.__globals_( ) ) _invocation_parameters['start'] = self.__start( self.__globals_( ) ) _invocation_parameters['width'] = self.__width( self.__globals_( ) ) _invocation_parameters['nbins'] = self.__nbins( self.__globals_( ) ) _invocation_parameters['robust'] = self.__robust( self.__globals_( ) ) _invocation_parameters['uvtaper'] = self.__uvtaper( self.__globals_( ) ) _invocation_parameters['clearlist'] = self.__clearlist( self.__globals_( ) ) _invocation_parameters['per_eb'] = self.__per_eb( self.__globals_( ) ) _invocation_parameters['calcsb'] = self.__calcsb( self.__globals_( ) ) _invocation_parameters['parallel'] = self.__parallel( self.__globals_( ) ) _invocation_parameters['pipelinemode'] = self.__pipelinemode( self.__globals_( ) ) _invocation_parameters['dryrun'] = self.__dryrun( self.__globals_( ) ) _invocation_parameters['acceptresults'] = self.__acceptresults( self.__globals_( ) ) try: with open(_prefile,'w') as _f: for _i in _invocation_parameters: _f.write("%-13s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i])))) _f.write("#hif_makeimlist( ") count = 0 for _i in _invocation_parameters: _f.write("%s=%s" % (_i,noobj(repr(_invocation_parameters[_i])))) count += 1 if count < len(_invocation_parameters): _f.write(",") _f.write(" )\n") except: pass try: _return_result_ = _hif_makeimlist_t( _invocation_parameters['vis'],_invocation_parameters['imagename'],_invocation_parameters['intent'],_invocation_parameters['field'],_invocation_parameters['spw'],_invocation_parameters['contfile'],_invocation_parameters['linesfile'],_invocation_parameters['uvrange'],_invocation_parameters['specmode'],_invocation_parameters['outframe'],_invocation_parameters['hm_imsize'],_invocation_parameters['hm_cell'],_invocation_parameters['calmaxpix'],_invocation_parameters['phasecenter'],_invocation_parameters['nchan'],_invocation_parameters['start'],_invocation_parameters['width'],_invocation_parameters['nbins'],_invocation_parameters['robust'],_invocation_parameters['uvtaper'],_invocation_parameters['clearlist'],_invocation_parameters['per_eb'],_invocation_parameters['calcsb'],_invocation_parameters['parallel'],_invocation_parameters['pipelinemode'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'] ) except Exception as e: from traceback import format_exc from casatasks import casalog casalog.origin('hif_makeimlist') casalog.post("Exception Reported: Error in hif_makeimlist: %s" % str(e),'SEVERE') casalog.post(format_exc( )) _return_result_ = False try: os.rename(_prefile,_postfile) except: pass return _return_result_ hif_makeimlist = _hif_makeimlist( )