Source code for pipeline.hifa.cli.gotasks.hifa_session_bandpass

##################### generated by xml-casa (v2) from hifa_session_bandpass.xml #####
##################### c002de19bc4253460b98219aaeef6395 ##############################
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.hifa.cli import hifa_session_bandpass as _hifa_session_bandpass_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 _hifa_session_bandpass: """ hifa_session_bandpass ---- Compute bandpass calibration solutions Compute amplitude and phase as a function of frequency for each spectral window in each MeasurementSet. Previous calibration can be applied on the fly. hifa_session_bandpass computes a bandpass solution for every specified science spectral window. By default a 'phaseup' pre-calibration is performed and applied on the fly to the data, before the bandpass is computed. The hif_refant task may be used to precompute a prioritized list of reference antennas. Output results -- If pipeline mode is 'getinputs' then None is returned. Otherwise the results object for the pipeline task is returned. Issues There is currently some discussion about whether or not to do an 'ampup' operations at the same time as the 'phaseup'. This is not required for the bandpass computation but the amplitude information may provide a useful quality assessment measure. The specified minsnr parameter is currently applied to the bandpass solution computation but not the 'phaseup' computation. Some noisy solutions in the phaseup may not be properly rejected. --------- parameter descriptions --------------------------------------------- vis The list of input MeasurementSets. Defaults to the list of MeasurementSets specified in the pipeline context. example: vis=['M51.ms'] caltable The list of output calibration tables. Defaults to the standard pipeline naming convention. example: caltable=['M51.bcal'] field The list of field names or field ids for which bandpasses are computed. Defaults to all fields. example: field='3C279', field='3C279, M82' intent A string containing a comma delimited list of intents against which the selected fields are matched. Defaults to all data with bandpass intent. example: intent='*PHASE*' spw The list of spectral windows and channels for which bandpasses are computed. Defaults to all science spectral windows. example: spw='11,13,15,17' antenna hm_phaseup The pre-bandpass solution phaseup gain heuristics. The options are 'snr' (compute solution required to achieve the specified SNR), 'manual' (use manual solution parameters), and '' (none). example: hm_phaseup='manual' phaseupsolint The phase correction solution interval in CASA syntax. Used when hm_phaseup='manual' or as a default if the hm_phaseup='snr' heuristic computation fails. example: phaseupsolint='300s' phaseupbw Bandwidth to be used for phaseup. Defaults to 500MHz. Used when hm_phaseup='manual'. example: phaseupbw='' to use entire bandpass, phaseupbw='500MHz' to use central 500MHz phaseupsnr The required SNR for the phaseup solution. Used only if hm_phaseup='snr'. example: phaseupsnr=10.0 phaseupnsols The minimum number of phaseup gain solutions. Used only if hm_phaseup='snr'. example: phaseupnsols=4 hm_bandpass The bandpass solution heuristics. The options are 'snr' (compute the solution required to achieve the specified SNR), 'smoothed' (simple smoothing heuristics), and 'fixed' (use the user defined parameters for all spws). solint Time and channel solution intervals in CASA syntax. default: 'inf' Used for hm_bandpass='fixed', and as a default for the 'snr' and 'smoothed' options. default: 'inf,7.8125MHz' example: solint='inf,10ch', solint='inf' maxchannels The bandpass solution smoothing factor in channels. The solution interval is bandwidth / 240. Set to 0 for no smoothing. Used if hm_bandpass='smoothed". example: 0 evenbpints Force the per spw frequency solint to be evenly divisible into the spw bandpass if hm_bandpass='snr'. example: evenbpints=False bpsnr The required SNR for the bandpass solution. Used only if hm_bandpass='snr' example: bpsnr=30.0 minbpsnr The minimum required SNR for the bandpass solution when strong atmospheric lines exist in Tsys spectra. Used only if hm_bandpass='snr'. example: minbpsnr=10.0 bpnsols The minimum number of bandpass solutions. Used only if hm_bandpass='snr'. hm_bandtype The type of bandpass. The options are 'channel' and 'polynomial' for CASA bandpass types = 'B' and 'BPOLY' respectively. combine Data axes to combine for solving. Axes are '', 'scan', 'spw', 'field' or any comma-separated combination. example: combine='scan,field' refant Reference antenna names. Defaults to the value(s) stored in the pipeline context. If undefined in the pipeline context defaults to the CASA reference antenna naming scheme. example: refant='DV01', refant='DV06,DV07' solnorm Normalise the bandpass solutions. minblperant Minimum number of baselines required per antenna for each solve Antennas with fewer baselines are excluded from solutions. Used for hm_bandtype='channel' only. minsnr Solutions below this SNR are rejected. Used for hm_bandtype= 'channel' only. degamp degphase 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 commands (True) or generate the commands to be run but do not execute (False). acceptresults Add the results of the task to the pipeline context (True) or reject them (False). parallel Execute using CASA HPC functionality, if available. --------- examples ----------------------------------------------------------- 1. Compute a channel bandpass for all visibility files in the pipeline context using the CASA reference antenna determination scheme: hifa_session_bandpass() 2. Same as the above but precompute a prioritized reference antenna list: hif_refant() hifa_session_bandpass() """ _info_group_ = """pipeline""" _info_desc_ = """Compute bandpass calibration solutions""" __schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'caltable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'field': {'type': 'cStr', 'coerce': _coerce.to_str}, 'intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'antenna': {'type': 'cStr', 'coerce': _coerce.to_str}, 'hm_phaseup': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'snr', 'manual', '' ]}, 'phaseupsolint': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'phaseupbw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'phaseupsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'phaseupnsols': {'type': 'cInt'}, 'hm_bandpass': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'snr', 'smoothed', 'fixed' ]}, 'solint': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'maxchannels': {'type': 'cInt'}, 'evenbpints': {'type': 'cBool'}, 'bpsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'minbpsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'bpnsols': {'type': 'cInt'}, 'hm_bandtype': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'channel', 'polynomial' ]}, 'combine': {'type': 'cStr', 'coerce': _coerce.to_str}, 'refant': {'type': 'cStr', 'coerce': _coerce.to_str}, 'solnorm': {'type': 'cBool'}, 'minblperant': {'type': 'cInt'}, 'minsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'degamp': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'degphase': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}, 'parallel': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'true', 'false' ]}} 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 __hm_phaseup_dflt( self, glb ): return 'snr' def __hm_phaseup( self, glb ): if 'hm_phaseup' in glb: return glb['hm_phaseup'] return 'snr' def __combine_dflt( self, glb ): return 'scan' def __combine( self, glb ): if 'combine' in glb: return glb['combine'] return 'scan' def __pipelinemode_dflt( self, glb ): return 'automatic' def __pipelinemode( self, glb ): if 'pipelinemode' in glb: return glb['pipelinemode'] return 'automatic' def __hm_bandtype_dflt( self, glb ): return 'channel' def __hm_bandtype( self, glb ): if 'hm_bandtype' in glb: return glb['hm_bandtype'] return 'channel' def __hm_bandpass_dflt( self, glb ): return 'snr' def __hm_bandpass( self, glb ): if 'hm_bandpass' in glb: return glb['hm_bandpass'] return 'snr' #--------- return non subparam/when values --------------------------------------------- def __solnorm( self, glb ): if 'solnorm' in glb: return glb['solnorm'] return True #--------- return inp/go default -------------------------------------------------- def __antenna_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __phaseupbw_dflt( self, glb ): if self.__hm_phaseup( glb ) == "manual": return "" return None def __dryrun_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(False) return None def __phaseupnsols_dflt( self, glb ): if self.__hm_phaseup( glb ) == "snr": return int(2) return None def __field_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __minbpsnr_dflt( self, glb ): if self.__hm_bandpass( glb ) == "snr": return float(20.0) return None def __intent_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __degamp_dflt( self, glb ): if self.__hm_bandtype( glb ) == "polynomial": return { } return None def __refant_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __minsnr_dflt( self, glb ): if self.__hm_bandtype( glb ) == "channel": return float(3.0) return None def __phaseupsnr_dflt( self, glb ): if self.__hm_phaseup( glb ) == "snr": return float(20.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 __minblperant_dflt( self, glb ): if self.__hm_bandtype( glb ) == "channel": return int(4) return None def __solnorm_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(True) if self.__pipelinemode( glb ) == "getinputs": return bool(True) return None def __maxchannels_dflt( self, glb ): if self.__hm_bandpass( glb ) == "smoothed": return int(240) return None def __phaseupsolint_dflt( self, glb ): if self.__hm_phaseup( glb ) == "snr": return "int" if self.__hm_phaseup( glb ) == "manual": return "int" return None def __bpsnr_dflt( self, glb ): if self.__hm_bandpass( glb ) == "snr": return float(50.0) return None def __bpnsols_dflt( self, glb ): if self.__hm_bandpass( glb ) == "snr": return int(8) return None def __solint_dflt( self, glb ): if self.__hm_bandpass( glb ) == "snr": return "inf" if self.__hm_bandpass( glb ) == "smoothed": return "inf" if self.__hm_bandpass( glb ) == "fixed": return "inf,7.8125MHz" return None def __evenbpints_dflt( self, glb ): if self.__hm_bandpass( glb ) == "snr": return bool(True) return None def __caltable_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] return None def __degphase_dflt( self, glb ): if self.__hm_bandtype( glb ) == "polynomial": return { } return None def __spw_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "" if self.__pipelinemode( glb ) == "getinputs": return "" return None def __parallel_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return "automatic" 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 __caltable( self, glb ): if 'caltable' in glb: return glb['caltable'] dflt = self.__caltable_dflt( glb ) if dflt is not None: return dflt return [ ] 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 __intent( self, glb ): if 'intent' in glb: return glb['intent'] dflt = self.__intent_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 __antenna( self, glb ): if 'antenna' in glb: return glb['antenna'] dflt = self.__antenna_dflt( glb ) if dflt is not None: return dflt return '' def __phaseupsolint( self, glb ): if 'phaseupsolint' in glb: return glb['phaseupsolint'] dflt = self.__phaseupsolint_dflt( glb ) if dflt is not None: return dflt return 'int' def __phaseupbw( self, glb ): if 'phaseupbw' in glb: return glb['phaseupbw'] dflt = self.__phaseupbw_dflt( glb ) if dflt is not None: return dflt return '' def __phaseupsnr( self, glb ): if 'phaseupsnr' in glb: return glb['phaseupsnr'] dflt = self.__phaseupsnr_dflt( glb ) if dflt is not None: return dflt return float(20.0) def __phaseupnsols( self, glb ): if 'phaseupnsols' in glb: return glb['phaseupnsols'] dflt = self.__phaseupnsols_dflt( glb ) if dflt is not None: return dflt return int(2) def __solint( self, glb ): if 'solint' in glb: return glb['solint'] dflt = self.__solint_dflt( glb ) if dflt is not None: return dflt return 'inf' def __maxchannels( self, glb ): if 'maxchannels' in glb: return glb['maxchannels'] dflt = self.__maxchannels_dflt( glb ) if dflt is not None: return dflt return int(240) def __evenbpints( self, glb ): if 'evenbpints' in glb: return glb['evenbpints'] dflt = self.__evenbpints_dflt( glb ) if dflt is not None: return dflt return True def __bpsnr( self, glb ): if 'bpsnr' in glb: return glb['bpsnr'] dflt = self.__bpsnr_dflt( glb ) if dflt is not None: return dflt return float(50.0) def __minbpsnr( self, glb ): if 'minbpsnr' in glb: return glb['minbpsnr'] dflt = self.__minbpsnr_dflt( glb ) if dflt is not None: return dflt return float(20.0) def __bpnsols( self, glb ): if 'bpnsols' in glb: return glb['bpnsols'] dflt = self.__bpnsols_dflt( glb ) if dflt is not None: return dflt return int(8) def __refant( self, glb ): if 'refant' in glb: return glb['refant'] dflt = self.__refant_dflt( glb ) if dflt is not None: return dflt return '' def __minblperant( self, glb ): if 'minblperant' in glb: return glb['minblperant'] dflt = self.__minblperant_dflt( glb ) if dflt is not None: return dflt return int(4) def __minsnr( self, glb ): if 'minsnr' in glb: return glb['minsnr'] dflt = self.__minsnr_dflt( glb ) if dflt is not None: return dflt return float(3.0) def __degamp( self, glb ): if 'degamp' in glb: return glb['degamp'] dflt = self.__degamp_dflt( glb ) if dflt is not None: return dflt return '' def __degphase( self, glb ): if 'degphase' in glb: return glb['degphase'] dflt = self.__degphase_dflt( glb ) if dflt is not None: return dflt return '' 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 def __parallel( self, glb ): if 'parallel' in glb: return glb['parallel'] dflt = self.__parallel_dflt( glb ) if dflt is not None: return dflt return 'automatic' #--------- 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 __caltable_inp(self): if self.__caltable_dflt( self.__globals_( ) ) is not None: description = 'List of output caltables' value = self.__caltable( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'caltable': value},{'caltable': self.__schema['caltable']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('caltable',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' 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 __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 __spw_inp(self): if self.__spw_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection spectral window/channels' 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 __antenna_inp(self): if self.__antenna_dflt( self.__globals_( ) ) is not None: description = 'Set of data selection antenna IDs' value = self.__antenna( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'antenna': value},{'antenna': self.__schema['antenna']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('antenna',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_phaseup_inp(self): description = 'Phaseup before computing the bandpass' value = self.__hm_phaseup( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_phaseup': value},{'hm_phaseup': self.__schema['hm_phaseup']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('hm_phaseup',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __phaseupsolint_inp(self): if self.__phaseupsolint_dflt( self.__globals_( ) ) is not None: description = 'Phaseup correction solution interval' value = self.__phaseupsolint( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'phaseupsolint': value},{'phaseupsolint': self.__schema['phaseupsolint']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('phaseupsolint',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __phaseupbw_inp(self): if self.__phaseupbw_dflt( self.__globals_( ) ) is not None: description = 'Bandwidth to use for phaseup' value = self.__phaseupbw( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'phaseupbw': value},{'phaseupbw': self.__schema['phaseupbw']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('phaseupbw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __phaseupsnr_inp(self): if self.__phaseupsnr_dflt( self.__globals_( ) ) is not None: description = 'SNR for phaseup solution' value = self.__phaseupsnr( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'phaseupsnr': value},{'phaseupsnr': self.__schema['phaseupsnr']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('phaseupsnr',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __phaseupnsols_inp(self): if self.__phaseupnsols_dflt( self.__globals_( ) ) is not None: description = 'Minimum number of phaseup gain solutions' value = self.__phaseupnsols( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'phaseupnsols': value},{'phaseupnsols': self.__schema['phaseupnsols']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('phaseupnsols',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_bandpass_inp(self): description = 'Bandpass solution heuristics' value = self.__hm_bandpass( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_bandpass': value},{'hm_bandpass': self.__schema['hm_bandpass']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('hm_bandpass',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __solint_inp(self): if self.__solint_dflt( self.__globals_( ) ) is not None: description = 'Solution intervals' value = self.__solint( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'solint': value},{'solint': self.__schema['solint']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('solint',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __maxchannels_inp(self): if self.__maxchannels_dflt( self.__globals_( ) ) is not None: description = 'The smoothing factor in channels' value = self.__maxchannels( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'maxchannels': value},{'maxchannels': self.__schema['maxchannels']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('maxchannels',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __evenbpints_inp(self): if self.__evenbpints_dflt( self.__globals_( ) ) is not None: description = 'Force frequency solint to even bandpass intervals' value = self.__evenbpints( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'evenbpints': value},{'evenbpints': self.__schema['evenbpints']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('evenbpints',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __bpsnr_inp(self): if self.__bpsnr_dflt( self.__globals_( ) ) is not None: description = 'SNR for bandpass solution' value = self.__bpsnr( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'bpsnr': value},{'bpsnr': self.__schema['bpsnr']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('bpsnr',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __minbpsnr_inp(self): if self.__minbpsnr_dflt( self.__globals_( ) ) is not None: description = 'The minimum required bandpass frequency solution signal to noise when strong atmospheric lines exist in Tsys spectra' value = self.__minbpsnr( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'minbpsnr': value},{'minbpsnr': self.__schema['minbpsnr']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('minbpsnr',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __bpnsols_inp(self): if self.__bpnsols_dflt( self.__globals_( ) ) is not None: description = 'Minimum number of bandpass solutions' value = self.__bpnsols( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'bpnsols': value},{'bpnsols': self.__schema['bpnsols']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('bpnsols',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_bandtype_inp(self): description = 'Bandpass solution type' value = self.__hm_bandtype( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_bandtype': value},{'hm_bandtype': self.__schema['hm_bandtype']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('hm_bandtype',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __combine_inp(self): description = 'Data axes which to combine for solve (scan, spw, and/or field)' value = self.__combine( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'combine': value},{'combine': self.__schema['combine']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-16.16s = %s%-23s%s' % ('combine',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __refant_inp(self): if self.__refant_dflt( self.__globals_( ) ) is not None: description = 'Reference antenna names' value = self.__refant( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'refant': value},{'refant': self.__schema['refant']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('refant',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __solnorm_inp(self): description = 'Normalise the bandpass solution' value = self.__solnorm( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'solnorm': value},{'solnorm': self.__schema['solnorm']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-16.16s = %s%-23s%s' % ('solnorm',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __minblperant_inp(self): if self.__minblperant_dflt( self.__globals_( ) ) is not None: description = 'Minimum baselines per antenna required for solve' value = self.__minblperant( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'minblperant': value},{'minblperant': self.__schema['minblperant']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('minblperant',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __minsnr_inp(self): if self.__minsnr_dflt( self.__globals_( ) ) is not None: description = 'Reject solutions below this SNR' value = self.__minsnr( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'minsnr': value},{'minsnr': self.__schema['minsnr']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('minsnr',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __degamp_inp(self): if self.__degamp_dflt( self.__globals_( ) ) is not None: description = 'Degree for polynomial amplitude solution' value = self.__degamp( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'degamp': value},{'degamp': self.__schema['degamp']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('degamp',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __degphase_inp(self): if self.__degphase_dflt( self.__globals_( ) ) is not None: description = 'Degree for polynomial phase solution' value = self.__degphase( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'degphase': value},{'degphase': self.__schema['degphase']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('degphase',pre,self.__to_string_(value),post),description,9+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 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)) def __parallel_inp(self): if self.__parallel_dflt( self.__globals_( ) ) is not None: description = 'Execute using CASA HPC functionality, if available.' 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(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('parallel',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 'antenna' in glb: del glb['antenna'] if 'phaseupbw' in glb: del glb['phaseupbw'] if 'dryrun' in glb: del glb['dryrun'] if 'phaseupnsols' in glb: del glb['phaseupnsols'] if 'field' in glb: del glb['field'] if 'pipelinemode' in glb: del glb['pipelinemode'] if 'minbpsnr' in glb: del glb['minbpsnr'] if 'intent' in glb: del glb['intent'] if 'degamp' in glb: del glb['degamp'] if 'refant' in glb: del glb['refant'] if 'minsnr' in glb: del glb['minsnr'] if 'phaseupsnr' in glb: del glb['phaseupsnr'] if 'vis' in glb: del glb['vis'] if 'acceptresults' in glb: del glb['acceptresults'] if 'minblperant' in glb: del glb['minblperant'] if 'solnorm' in glb: del glb['solnorm'] if 'maxchannels' in glb: del glb['maxchannels'] if 'phaseupsolint' in glb: del glb['phaseupsolint'] if 'combine' in glb: del glb['combine'] if 'bpsnr' in glb: del glb['bpsnr'] if 'bpnsols' in glb: del glb['bpnsols'] if 'hm_phaseup' in glb: del glb['hm_phaseup'] if 'solint' in glb: del glb['solint'] if 'evenbpints' in glb: del glb['evenbpints'] if 'hm_bandtype' in glb: del glb['hm_bandtype'] if 'caltable' in glb: del glb['caltable'] if 'hm_bandpass' in glb: del glb['hm_bandpass'] if 'degphase' in glb: del glb['degphase'] if 'spw' in glb: del glb['spw'] if 'parallel' in glb: del glb['parallel'] #--------- inp function ----------------------------------------------------------- def inp(self): print("# hifa_session_bandpass -- %s" % self._info_desc_) self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24)) self.__vis_inp( ) self.__caltable_inp( ) self.__field_inp( ) self.__intent_inp( ) self.__spw_inp( ) self.__antenna_inp( ) self.__hm_phaseup_inp( ) self.__phaseupsolint_inp( ) self.__phaseupbw_inp( ) self.__phaseupsnr_inp( ) self.__phaseupnsols_inp( ) self.__hm_bandpass_inp( ) self.__solint_inp( ) self.__maxchannels_inp( ) self.__evenbpints_inp( ) self.__bpsnr_inp( ) self.__minbpsnr_inp( ) self.__bpnsols_inp( ) self.__hm_bandtype_inp( ) self.__combine_inp( ) self.__refant_inp( ) self.__solnorm_inp( ) self.__minblperant_inp( ) self.__minsnr_inp( ) self.__degamp_inp( ) self.__degphase_inp( ) self.__pipelinemode_inp( ) self.__dryrun_inp( ) self.__acceptresults_inp( ) self.__parallel_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("hifa_session_bandpass.last"): filename = "hifa_session_bandpass.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, caltable=None, field=None, intent=None, spw=None, antenna=None, hm_phaseup=None, phaseupsolint=None, phaseupbw=None, phaseupsnr=None, phaseupnsols=None, hm_bandpass=None, solint=None, maxchannels=None, evenbpints=None, bpsnr=None, minbpsnr=None, bpnsols=None, hm_bandtype=None, combine=None, refant=None, solnorm=None, minblperant=None, minsnr=None, degamp=None, degphase=None, pipelinemode=None, dryrun=None, acceptresults=None, parallel=None ): def noobj(s): if s.startswith('<') and s.endswith('>'): return "None" else: return s _prefile = os.path.realpath('hifa_session_bandpass.pre') _postfile = os.path.realpath('hifa_session_bandpass.last') _return_result_ = None _arguments = [vis,caltable,field,intent,spw,antenna,hm_phaseup,phaseupsolint,phaseupbw,phaseupsnr,phaseupnsols,hm_bandpass,solint,maxchannels,evenbpints,bpsnr,minbpsnr,bpnsols,hm_bandtype,combine,refant,solnorm,minblperant,minsnr,degamp,degphase,pipelinemode,dryrun,acceptresults,parallel] _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_phaseup is not None: local_global['hm_phaseup'] = hm_phaseup if hm_bandpass is not None: local_global['hm_bandpass'] = hm_bandpass if hm_bandtype is not None: local_global['hm_bandtype'] = hm_bandtype if combine is not None: local_global['combine'] = combine if solnorm is not None: local_global['solnorm'] = solnorm 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_phaseup'] = self.__hm_phaseup( local_global ) _invocation_parameters['hm_bandpass'] = self.__hm_bandpass( local_global ) _invocation_parameters['hm_bandtype'] = self.__hm_bandtype( local_global ) _invocation_parameters['combine'] = self.__combine( local_global ) _invocation_parameters['solnorm'] = self.__solnorm( 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['caltable'] = self.__caltable( _invocation_parameters ) if caltable is None else caltable _invocation_parameters['field'] = self.__field( _invocation_parameters ) if field is None else field _invocation_parameters['intent'] = self.__intent( _invocation_parameters ) if intent is None else intent _invocation_parameters['spw'] = self.__spw( _invocation_parameters ) if spw is None else spw _invocation_parameters['antenna'] = self.__antenna( _invocation_parameters ) if antenna is None else antenna _invocation_parameters['phaseupsolint'] = self.__phaseupsolint( _invocation_parameters ) if phaseupsolint is None else phaseupsolint _invocation_parameters['phaseupbw'] = self.__phaseupbw( _invocation_parameters ) if phaseupbw is None else phaseupbw _invocation_parameters['phaseupsnr'] = self.__phaseupsnr( _invocation_parameters ) if phaseupsnr is None else phaseupsnr _invocation_parameters['phaseupnsols'] = self.__phaseupnsols( _invocation_parameters ) if phaseupnsols is None else phaseupnsols _invocation_parameters['solint'] = self.__solint( _invocation_parameters ) if solint is None else solint _invocation_parameters['maxchannels'] = self.__maxchannels( _invocation_parameters ) if maxchannels is None else maxchannels _invocation_parameters['evenbpints'] = self.__evenbpints( _invocation_parameters ) if evenbpints is None else evenbpints _invocation_parameters['bpsnr'] = self.__bpsnr( _invocation_parameters ) if bpsnr is None else bpsnr _invocation_parameters['minbpsnr'] = self.__minbpsnr( _invocation_parameters ) if minbpsnr is None else minbpsnr _invocation_parameters['bpnsols'] = self.__bpnsols( _invocation_parameters ) if bpnsols is None else bpnsols _invocation_parameters['refant'] = self.__refant( _invocation_parameters ) if refant is None else refant _invocation_parameters['minblperant'] = self.__minblperant( _invocation_parameters ) if minblperant is None else minblperant _invocation_parameters['minsnr'] = self.__minsnr( _invocation_parameters ) if minsnr is None else minsnr _invocation_parameters['degamp'] = self.__degamp( _invocation_parameters ) if degamp is None else degamp _invocation_parameters['degphase'] = self.__degphase( _invocation_parameters ) if degphase is None else degphase _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 _invocation_parameters['parallel'] = self.__parallel( _invocation_parameters ) if parallel is None else parallel else: # invoke with inp/go semantics _invocation_parameters['vis'] = self.__vis( self.__globals_( ) ) _invocation_parameters['caltable'] = self.__caltable( self.__globals_( ) ) _invocation_parameters['field'] = self.__field( self.__globals_( ) ) _invocation_parameters['intent'] = self.__intent( self.__globals_( ) ) _invocation_parameters['spw'] = self.__spw( self.__globals_( ) ) _invocation_parameters['antenna'] = self.__antenna( self.__globals_( ) ) _invocation_parameters['hm_phaseup'] = self.__hm_phaseup( self.__globals_( ) ) _invocation_parameters['phaseupsolint'] = self.__phaseupsolint( self.__globals_( ) ) _invocation_parameters['phaseupbw'] = self.__phaseupbw( self.__globals_( ) ) _invocation_parameters['phaseupsnr'] = self.__phaseupsnr( self.__globals_( ) ) _invocation_parameters['phaseupnsols'] = self.__phaseupnsols( self.__globals_( ) ) _invocation_parameters['hm_bandpass'] = self.__hm_bandpass( self.__globals_( ) ) _invocation_parameters['solint'] = self.__solint( self.__globals_( ) ) _invocation_parameters['maxchannels'] = self.__maxchannels( self.__globals_( ) ) _invocation_parameters['evenbpints'] = self.__evenbpints( self.__globals_( ) ) _invocation_parameters['bpsnr'] = self.__bpsnr( self.__globals_( ) ) _invocation_parameters['minbpsnr'] = self.__minbpsnr( self.__globals_( ) ) _invocation_parameters['bpnsols'] = self.__bpnsols( self.__globals_( ) ) _invocation_parameters['hm_bandtype'] = self.__hm_bandtype( self.__globals_( ) ) _invocation_parameters['combine'] = self.__combine( self.__globals_( ) ) _invocation_parameters['refant'] = self.__refant( self.__globals_( ) ) _invocation_parameters['solnorm'] = self.__solnorm( self.__globals_( ) ) _invocation_parameters['minblperant'] = self.__minblperant( self.__globals_( ) ) _invocation_parameters['minsnr'] = self.__minsnr( self.__globals_( ) ) _invocation_parameters['degamp'] = self.__degamp( self.__globals_( ) ) _invocation_parameters['degphase'] = self.__degphase( self.__globals_( ) ) _invocation_parameters['pipelinemode'] = self.__pipelinemode( self.__globals_( ) ) _invocation_parameters['dryrun'] = self.__dryrun( self.__globals_( ) ) _invocation_parameters['acceptresults'] = self.__acceptresults( self.__globals_( ) ) _invocation_parameters['parallel'] = self.__parallel( 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("#hifa_session_bandpass( ") 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_ = _hifa_session_bandpass_t( _invocation_parameters['vis'],_invocation_parameters['caltable'],_invocation_parameters['field'],_invocation_parameters['intent'],_invocation_parameters['spw'],_invocation_parameters['antenna'],_invocation_parameters['hm_phaseup'],_invocation_parameters['phaseupsolint'],_invocation_parameters['phaseupbw'],_invocation_parameters['phaseupsnr'],_invocation_parameters['phaseupnsols'],_invocation_parameters['hm_bandpass'],_invocation_parameters['solint'],_invocation_parameters['maxchannels'],_invocation_parameters['evenbpints'],_invocation_parameters['bpsnr'],_invocation_parameters['minbpsnr'],_invocation_parameters['bpnsols'],_invocation_parameters['hm_bandtype'],_invocation_parameters['combine'],_invocation_parameters['refant'],_invocation_parameters['solnorm'],_invocation_parameters['minblperant'],_invocation_parameters['minsnr'],_invocation_parameters['degamp'],_invocation_parameters['degphase'],_invocation_parameters['pipelinemode'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'],_invocation_parameters['parallel'] ) except Exception as e: from traceback import format_exc from casatasks import casalog casalog.origin('hifa_session_bandpass') casalog.post("Exception Reported: Error in hifa_session_bandpass: %s" % str(e),'SEVERE') casalog.post(format_exc( )) _return_result_ = False try: os.rename(_prefile,_postfile) except: pass return _return_result_ hifa_session_bandpass = _hifa_session_bandpass( )