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

##################### generated by xml-casa (v2) from hifa_wvrgcalflag.xml ##########
##################### 577ef4569f3102f11f91a2abff540f1d ##############################
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_wvrgcalflag as _hifa_wvrgcalflag_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_wvrgcalflag: """ hifa_wvrgcalflag ---- Generate a gain table based on Water Vapor Radiometer data, interpolating over antennas with bad radiometers. This task will first identify for each vis whether it includes at least 3 antennas with Water Vapor Radiometer (WVR) data, and that the fraction of WVR antennas / all antennas exceeds the minimum threshold (ants_with_wvr_thresh). If there are not enough WVR antennas by number and/or fraction, then no WVR caltable is created and no WVR calibration will be applied to the corresponding vis. If there are enough WVR antennas, then the task proceeds as follows for each valid vis: First, generate a gain table based on the Water Vapor Radiometer data for each vis. Second, apply the WVR calibration to the data specified by 'flag_intent', calculate flagging 'views' showing the ratio 'phase-rms with WVR / phase-rms without WVR' for each scan. A ratio < 1 implies that the phase noise is improved, a score > 1 implies that it is made worse. Third, search the flagging views for antennas with anomalous high values. If any are found then recalculate the WVR calibration with the 'wvrflag' parameter set to ignore their data and interpolate results from other antennas according to 'maxdistm' and 'minnumants'. Fourth, after flagging, if the remaining unflagged antennas with WVR number fewer than 3, or represent a smaller fraction of antennas than the minimum threshold (ants_with_wvr_thresh), then the WVR calibration file is rejected and will not be merged into the context, i.e. not be used in subsequent calibration. Fifth, if the overall QA score for the final WVR correction of a vis file is greater than the value in 'accept_threshold' then make available the wvr calibration file for merging into the context and use in the subsequent reduction. --------- parameter descriptions --------------------------------------------- vis List of input visibility files. default: none, in which case the vis files to be used will be read from the context example: vis=['ngc5921.ms'] caltable List of output gain calibration tables. default: none, in which case the names of the caltables will be generated automatically example: caltable='ngc5921.wvr' offsetstable List of input temperature offsets table files to subtract from WVR measurements before calculating phase corrections. default: none, in which case no offsets are applied example: offsetstable=['ngc5921.cloud_offsets'] hm_toffset If 'manual', set the 'toffset' parameter to the user-specified value. If 'automatic', set the 'toffset' parameter according to the date of the MeasurementSet; toffset=-1 if before 2013-01-21T00:00:00 toffset=0 otherwise. toffset Time offset (sec) between interferometric and WVR data. segsource If True calculate new atmospheric phase correction coefficients for each source, subject to the constraints of the 'tie' parameter. 'segsource' is forced to be True if the 'tie' parameter is set to a non-empty value by the user or by the automatic heuristic. sourceflag Flag the WVR data for these source(s) as bad and do not produce corrections for it. Requires segsource=True. example: sourceflag=['3C273'] hm_tie If 'manual', set the 'tie' parameter to the user-specified value. If 'automatic', set the 'tie' parameter to include with the target all calibrators that are within 15 degrees of it: if no calibrators are that close then 'tie' is left empty. tie Use the same atmospheric phase correction coefficients when calculating the WVR correction for all sources in the 'tie'. If 'tie' is not empty then 'segsource' is forced to be True. Ignored unless hm_tie='manual'. example: tie=['3C273,NGC253', 'IC433,3C279'] nsol Number of solutions for phase correction coefficients during this observation, evenly distributed in time throughout the observation. It is used only if segsource=False because if segsource=True then the coefficients are recomputed whenever the telescope moves to a new source (within the limits imposed by 'tie'). disperse Apply correction for dispersion. wvrflag Flag the WVR data for these antenna(s) as bad and replace its data with interpolated values. example: wvrflag=['DV03','DA05','PM02'] hm_smooth If 'manual' set the 'smooth' parameter to the user-specified value. If 'automatic', run the wvrgcal task with the range of 'smooth' parameters required to match the integration time of the WVR data to that of the interferometric data in each spectral window. smooth Smooth WVR data on this timescale before calculating the correction. Ignored unless hm_smooth='manual'. scale Scale the entire phase correction by this factor. maxdistm tance in meters of an antenna used for interpolation from a flagged antenna. default: -1 (automatically set to 100m if >50% of antennas are 7m antennas without WVR and otherwise set to 500m) example: maxdistm=550 minnumants Minimum number of nearby antennas (up to 3) used for interpolation from a flagged antenna. example: minnumants=3 mingoodfrac Minimum fraction of good data per antenna. example: mingoodfrac=0.7 refant Ranked comma delimited list of reference antennas. example: refant='DV02,DV06' flag_intent The data intent(s) on whose WVR correction results the search for bad WVR antennas is to be based. A 'flagging view' will be calculated for each specified intent, in each spectral window in each vis file. Each 'flagging view' will consist of a 2-d image with dimensions ['ANTENNA', 'TIME'], showing the phase noise after the WVR correction has been applied. If flag_intent is left blank, the default, the flagging views will be derived from data with the default bandpass calibration intent i.e. the first in the list BANDPASS, PHASE, AMPLITUDE for which the MeasurementSet has data. qa_intent The list of data intents on which the WVR correction is to be tried as a means of estimating its effectiveness. A QA 'view' will be calculated for each specified intent, in each spectral window in each vis file. Each QA 'view' will consist of a pair of 2-d images with dimensions ['ANTENNA', 'TIME'], one showing the data phase-noise before the WVR application, the second showing the phase noise after (both 'before' and 'after' images have a bandpass calibration applied as well). An overall QA score is calculated for each vis file, by dividing the 'before' images by the 'after' and taking the median of the result. An overall score of 1 would correspond to no change in the phase noise, a score > 1 implies an improvement. If the overall score for a vis file is less than the value in 'accept_threshold' then the WVR calibration file is not made available for merging into the context for use in the subsequent reduction. qa_bandpass_intent The data intent to use for the bandpass calibration in the qa calculation. The default is blank to allow the underlying bandpass task to select a sensible intent if the dataset lacks BANDPASS data. accept_threshold The phase-rms improvement ratio (rms without WVR / rms with WVR) above which the wrvg file will be accepted into the context for subsequent application. flag_hi True to flag high figure of merit outliers. fhi_limit Flag figure of merit values higher than limit * MAD. fhi_minsample Minimum number of samples for valid MAD estimate/ ants_with_wvr_thresh this threshold sets the minimum fraction of antennas that should have WVR data for WVR calibration and flagging to proceed; the same threshold is used to determine, after flagging, whether there remain enough unflagged antennas with WVR data for the WVR calibration to be applied. example: ants_with_wvr_thresh=0.5 pipelinemode The pipeline operating mode dryrun Run the task (False) or display the command(True) acceptresults Add the results to the pipeline context --------- examples ----------------------------------------------------------- 1. Compute the WVR calibration for all the MeasurementSets: hifa_wvrgcalflag(hm_tie='automatic') """ _info_group_ = """pipeline""" _info_desc_ = """ Generate a gain table based on Water Vapor Radiometer data, interpolating over antennas with bad radiometers. """ __schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'caltable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'offsetstable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_toffset': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'manual', 'automatic' ]}, 'toffset': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'segsource': {'type': 'cBool'}, 'sourceflag': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_tie': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'manual' ]}, 'tie': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'nsol': {'type': 'cInt'}, 'disperse': {'type': 'cBool'}, 'wvrflag': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_smooth': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'manual' ]}, 'smooth': {'type': 'cStr', 'coerce': _coerce.to_str}, 'scale': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'maxdistm': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'minnumants': {'type': 'cInt', 'allowed': [ 1, 2, 3 ]}, 'mingoodfrac': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'refant': {'type': 'cStr', 'coerce': _coerce.to_str}, 'flag_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_bandpass_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'accept_threshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'flag_hi': {'type': 'cBool'}, 'fhi_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'fhi_minsample': {'type': 'cInt'}, 'ants_with_wvr_thresh': {'type': 'cFloat', 'coerce': _coerce.to_float}, '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 + 20 + 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 __minnumants_dflt( self, glb ): return int(2) def __minnumants( self, glb ): if 'minnumants' in glb: return glb['minnumants'] return int(2) def __accept_threshold_dflt( self, glb ): return float(1.0) def __accept_threshold( self, glb ): if 'accept_threshold' in glb: return glb['accept_threshold'] return float(1.0) def __ants_with_wvr_thresh_dflt( self, glb ): return float(0.2) def __ants_with_wvr_thresh( self, glb ): if 'ants_with_wvr_thresh' in glb: return glb['ants_with_wvr_thresh'] return float(0.2) def __hm_smooth_dflt( self, glb ): return 'automatic' def __hm_smooth( self, glb ): if 'hm_smooth' in glb: return glb['hm_smooth'] return 'automatic' def __maxdistm_dflt( self, glb ): return float(-1) def __maxdistm( self, glb ): if 'maxdistm' in glb: return glb['maxdistm'] return float(-1) def __hm_tie_dflt( self, glb ): return 'automatic' def __hm_tie( self, glb ): if 'hm_tie' in glb: return glb['hm_tie'] return 'automatic' def __hm_toffset_dflt( self, glb ): return 'automatic' def __hm_toffset( self, glb ): if 'hm_toffset' in glb: return glb['hm_toffset'] return 'automatic' def __disperse_dflt( self, glb ): return False def __disperse( self, glb ): if 'disperse' in glb: return glb['disperse'] return False def __flag_hi_dflt( self, glb ): return True def __flag_hi( self, glb ): if 'flag_hi' in glb: return glb['flag_hi'] return True def __qa_bandpass_intent_dflt( self, glb ): return '' def __qa_bandpass_intent( self, glb ): if 'qa_bandpass_intent' in glb: return glb['qa_bandpass_intent'] return '' def __flag_intent_dflt( self, glb ): return '' def __flag_intent( self, glb ): if 'flag_intent' in glb: return glb['flag_intent'] return '' def __pipelinemode_dflt( self, glb ): return 'automatic' def __pipelinemode( self, glb ): if 'pipelinemode' in glb: return glb['pipelinemode'] return 'automatic' def __qa_intent_dflt( self, glb ): return 'BANDPASS,PHASE' def __qa_intent( self, glb ): if 'qa_intent' in glb: return glb['qa_intent'] return 'BANDPASS,PHASE' def __mingoodfrac_dflt( self, glb ): return float(0.8) def __mingoodfrac( self, glb ): if 'mingoodfrac' in glb: return glb['mingoodfrac'] return float(0.8) #--------- return inp/go default -------------------------------------------------- def __dryrun_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(False) return None def __toffset_dflt( self, glb ): if self.__hm_toffset( glb ) == "manual": return float(0) return None def __fhi_limit_dflt( self, glb ): if self.__flag_hi( glb ) == bool(True): return float(10.0) return None def __tie_dflt( self, glb ): if self.__hm_tie( glb ) == "manual": return [] return None def __smooth_dflt( self, glb ): if self.__hm_smooth( glb ) == "manual": return "" return None def __scale_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return float(1.0) if self.__pipelinemode( glb ) == "getinputs": return float(1.0) return None def __offsetstable_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] return None def __refant_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 __sourceflag_dflt( self, glb ): if self.__hm_tie( glb ) == "manual": return [] return None def __wvrflag_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] return None def __nsol_dflt( self, glb ): if self.__hm_tie( glb ) == "manual": return int(1) return None def __segsource_dflt( self, glb ): if self.__hm_tie( glb ) == "manual": return bool(False) return None def __fhi_minsample_dflt( self, glb ): if self.__flag_hi( glb ) == bool(True): return int(5) return None def __caltable_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] 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 __offsetstable( self, glb ): if 'offsetstable' in glb: return glb['offsetstable'] dflt = self.__offsetstable_dflt( glb ) if dflt is not None: return dflt return [ ] def __toffset( self, glb ): if 'toffset' in glb: return glb['toffset'] dflt = self.__toffset_dflt( glb ) if dflt is not None: return dflt return float(0) def __segsource( self, glb ): if 'segsource' in glb: return glb['segsource'] dflt = self.__segsource_dflt( glb ) if dflt is not None: return dflt return True def __sourceflag( self, glb ): if 'sourceflag' in glb: return glb['sourceflag'] dflt = self.__sourceflag_dflt( glb ) if dflt is not None: return dflt return [ ] def __tie( self, glb ): if 'tie' in glb: return glb['tie'] dflt = self.__tie_dflt( glb ) if dflt is not None: return dflt return [ ] def __nsol( self, glb ): if 'nsol' in glb: return glb['nsol'] dflt = self.__nsol_dflt( glb ) if dflt is not None: return dflt return int(1) def __wvrflag( self, glb ): if 'wvrflag' in glb: return glb['wvrflag'] dflt = self.__wvrflag_dflt( glb ) if dflt is not None: return dflt return [ ] def __smooth( self, glb ): if 'smooth' in glb: return glb['smooth'] dflt = self.__smooth_dflt( glb ) if dflt is not None: return dflt return '' def __scale( self, glb ): if 'scale' in glb: return glb['scale'] dflt = self.__scale_dflt( glb ) if dflt is not None: return dflt return float(1) 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 __fhi_limit( self, glb ): if 'fhi_limit' in glb: return glb['fhi_limit'] dflt = self.__fhi_limit_dflt( glb ) if dflt is not None: return dflt return float(10.0) def __fhi_minsample( self, glb ): if 'fhi_minsample' in glb: return glb['fhi_minsample'] dflt = self.__fhi_minsample_dflt( glb ) if dflt is not None: return dflt return int(5) 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 visibility files' 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%-17.17s =\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 gain calibration tables' 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%-17.17s =\x1B[0m %s%-23s%s' % ('caltable',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __offsetstable_inp(self): if self.__offsetstable_dflt( self.__globals_( ) ) is not None: description = 'List of input temperature offsets table files' value = self.__offsetstable( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'offsetstable': value},{'offsetstable': self.__schema['offsetstable']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('offsetstable',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_toffset_inp(self): description = 'Toffset computation heuristic method' value = self.__hm_toffset( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_toffset': value},{'hm_toffset': self.__schema['hm_toffset']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_toffset',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __toffset_inp(self): if self.__toffset_dflt( self.__globals_( ) ) is not None: description = 'Time offset (sec) between IF and WVR data' value = self.__toffset( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'toffset': value},{'toffset': self.__schema['toffset']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('toffset',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __segsource_inp(self): if self.__segsource_dflt( self.__globals_( ) ) is not None: description = 'Compute new coefficient calculation for each source' value = self.__segsource( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'segsource': value},{'segsource': self.__schema['segsource']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('segsource',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __sourceflag_inp(self): if self.__sourceflag_dflt( self.__globals_( ) ) is not None: description = 'Flag the WVR data for these source(s)' value = self.__sourceflag( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'sourceflag': value},{'sourceflag': self.__schema['sourceflag']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('sourceflag',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_tie_inp(self): description = 'Tie computation heuristics method' value = self.__hm_tie( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_tie': value},{'hm_tie': self.__schema['hm_tie']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_tie',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __tie_inp(self): if self.__tie_dflt( self.__globals_( ) ) is not None: description = 'Sources for which to use the same atmospheric phase correction coefficients' value = self.__tie( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'tie': value},{'tie': self.__schema['tie']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('tie',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __nsol_inp(self): if self.__nsol_dflt( self.__globals_( ) ) is not None: description = 'Number of solutions for phase correction coefficients' value = self.__nsol( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'nsol': value},{'nsol': self.__schema['nsol']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('nsol',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __disperse_inp(self): description = 'Apply correction for dispersion' value = self.__disperse( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'disperse': value},{'disperse': self.__schema['disperse']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('disperse',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __wvrflag_inp(self): if self.__wvrflag_dflt( self.__globals_( ) ) is not None: description = 'Flag the WVR data for these antenna(s) replace with interpolated values' value = self.__wvrflag( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'wvrflag': value},{'wvrflag': self.__schema['wvrflag']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('wvrflag',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __hm_smooth_inp(self): description = 'Smoothing computation heuristics method' value = self.__hm_smooth( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'hm_smooth': value},{'hm_smooth': self.__schema['hm_smooth']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-20.20s =\x1B[0m %s%-23s%s' % ('hm_smooth',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __smooth_inp(self): if self.__smooth_dflt( self.__globals_( ) ) is not None: description = 'Smooth WVR data on the given timescale before calculating the correction' value = self.__smooth( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'smooth': value},{'smooth': self.__schema['smooth']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('smooth',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __scale_inp(self): if self.__scale_dflt( self.__globals_( ) ) is not None: description = 'Scale the entire phase correction by this factor' value = self.__scale( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'scale': value},{'scale': self.__schema['scale']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('scale',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __maxdistm_inp(self): description = 'Maximum distance (m) of an antenna used for interpolation for a flagged antenna' value = self.__maxdistm( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'maxdistm': value},{'maxdistm': self.__schema['maxdistm']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('maxdistm',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __minnumants_inp(self): description = 'Minimum number of near antennas (up to 3) required for interpolation' value = self.__minnumants( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'minnumants': value},{'minnumants': self.__schema['minnumants']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('minnumants',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __mingoodfrac_inp(self): description = 'Minimum fraction of good data per antenna' value = self.__mingoodfrac( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'mingoodfrac': value},{'mingoodfrac': self.__schema['mingoodfrac']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('mingoodfrac',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 = 'Ranked list of reference antennas' 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%-17.17s =\x1B[0m %s%-23s%s' % ('refant',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_intent_inp(self): description = 'Data intents to use in detecting and flagging bad WVR antennas' value = self.__flag_intent( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_intent': value},{'flag_intent': self.__schema['flag_intent']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('flag_intent',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __qa_intent_inp(self): description = 'Data intents to use in estimating the effectiveness of the WVR correction' value = self.__qa_intent( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'qa_intent': value},{'qa_intent': self.__schema['qa_intent']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('qa_intent',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __qa_bandpass_intent_inp(self): description = 'Data intent to use for the bandpass calibration in the qa calculation' value = self.__qa_bandpass_intent( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'qa_bandpass_intent': value},{'qa_bandpass_intent': self.__schema['qa_bandpass_intent']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('qa_bandpass_intent',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __accept_threshold_inp(self): description = 'Improvement ratio (phase-rms without WVR / phase-rms with WVR) above which wvrg calibration file will be accepted' value = self.__accept_threshold( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'accept_threshold': value},{'accept_threshold': self.__schema['accept_threshold']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('accept_threshold',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __flag_hi_inp(self): description = 'True to flag high figure of merit outliers' value = self.__flag_hi( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_hi': value},{'flag_hi': self.__schema['flag_hi']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-20.20s =\x1B[0m %s%-23s%s' % ('flag_hi',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __fhi_limit_inp(self): if self.__fhi_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag figure of merit values higher than limit * MAD' value = self.__fhi_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fhi_limit': value},{'fhi_limit': self.__schema['fhi_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('fhi_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __fhi_minsample_inp(self): if self.__fhi_minsample_dflt( self.__globals_( ) ) is not None: description = 'Minimum number of samples for valid MAD estimate' value = self.__fhi_minsample( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fhi_minsample': value},{'fhi_minsample': self.__schema['fhi_minsample']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-17.17s =\x1B[0m %s%-23s%s' % ('fhi_minsample',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __ants_with_wvr_thresh_inp(self): description = 'Minimum fraction of unflagged antennas that need to have WVR for calibration to proceed.' value = self.__ants_with_wvr_thresh( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'ants_with_wvr_thresh': value},{'ants_with_wvr_thresh': self.__schema['ants_with_wvr_thresh']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-20.20s = %s%-23s%s' % ('ants_with_wvr_thresh',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%-20.20s =\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%-17.17s =\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%-17.17s =\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 'accept_threshold' in glb: del glb['accept_threshold'] if 'ants_with_wvr_thresh' in glb: del glb['ants_with_wvr_thresh'] if 'dryrun' in glb: del glb['dryrun'] if 'toffset' in glb: del glb['toffset'] if 'fhi_limit' in glb: del glb['fhi_limit'] if 'tie' in glb: del glb['tie'] if 'disperse' in glb: del glb['disperse'] if 'smooth' in glb: del glb['smooth'] if 'pipelinemode' in glb: del glb['pipelinemode'] if 'scale' in glb: del glb['scale'] if 'mingoodfrac' in glb: del glb['mingoodfrac'] if 'minnumants' in glb: del glb['minnumants'] if 'offsetstable' in glb: del glb['offsetstable'] if 'refant' in glb: del glb['refant'] if 'flag_intent' in glb: del glb['flag_intent'] if 'vis' in glb: del glb['vis'] if 'acceptresults' in glb: del glb['acceptresults'] if 'qa_intent' in glb: del glb['qa_intent'] if 'sourceflag' in glb: del glb['sourceflag'] if 'wvrflag' in glb: del glb['wvrflag'] if 'hm_toffset' in glb: del glb['hm_toffset'] if 'flag_hi' in glb: del glb['flag_hi'] if 'maxdistm' in glb: del glb['maxdistm'] if 'hm_smooth' in glb: del glb['hm_smooth'] if 'nsol' in glb: del glb['nsol'] if 'qa_bandpass_intent' in glb: del glb['qa_bandpass_intent'] if 'hm_tie' in glb: del glb['hm_tie'] if 'segsource' in glb: del glb['segsource'] if 'fhi_minsample' in glb: del glb['fhi_minsample'] if 'caltable' in glb: del glb['caltable'] #--------- inp function ----------------------------------------------------------- def inp(self): print("# hifa_wvrgcalflag -- %s" % self._info_desc_) self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24)) self.__vis_inp( ) self.__caltable_inp( ) self.__offsetstable_inp( ) self.__hm_toffset_inp( ) self.__toffset_inp( ) self.__segsource_inp( ) self.__sourceflag_inp( ) self.__hm_tie_inp( ) self.__tie_inp( ) self.__nsol_inp( ) self.__disperse_inp( ) self.__wvrflag_inp( ) self.__hm_smooth_inp( ) self.__smooth_inp( ) self.__scale_inp( ) self.__maxdistm_inp( ) self.__minnumants_inp( ) self.__mingoodfrac_inp( ) self.__refant_inp( ) self.__flag_intent_inp( ) self.__qa_intent_inp( ) self.__qa_bandpass_intent_inp( ) self.__accept_threshold_inp( ) self.__flag_hi_inp( ) self.__fhi_limit_inp( ) self.__fhi_minsample_inp( ) self.__ants_with_wvr_thresh_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("hifa_wvrgcalflag.last"): filename = "hifa_wvrgcalflag.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, offsetstable=None, hm_toffset=None, toffset=None, segsource=None, sourceflag=None, hm_tie=None, tie=None, nsol=None, disperse=None, wvrflag=None, hm_smooth=None, smooth=None, scale=None, maxdistm=None, minnumants=None, mingoodfrac=None, refant=None, flag_intent=None, qa_intent=None, qa_bandpass_intent=None, accept_threshold=None, flag_hi=None, fhi_limit=None, fhi_minsample=None, ants_with_wvr_thresh=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('hifa_wvrgcalflag.pre') _postfile = os.path.realpath('hifa_wvrgcalflag.last') _return_result_ = None _arguments = [vis,caltable,offsetstable,hm_toffset,toffset,segsource,sourceflag,hm_tie,tie,nsol,disperse,wvrflag,hm_smooth,smooth,scale,maxdistm,minnumants,mingoodfrac,refant,flag_intent,qa_intent,qa_bandpass_intent,accept_threshold,flag_hi,fhi_limit,fhi_minsample,ants_with_wvr_thresh,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_toffset is not None: local_global['hm_toffset'] = hm_toffset if hm_tie is not None: local_global['hm_tie'] = hm_tie if disperse is not None: local_global['disperse'] = disperse if hm_smooth is not None: local_global['hm_smooth'] = hm_smooth if maxdistm is not None: local_global['maxdistm'] = maxdistm if minnumants is not None: local_global['minnumants'] = minnumants if mingoodfrac is not None: local_global['mingoodfrac'] = mingoodfrac if flag_intent is not None: local_global['flag_intent'] = flag_intent if qa_intent is not None: local_global['qa_intent'] = qa_intent if qa_bandpass_intent is not None: local_global['qa_bandpass_intent'] = qa_bandpass_intent if accept_threshold is not None: local_global['accept_threshold'] = accept_threshold if flag_hi is not None: local_global['flag_hi'] = flag_hi if ants_with_wvr_thresh is not None: local_global['ants_with_wvr_thresh'] = ants_with_wvr_thresh 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_toffset'] = self.__hm_toffset( local_global ) _invocation_parameters['hm_tie'] = self.__hm_tie( local_global ) _invocation_parameters['disperse'] = self.__disperse( local_global ) _invocation_parameters['hm_smooth'] = self.__hm_smooth( local_global ) _invocation_parameters['maxdistm'] = self.__maxdistm( local_global ) _invocation_parameters['minnumants'] = self.__minnumants( local_global ) _invocation_parameters['mingoodfrac'] = self.__mingoodfrac( local_global ) _invocation_parameters['flag_intent'] = self.__flag_intent( local_global ) _invocation_parameters['qa_intent'] = self.__qa_intent( local_global ) _invocation_parameters['qa_bandpass_intent'] = self.__qa_bandpass_intent( local_global ) _invocation_parameters['accept_threshold'] = self.__accept_threshold( local_global ) _invocation_parameters['flag_hi'] = self.__flag_hi( local_global ) _invocation_parameters['ants_with_wvr_thresh'] = self.__ants_with_wvr_thresh( 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['offsetstable'] = self.__offsetstable( _invocation_parameters ) if offsetstable is None else offsetstable _invocation_parameters['toffset'] = self.__toffset( _invocation_parameters ) if toffset is None else toffset _invocation_parameters['segsource'] = self.__segsource( _invocation_parameters ) if segsource is None else segsource _invocation_parameters['sourceflag'] = self.__sourceflag( _invocation_parameters ) if sourceflag is None else sourceflag _invocation_parameters['tie'] = self.__tie( _invocation_parameters ) if tie is None else tie _invocation_parameters['nsol'] = self.__nsol( _invocation_parameters ) if nsol is None else nsol _invocation_parameters['wvrflag'] = self.__wvrflag( _invocation_parameters ) if wvrflag is None else wvrflag _invocation_parameters['smooth'] = self.__smooth( _invocation_parameters ) if smooth is None else smooth _invocation_parameters['scale'] = self.__scale( _invocation_parameters ) if scale is None else scale _invocation_parameters['refant'] = self.__refant( _invocation_parameters ) if refant is None else refant _invocation_parameters['fhi_limit'] = self.__fhi_limit( _invocation_parameters ) if fhi_limit is None else fhi_limit _invocation_parameters['fhi_minsample'] = self.__fhi_minsample( _invocation_parameters ) if fhi_minsample is None else fhi_minsample _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['caltable'] = self.__caltable( self.__globals_( ) ) _invocation_parameters['offsetstable'] = self.__offsetstable( self.__globals_( ) ) _invocation_parameters['hm_toffset'] = self.__hm_toffset( self.__globals_( ) ) _invocation_parameters['toffset'] = self.__toffset( self.__globals_( ) ) _invocation_parameters['segsource'] = self.__segsource( self.__globals_( ) ) _invocation_parameters['sourceflag'] = self.__sourceflag( self.__globals_( ) ) _invocation_parameters['hm_tie'] = self.__hm_tie( self.__globals_( ) ) _invocation_parameters['tie'] = self.__tie( self.__globals_( ) ) _invocation_parameters['nsol'] = self.__nsol( self.__globals_( ) ) _invocation_parameters['disperse'] = self.__disperse( self.__globals_( ) ) _invocation_parameters['wvrflag'] = self.__wvrflag( self.__globals_( ) ) _invocation_parameters['hm_smooth'] = self.__hm_smooth( self.__globals_( ) ) _invocation_parameters['smooth'] = self.__smooth( self.__globals_( ) ) _invocation_parameters['scale'] = self.__scale( self.__globals_( ) ) _invocation_parameters['maxdistm'] = self.__maxdistm( self.__globals_( ) ) _invocation_parameters['minnumants'] = self.__minnumants( self.__globals_( ) ) _invocation_parameters['mingoodfrac'] = self.__mingoodfrac( self.__globals_( ) ) _invocation_parameters['refant'] = self.__refant( self.__globals_( ) ) _invocation_parameters['flag_intent'] = self.__flag_intent( self.__globals_( ) ) _invocation_parameters['qa_intent'] = self.__qa_intent( self.__globals_( ) ) _invocation_parameters['qa_bandpass_intent'] = self.__qa_bandpass_intent( self.__globals_( ) ) _invocation_parameters['accept_threshold'] = self.__accept_threshold( self.__globals_( ) ) _invocation_parameters['flag_hi'] = self.__flag_hi( self.__globals_( ) ) _invocation_parameters['fhi_limit'] = self.__fhi_limit( self.__globals_( ) ) _invocation_parameters['fhi_minsample'] = self.__fhi_minsample( self.__globals_( ) ) _invocation_parameters['ants_with_wvr_thresh'] = self.__ants_with_wvr_thresh( 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("%-20s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i])))) _f.write("#hifa_wvrgcalflag( ") 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_wvrgcalflag_t( _invocation_parameters['vis'],_invocation_parameters['caltable'],_invocation_parameters['offsetstable'],_invocation_parameters['hm_toffset'],_invocation_parameters['toffset'],_invocation_parameters['segsource'],_invocation_parameters['sourceflag'],_invocation_parameters['hm_tie'],_invocation_parameters['tie'],_invocation_parameters['nsol'],_invocation_parameters['disperse'],_invocation_parameters['wvrflag'],_invocation_parameters['hm_smooth'],_invocation_parameters['smooth'],_invocation_parameters['scale'],_invocation_parameters['maxdistm'],_invocation_parameters['minnumants'],_invocation_parameters['mingoodfrac'],_invocation_parameters['refant'],_invocation_parameters['flag_intent'],_invocation_parameters['qa_intent'],_invocation_parameters['qa_bandpass_intent'],_invocation_parameters['accept_threshold'],_invocation_parameters['flag_hi'],_invocation_parameters['fhi_limit'],_invocation_parameters['fhi_minsample'],_invocation_parameters['ants_with_wvr_thresh'],_invocation_parameters['pipelinemode'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'] ) except Exception as e: from traceback import format_exc from casatasks import casalog casalog.origin('hifa_wvrgcalflag') casalog.post("Exception Reported: Error in hifa_wvrgcalflag: %s" % str(e),'SEVERE') casalog.post(format_exc( )) _return_result_ = False try: os.rename(_prefile,_postfile) except: pass return _return_result_ hifa_wvrgcalflag = _hifa_wvrgcalflag( )