##################### generated by xml-casa (v2) from hif_makeimages.xml ############
##################### fffd9c21ccdc54826e983dd468a2484d ##############################
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_makeimages as _hif_makeimages_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_makeimages:
"""
hif_makeimages ---- Compute clean map
Compute clean results from a list of specified targets.
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']
target_list Dictionary specifying targets to be imaged; blank will read list from context
hm_masking Clean masking mode. Options are 'centralregion', 'auto',
'manual' and 'none'
hm_sidelobethreshold sidelobethreshold * the max sidelobe level
hm_noisethreshold noisethreshold * rms in residual image
hm_lownoisethreshold lownoisethreshold * rms in residual image
hm_negativethreshold negativethreshold * rms in residual image
hm_minbeamfrac Minimum beam fraction for pruning
hm_growiterations Number of binary dilation iterations for growing the mask
hm_dogrowprune Do pruning on the grow mask
hm_minpercentchange Mask size change threshold
hm_fastnoise Faster noise calucation for automask or nsigma stopping
hm_nsigma Multiplicative factor for rms-based threshold stopping
hm_perchanweightdensity Calculate the weight density for each channel independently
hm_npixels Number of pixels to determine uv-cell size for super-uniform weighting
hm_cyclefactor Scaling on PSF sidelobe level to compute the minor-cycle stopping threshold
hm_minpsffraction PSF fraction that marks the max depth of cleaning in the minor cycle
hm_maxpsffraction PSF fraction that marks the minimum depth of cleaning in the minor cycle
hm_cleaning Pipeline cleaning mode
tlimit Times the sensitivity limit for cleaning
masklimit Times good mask pixels for cleaning
cleancontranges Clean continuum frequency ranges in cubes
calcsb Force (re-)calculation of sensitivities and beams
mosweight Mosaic weighting
overwrite_on_export Replace existing image products when h/hifa/hifv_exportdata is
called.
If False, images that would have the same FITS name on export,
are amended to include a version number. For example, if
oussid.J1248-4559_ph.spw21.mfs.I.pbcor.fits would already be
exported by a previous call to hif_makeimags, then
'oussid.J1248-4559_ph.spw21.mfs.I.pbcor.v2.fits' would also be
exported to the products/ directory. The first exported
product retains the same name. Additional products start
counting with 'v2', 'v3', etc.
parallel Clean images using MPI cluster
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 to the pipeline context
--------- examples -----------------------------------------------------------
"""
_info_group_ = """pipeline"""
_info_desc_ = """Compute clean map"""
__schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'target_list': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'hm_masking': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'none', 'auto', 'manual', 'centralregion', '' ]}, 'hm_sidelobethreshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_noisethreshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_lownoisethreshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_negativethreshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_minbeamfrac': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_growiterations': {'type': 'cInt'}, 'hm_dogrowprune': {'type': 'cBool'}, 'hm_minpercentchange': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_fastnoise': {'type': 'cBool'}, 'hm_nsigma': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_perchanweightdensity': {'type': 'cBool'}, 'hm_npixels': {'type': 'cInt'}, 'hm_cyclefactor': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_minpsffraction': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_maxpsffraction': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_cleaning': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'timesmask', 'sensitivity', 'manual', 'rms', '' ]}, 'tlimit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'masklimit': {'type': 'cInt'}, 'cleancontranges': {'type': 'cBool'}, 'calcsb': {'type': 'cBool'}, 'mosweight': {'type': 'cBool'}, 'overwrite_on_export': {'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 + 23 + 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 __hm_fastnoise_dflt( self, glb ):
return True
def __hm_fastnoise( self, glb ):
if 'hm_fastnoise' in glb: return glb['hm_fastnoise']
return True
def __hm_npixels_dflt( self, glb ):
return int(0)
def __hm_npixels( self, glb ):
if 'hm_npixels' in glb: return glb['hm_npixels']
return int(0)
def __hm_perchanweightdensity_dflt( self, glb ):
return False
def __hm_perchanweightdensity( self, glb ):
if 'hm_perchanweightdensity' in glb: return glb['hm_perchanweightdensity']
return False
def __hm_maxpsffraction_dflt( self, glb ):
return float(-999.0)
def __hm_maxpsffraction( self, glb ):
if 'hm_maxpsffraction' in glb: return glb['hm_maxpsffraction']
return float(-999.0)
def __hm_cleaning_dflt( self, glb ):
return ''
def __hm_cleaning( self, glb ):
if 'hm_cleaning' in glb: return glb['hm_cleaning']
return ''
def __hm_nsigma_dflt( self, glb ):
return float(0.0)
def __hm_nsigma( self, glb ):
if 'hm_nsigma' in glb: return glb['hm_nsigma']
return float(0.0)
def __mosweight_dflt( self, glb ):
return False
def __mosweight( self, glb ):
if 'mosweight' in glb: return glb['mosweight']
return False
def __hm_minpsffraction_dflt( self, glb ):
return float(-999.0)
def __hm_minpsffraction( self, glb ):
if 'hm_minpsffraction' in glb: return glb['hm_minpsffraction']
return float(-999.0)
def __hm_masking_dflt( self, glb ):
return 'auto'
def __hm_masking( self, glb ):
if 'hm_masking' in glb: return glb['hm_masking']
return 'auto'
def __hm_cyclefactor_dflt( self, glb ):
return float(-999.0)
def __hm_cyclefactor( self, glb ):
if 'hm_cyclefactor' in glb: return glb['hm_cyclefactor']
return float(-999.0)
def __cleancontranges_dflt( self, glb ):
return False
def __cleancontranges( self, glb ):
if 'cleancontranges' in glb: return glb['cleancontranges']
return False
def __overwrite_on_export_dflt( self, glb ):
return True
def __overwrite_on_export( self, glb ):
if 'overwrite_on_export' in glb: return glb['overwrite_on_export']
return True
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'
#--------- return inp/go default --------------------------------------------------
def __dryrun_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(False)
return None
def __hm_growiterations_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return int(-999)
return None
def __hm_lownoisethreshold_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
return None
def __hm_dogrowprune_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return bool(True)
return None
def __hm_negativethreshold_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
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 __hm_minpercentchange_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
return None
def __masklimit_dflt( self, glb ):
if self.__hm_cleaning( glb ) == "timesmask": return int(4)
return None
def __hm_minbeamfrac_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
return None
def __target_list_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return {}
if self.__pipelinemode( glb ) == "getinputs": return {}
return None
def __hm_noisethreshold_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
return None
def __hm_sidelobethreshold_dflt( self, glb ):
if self.__hm_masking( glb ) == "auto": return float(-999.0)
return None
def __tlimit_dflt( self, glb ):
if self.__hm_cleaning( glb ) == "rms": return float(2.0)
if self.__hm_cleaning( glb ) == "sensitivity": return float(2.0)
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 __target_list( self, glb ):
if 'target_list' in glb: return glb['target_list']
dflt = self.__target_list_dflt( glb )
if dflt is not None: return dflt
return [ ]
def __hm_sidelobethreshold( self, glb ):
if 'hm_sidelobethreshold' in glb: return glb['hm_sidelobethreshold']
dflt = self.__hm_sidelobethreshold_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __hm_noisethreshold( self, glb ):
if 'hm_noisethreshold' in glb: return glb['hm_noisethreshold']
dflt = self.__hm_noisethreshold_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __hm_lownoisethreshold( self, glb ):
if 'hm_lownoisethreshold' in glb: return glb['hm_lownoisethreshold']
dflt = self.__hm_lownoisethreshold_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __hm_negativethreshold( self, glb ):
if 'hm_negativethreshold' in glb: return glb['hm_negativethreshold']
dflt = self.__hm_negativethreshold_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __hm_minbeamfrac( self, glb ):
if 'hm_minbeamfrac' in glb: return glb['hm_minbeamfrac']
dflt = self.__hm_minbeamfrac_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __hm_growiterations( self, glb ):
if 'hm_growiterations' in glb: return glb['hm_growiterations']
dflt = self.__hm_growiterations_dflt( glb )
if dflt is not None: return dflt
return int(-999)
def __hm_dogrowprune( self, glb ):
if 'hm_dogrowprune' in glb: return glb['hm_dogrowprune']
dflt = self.__hm_dogrowprune_dflt( glb )
if dflt is not None: return dflt
return True
def __hm_minpercentchange( self, glb ):
if 'hm_minpercentchange' in glb: return glb['hm_minpercentchange']
dflt = self.__hm_minpercentchange_dflt( glb )
if dflt is not None: return dflt
return float(-999.0)
def __tlimit( self, glb ):
if 'tlimit' in glb: return glb['tlimit']
dflt = self.__tlimit_dflt( glb )
if dflt is not None: return dflt
return float(2.0)
def __masklimit( self, glb ):
if 'masklimit' in glb: return glb['masklimit']
dflt = self.__masklimit_dflt( glb )
if dflt is not None: return dflt
return int(4)
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%-20.20s =\x1B[0m %s%-23s%s' % ('vis',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __target_list_inp(self):
if self.__target_list_dflt( self.__globals_( ) ) is not None:
description = 'Dictionary specifying targets to be imaged; blank will read list from context'
value = self.__target_list( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'target_list': value},{'target_list': self.__schema['target_list']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('target_list',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_masking_inp(self):
description = 'Pipeline heuristics masking mode'
value = self.__hm_masking( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_masking': value},{'hm_masking': self.__schema['hm_masking']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-23.23s =\x1B[0m %s%-23s%s' % ('hm_masking',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __hm_sidelobethreshold_inp(self):
if self.__hm_sidelobethreshold_dflt( self.__globals_( ) ) is not None:
description = 'sidelobethreshold * the max sidelobe level'
value = self.__hm_sidelobethreshold( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_sidelobethreshold': value},{'hm_sidelobethreshold': self.__schema['hm_sidelobethreshold']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_sidelobethreshold',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_noisethreshold_inp(self):
if self.__hm_noisethreshold_dflt( self.__globals_( ) ) is not None:
description = 'noisethreshold * rms in residual image'
value = self.__hm_noisethreshold( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_noisethreshold': value},{'hm_noisethreshold': self.__schema['hm_noisethreshold']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_noisethreshold',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_lownoisethreshold_inp(self):
if self.__hm_lownoisethreshold_dflt( self.__globals_( ) ) is not None:
description = 'lownoisethreshold * rms in residual image'
value = self.__hm_lownoisethreshold( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_lownoisethreshold': value},{'hm_lownoisethreshold': self.__schema['hm_lownoisethreshold']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_lownoisethreshold',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_negativethreshold_inp(self):
if self.__hm_negativethreshold_dflt( self.__globals_( ) ) is not None:
description = 'negativethreshold * rms in residual image'
value = self.__hm_negativethreshold( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_negativethreshold': value},{'hm_negativethreshold': self.__schema['hm_negativethreshold']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_negativethreshold',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_minbeamfrac_inp(self):
if self.__hm_minbeamfrac_dflt( self.__globals_( ) ) is not None:
description = 'Minimum beam fraction for pruning'
value = self.__hm_minbeamfrac( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_minbeamfrac': value},{'hm_minbeamfrac': self.__schema['hm_minbeamfrac']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_minbeamfrac',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_growiterations_inp(self):
if self.__hm_growiterations_dflt( self.__globals_( ) ) is not None:
description = 'Number of binary dilation iterations for growing the mask'
value = self.__hm_growiterations( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_growiterations': value},{'hm_growiterations': self.__schema['hm_growiterations']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_growiterations',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_dogrowprune_inp(self):
if self.__hm_dogrowprune_dflt( self.__globals_( ) ) is not None:
description = 'Do pruning on the grow mask'
value = self.__hm_dogrowprune( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_dogrowprune': value},{'hm_dogrowprune': self.__schema['hm_dogrowprune']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_dogrowprune',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_minpercentchange_inp(self):
if self.__hm_minpercentchange_dflt( self.__globals_( ) ) is not None:
description = 'Mask size change threshold'
value = self.__hm_minpercentchange( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_minpercentchange': value},{'hm_minpercentchange': self.__schema['hm_minpercentchange']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_minpercentchange',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_fastnoise_inp(self):
description = 'Faster noise calucation for automask or nsigma stopping'
value = self.__hm_fastnoise( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_fastnoise': value},{'hm_fastnoise': self.__schema['hm_fastnoise']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_fastnoise',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_nsigma_inp(self):
description = 'Multiplicative factor for rms-based threshold stopping'
value = self.__hm_nsigma( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_nsigma': value},{'hm_nsigma': self.__schema['hm_nsigma']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_nsigma',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_perchanweightdensity_inp(self):
description = 'Calculate the weight density for each channel independently'
value = self.__hm_perchanweightdensity( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_perchanweightdensity': value},{'hm_perchanweightdensity': self.__schema['hm_perchanweightdensity']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_perchanweightdensity',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_npixels_inp(self):
description = 'Number of pixels to determine uv-cell size for super-uniform weighting'
value = self.__hm_npixels( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_npixels': value},{'hm_npixels': self.__schema['hm_npixels']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_npixels',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_cyclefactor_inp(self):
description = 'Scaling on PSF sidelobe level to compute the minor-cycle stopping threshold'
value = self.__hm_cyclefactor( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_cyclefactor': value},{'hm_cyclefactor': self.__schema['hm_cyclefactor']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_cyclefactor',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_minpsffraction_inp(self):
description = 'PSF fraction that marks the max depth of cleaning in the minor cycle'
value = self.__hm_minpsffraction( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_minpsffraction': value},{'hm_minpsffraction': self.__schema['hm_minpsffraction']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_minpsffraction',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_maxpsffraction_inp(self):
description = 'PSF fraction that marks the minimum depth of cleaning in the minor cycle'
value = self.__hm_maxpsffraction( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_maxpsffraction': value},{'hm_maxpsffraction': self.__schema['hm_maxpsffraction']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('hm_maxpsffraction',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __hm_cleaning_inp(self):
description = 'Pipeline cleaning mode'
value = self.__hm_cleaning( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_cleaning': value},{'hm_cleaning': self.__schema['hm_cleaning']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-23.23s =\x1B[0m %s%-23s%s' % ('hm_cleaning',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __tlimit_inp(self):
if self.__tlimit_dflt( self.__globals_( ) ) is not None:
description = 'Times the sensitivity limit for cleaning'
value = self.__tlimit( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'tlimit': value},{'tlimit': self.__schema['tlimit']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('tlimit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __masklimit_inp(self):
if self.__masklimit_dflt( self.__globals_( ) ) is not None:
description = 'Times good mask pixels for cleaning'
value = self.__masklimit( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'masklimit': value},{'masklimit': self.__schema['masklimit']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-20.20s =\x1B[0m %s%-23s%s' % ('masklimit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __cleancontranges_inp(self):
description = 'Clean continuum frequency ranges in cubes'
value = self.__cleancontranges( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'cleancontranges': value},{'cleancontranges': self.__schema['cleancontranges']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('cleancontranges',pre,self.__to_string_(value),post),description,0+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('%-23.23s = %s%-23s%s' % ('calcsb',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __mosweight_inp(self):
description = 'Mosaic weighting'
value = self.__mosweight( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'mosweight': value},{'mosweight': self.__schema['mosweight']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('mosweight',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __overwrite_on_export_inp(self):
description = 'Replace existing image products'
value = self.__overwrite_on_export( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'overwrite_on_export': value},{'overwrite_on_export': self.__schema['overwrite_on_export']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-23.23s = %s%-23s%s' % ('overwrite_on_export',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __parallel_inp(self):
description = 'Clean images using MPI cluster'
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('%-23.23s = %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%-23.23s =\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%-20.20s =\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%-20.20s =\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 'hm_perchanweightdensity' in glb: del glb['hm_perchanweightdensity']
if 'dryrun' in glb: del glb['dryrun']
if 'hm_fastnoise' in glb: del glb['hm_fastnoise']
if 'hm_masking' in glb: del glb['hm_masking']
if 'pipelinemode' in glb: del glb['pipelinemode']
if 'hm_growiterations' in glb: del glb['hm_growiterations']
if 'hm_lownoisethreshold' in glb: del glb['hm_lownoisethreshold']
if 'hm_dogrowprune' in glb: del glb['hm_dogrowprune']
if 'cleancontranges' in glb: del glb['cleancontranges']
if 'hm_cyclefactor' in glb: del glb['hm_cyclefactor']
if 'hm_negativethreshold' in glb: del glb['hm_negativethreshold']
if 'hm_minpsffraction' in glb: del glb['hm_minpsffraction']
if 'hm_cleaning' in glb: del glb['hm_cleaning']
if 'vis' in glb: del glb['vis']
if 'acceptresults' in glb: del glb['acceptresults']
if 'calcsb' in glb: del glb['calcsb']
if 'hm_minpercentchange' in glb: del glb['hm_minpercentchange']
if 'masklimit' in glb: del glb['masklimit']
if 'mosweight' in glb: del glb['mosweight']
if 'hm_nsigma' in glb: del glb['hm_nsigma']
if 'hm_minbeamfrac' in glb: del glb['hm_minbeamfrac']
if 'target_list' in glb: del glb['target_list']
if 'hm_npixels' in glb: del glb['hm_npixels']
if 'hm_maxpsffraction' in glb: del glb['hm_maxpsffraction']
if 'hm_noisethreshold' in glb: del glb['hm_noisethreshold']
if 'overwrite_on_export' in glb: del glb['overwrite_on_export']
if 'hm_sidelobethreshold' in glb: del glb['hm_sidelobethreshold']
if 'parallel' in glb: del glb['parallel']
if 'tlimit' in glb: del glb['tlimit']
#--------- inp function -----------------------------------------------------------
def inp(self):
print("# hif_makeimages -- %s" % self._info_desc_)
self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24))
self.__vis_inp( )
self.__target_list_inp( )
self.__hm_masking_inp( )
self.__hm_sidelobethreshold_inp( )
self.__hm_noisethreshold_inp( )
self.__hm_lownoisethreshold_inp( )
self.__hm_negativethreshold_inp( )
self.__hm_minbeamfrac_inp( )
self.__hm_growiterations_inp( )
self.__hm_dogrowprune_inp( )
self.__hm_minpercentchange_inp( )
self.__hm_fastnoise_inp( )
self.__hm_nsigma_inp( )
self.__hm_perchanweightdensity_inp( )
self.__hm_npixels_inp( )
self.__hm_cyclefactor_inp( )
self.__hm_minpsffraction_inp( )
self.__hm_maxpsffraction_inp( )
self.__hm_cleaning_inp( )
self.__tlimit_inp( )
self.__masklimit_inp( )
self.__cleancontranges_inp( )
self.__calcsb_inp( )
self.__mosweight_inp( )
self.__overwrite_on_export_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_makeimages.last"):
filename = "hif_makeimages.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, target_list=None, hm_masking=None, hm_sidelobethreshold=None, hm_noisethreshold=None, hm_lownoisethreshold=None, hm_negativethreshold=None, hm_minbeamfrac=None, hm_growiterations=None, hm_dogrowprune=None, hm_minpercentchange=None, hm_fastnoise=None, hm_nsigma=None, hm_perchanweightdensity=None, hm_npixels=None, hm_cyclefactor=None, hm_minpsffraction=None, hm_maxpsffraction=None, hm_cleaning=None, tlimit=None, masklimit=None, cleancontranges=None, calcsb=None, mosweight=None, overwrite_on_export=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_makeimages.pre')
_postfile = os.path.realpath('hif_makeimages.last')
_return_result_ = None
_arguments = [vis,target_list,hm_masking,hm_sidelobethreshold,hm_noisethreshold,hm_lownoisethreshold,hm_negativethreshold,hm_minbeamfrac,hm_growiterations,hm_dogrowprune,hm_minpercentchange,hm_fastnoise,hm_nsigma,hm_perchanweightdensity,hm_npixels,hm_cyclefactor,hm_minpsffraction,hm_maxpsffraction,hm_cleaning,tlimit,masklimit,cleancontranges,calcsb,mosweight,overwrite_on_export,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 hm_masking is not None: local_global['hm_masking'] = hm_masking
if hm_fastnoise is not None: local_global['hm_fastnoise'] = hm_fastnoise
if hm_nsigma is not None: local_global['hm_nsigma'] = hm_nsigma
if hm_perchanweightdensity is not None: local_global['hm_perchanweightdensity'] = hm_perchanweightdensity
if hm_npixels is not None: local_global['hm_npixels'] = hm_npixels
if hm_cyclefactor is not None: local_global['hm_cyclefactor'] = hm_cyclefactor
if hm_minpsffraction is not None: local_global['hm_minpsffraction'] = hm_minpsffraction
if hm_maxpsffraction is not None: local_global['hm_maxpsffraction'] = hm_maxpsffraction
if hm_cleaning is not None: local_global['hm_cleaning'] = hm_cleaning
if cleancontranges is not None: local_global['cleancontranges'] = cleancontranges
if calcsb is not None: local_global['calcsb'] = calcsb
if mosweight is not None: local_global['mosweight'] = mosweight
if overwrite_on_export is not None: local_global['overwrite_on_export'] = overwrite_on_export
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['hm_masking'] = self.__hm_masking( local_global )
_invocation_parameters['hm_fastnoise'] = self.__hm_fastnoise( local_global )
_invocation_parameters['hm_nsigma'] = self.__hm_nsigma( local_global )
_invocation_parameters['hm_perchanweightdensity'] = self.__hm_perchanweightdensity( local_global )
_invocation_parameters['hm_npixels'] = self.__hm_npixels( local_global )
_invocation_parameters['hm_cyclefactor'] = self.__hm_cyclefactor( local_global )
_invocation_parameters['hm_minpsffraction'] = self.__hm_minpsffraction( local_global )
_invocation_parameters['hm_maxpsffraction'] = self.__hm_maxpsffraction( local_global )
_invocation_parameters['hm_cleaning'] = self.__hm_cleaning( local_global )
_invocation_parameters['cleancontranges'] = self.__cleancontranges( local_global )
_invocation_parameters['calcsb'] = self.__calcsb( local_global )
_invocation_parameters['mosweight'] = self.__mosweight( local_global )
_invocation_parameters['overwrite_on_export'] = self.__overwrite_on_export( 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['target_list'] = self.__target_list( _invocation_parameters ) if target_list is None else target_list
_invocation_parameters['hm_sidelobethreshold'] = self.__hm_sidelobethreshold( _invocation_parameters ) if hm_sidelobethreshold is None else hm_sidelobethreshold
_invocation_parameters['hm_noisethreshold'] = self.__hm_noisethreshold( _invocation_parameters ) if hm_noisethreshold is None else hm_noisethreshold
_invocation_parameters['hm_lownoisethreshold'] = self.__hm_lownoisethreshold( _invocation_parameters ) if hm_lownoisethreshold is None else hm_lownoisethreshold
_invocation_parameters['hm_negativethreshold'] = self.__hm_negativethreshold( _invocation_parameters ) if hm_negativethreshold is None else hm_negativethreshold
_invocation_parameters['hm_minbeamfrac'] = self.__hm_minbeamfrac( _invocation_parameters ) if hm_minbeamfrac is None else hm_minbeamfrac
_invocation_parameters['hm_growiterations'] = self.__hm_growiterations( _invocation_parameters ) if hm_growiterations is None else hm_growiterations
_invocation_parameters['hm_dogrowprune'] = self.__hm_dogrowprune( _invocation_parameters ) if hm_dogrowprune is None else hm_dogrowprune
_invocation_parameters['hm_minpercentchange'] = self.__hm_minpercentchange( _invocation_parameters ) if hm_minpercentchange is None else hm_minpercentchange
_invocation_parameters['tlimit'] = self.__tlimit( _invocation_parameters ) if tlimit is None else tlimit
_invocation_parameters['masklimit'] = self.__masklimit( _invocation_parameters ) if masklimit is None else masklimit
_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['target_list'] = self.__target_list( self.__globals_( ) )
_invocation_parameters['hm_masking'] = self.__hm_masking( self.__globals_( ) )
_invocation_parameters['hm_sidelobethreshold'] = self.__hm_sidelobethreshold( self.__globals_( ) )
_invocation_parameters['hm_noisethreshold'] = self.__hm_noisethreshold( self.__globals_( ) )
_invocation_parameters['hm_lownoisethreshold'] = self.__hm_lownoisethreshold( self.__globals_( ) )
_invocation_parameters['hm_negativethreshold'] = self.__hm_negativethreshold( self.__globals_( ) )
_invocation_parameters['hm_minbeamfrac'] = self.__hm_minbeamfrac( self.__globals_( ) )
_invocation_parameters['hm_growiterations'] = self.__hm_growiterations( self.__globals_( ) )
_invocation_parameters['hm_dogrowprune'] = self.__hm_dogrowprune( self.__globals_( ) )
_invocation_parameters['hm_minpercentchange'] = self.__hm_minpercentchange( self.__globals_( ) )
_invocation_parameters['hm_fastnoise'] = self.__hm_fastnoise( self.__globals_( ) )
_invocation_parameters['hm_nsigma'] = self.__hm_nsigma( self.__globals_( ) )
_invocation_parameters['hm_perchanweightdensity'] = self.__hm_perchanweightdensity( self.__globals_( ) )
_invocation_parameters['hm_npixels'] = self.__hm_npixels( self.__globals_( ) )
_invocation_parameters['hm_cyclefactor'] = self.__hm_cyclefactor( self.__globals_( ) )
_invocation_parameters['hm_minpsffraction'] = self.__hm_minpsffraction( self.__globals_( ) )
_invocation_parameters['hm_maxpsffraction'] = self.__hm_maxpsffraction( self.__globals_( ) )
_invocation_parameters['hm_cleaning'] = self.__hm_cleaning( self.__globals_( ) )
_invocation_parameters['tlimit'] = self.__tlimit( self.__globals_( ) )
_invocation_parameters['masklimit'] = self.__masklimit( self.__globals_( ) )
_invocation_parameters['cleancontranges'] = self.__cleancontranges( self.__globals_( ) )
_invocation_parameters['calcsb'] = self.__calcsb( self.__globals_( ) )
_invocation_parameters['mosweight'] = self.__mosweight( self.__globals_( ) )
_invocation_parameters['overwrite_on_export'] = self.__overwrite_on_export( 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("%-23s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
_f.write("#hif_makeimages( ")
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_makeimages_t( _invocation_parameters['vis'],_invocation_parameters['target_list'],_invocation_parameters['hm_masking'],_invocation_parameters['hm_sidelobethreshold'],_invocation_parameters['hm_noisethreshold'],_invocation_parameters['hm_lownoisethreshold'],_invocation_parameters['hm_negativethreshold'],_invocation_parameters['hm_minbeamfrac'],_invocation_parameters['hm_growiterations'],_invocation_parameters['hm_dogrowprune'],_invocation_parameters['hm_minpercentchange'],_invocation_parameters['hm_fastnoise'],_invocation_parameters['hm_nsigma'],_invocation_parameters['hm_perchanweightdensity'],_invocation_parameters['hm_npixels'],_invocation_parameters['hm_cyclefactor'],_invocation_parameters['hm_minpsffraction'],_invocation_parameters['hm_maxpsffraction'],_invocation_parameters['hm_cleaning'],_invocation_parameters['tlimit'],_invocation_parameters['masklimit'],_invocation_parameters['cleancontranges'],_invocation_parameters['calcsb'],_invocation_parameters['mosweight'],_invocation_parameters['overwrite_on_export'],_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_makeimages')
casalog.post("Exception Reported: Error in hif_makeimages: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hif_makeimages = _hif_makeimages( )