##################### generated by xml-casa (v2) from hifa_wvrgcal.xml ##############
##################### 6cb055d7c8307b96c81fab81131fe1f8 ##############################
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_wvrgcal as _hifa_wvrgcal_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_wvrgcal:
"""
hifa_wvrgcal ----
Generate a gain table based on Water Vapor Radiometer data, and calculate
a QA score based on its effect on the interferometric data.
Generate a gain table based on the Water Vapor Radiometer data in each vis
file. By applying the wvr calibration to the data specified by 'qa_intent' and
'qa_spw', calculate a QA score to indicate its effect on interferometric data;
a score > 1 implies that the phase noise is improved, a score < 1 implies
that it is made worse. If the score is less than 'accept_threshold' then the
wvr gain table is not accepted into the context for subsequent use.
--------- 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: ['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: ['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 the listed antennas as bad and replace
their data with values interpolated from the 3 nearest antennas with
unflagged data.
example: ['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 Maximum distance 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.
refant Ranked comma delimited list of reference antennas.
example: refant='DV01,DV02'
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.
If you do not want any QA calculations then set qa_intent=''.
example: qa_intent='PHASE'
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.
qa_spw The SpW(s) to use for the qa calculation, in the order that they
should be tried. Input as a comma-separated list. The default is blank, in
which case the task will try SpWs in order of decreasing median sky
opacity.
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.
pipelinemode
dryrun
acceptresults
--------- examples -----------------------------------------------------------
Example
1. Compute the WVR calibration for all the MeasurementSets:
hifa_wvrgcal(hm_tie='automatic')
"""
_info_group_ = """pipeline"""
_info_desc_ = """
Generate a gain table based on Water Vapor Radiometer data, and calculate
a QA score based on its effect on the interferometric data.
"""
__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': [ 'manual', 'automatic' ]}, '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': [ 'manual', 'automatic' ]}, '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}, 'qa_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_bandpass_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'accept_threshold': {'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 + 18 + 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 __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 __qa_intent_dflt( self, glb ):
return ''
def __qa_intent( self, glb ):
if 'qa_intent' in glb: return glb['qa_intent']
return ''
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 __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 __pipelinemode_dflt( self, glb ):
return 'automatic'
def __pipelinemode( self, glb ):
if 'pipelinemode' in glb: return glb['pipelinemode']
return 'automatic'
def __mingoodfrac_dflt( self, glb ):
return float(0.8)
def __mingoodfrac( self, glb ):
if 'mingoodfrac' in glb: return glb['mingoodfrac']
return float(0.8)
def __qa_spw_dflt( self, glb ):
return ''
def __qa_spw( self, glb ):
if 'qa_spw' in glb: return glb['qa_spw']
return ''
#--------- return non subparam/when values ---------------------------------------------
def __segsource( self, glb ):
if 'segsource' in glb: return glb['segsource']
return True
#--------- 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 __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 __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 __sourceflag( self, glb ):
if 'sourceflag' in glb: return glb['sourceflag']
dflt = self.__sourceflag_dflt( glb )
if dflt is not None: return dflt
return [ ]
def __hm_tie( self, glb ):
if 'hm_tie' in glb: return glb['hm_tie']
dflt = self.__hm_tie_dflt( glb )
if dflt is not None: return dflt
return 'automatic'
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 __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%-15.15s =\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%-15.15s =\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%-15.15s =\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%-18.18s =\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%-15.15s =\x1B[0m %s%-23s%s' % ('toffset',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __segsource_inp(self):
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('%-18.18s = %s%-23s%s' % ('segsource',pre,self.__to_string_(value),post),description,0+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%-15.15s =\x1B[0m %s%-23s%s' % ('sourceflag',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_tie_inp(self):
if self.__hm_tie_dflt( self.__globals_( ) ) is not None:
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[92m%-15.15s =\x1B[0m %s%-23s%s' % ('hm_tie',pre,self.__to_string_(value),post),description,9+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%-15.15s =\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%-15.15s =\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('%-18.18s = %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%-15.15s =\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%-18.18s =\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%-15.15s =\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%-15.15s =\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('%-18.18s = %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('%-18.18s = %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('%-18.18s = %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%-15.15s =\x1B[0m %s%-23s%s' % ('refant',pre,self.__to_string_(value),post),description,9+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('%-18.18s = %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('%-18.18s = %s%-23s%s' % ('qa_bandpass_intent',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __qa_spw_inp(self):
description = 'Data SpW(s) to use in estimating the effectiveness of the wvr correction'
value = self.__qa_spw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'qa_spw': value},{'qa_spw': self.__schema['qa_spw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-18.18s = %s%-23s%s' % ('qa_spw',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('%-18.18s = %s%-23s%s' % ('accept_threshold',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%-18.18s =\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%-15.15s =\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%-15.15s =\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 'dryrun' in glb: del glb['dryrun']
if 'toffset' in glb: del glb['toffset']
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 '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 '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 'caltable' in glb: del glb['caltable']
if 'qa_spw' in glb: del glb['qa_spw']
#--------- inp function -----------------------------------------------------------
def inp(self):
print("# hifa_wvrgcal -- %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.__qa_intent_inp( )
self.__qa_bandpass_intent_inp( )
self.__qa_spw_inp( )
self.__accept_threshold_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_wvrgcal.last"):
filename = "hifa_wvrgcal.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, qa_intent=None, qa_bandpass_intent=None, qa_spw=None, accept_threshold=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_wvrgcal.pre')
_postfile = os.path.realpath('hifa_wvrgcal.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,qa_intent,qa_bandpass_intent,qa_spw,accept_threshold,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 segsource is not None: local_global['segsource'] = segsource
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 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 qa_spw is not None: local_global['qa_spw'] = qa_spw
if accept_threshold is not None: local_global['accept_threshold'] = accept_threshold
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['segsource'] = self.__segsource( 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['qa_intent'] = self.__qa_intent( local_global )
_invocation_parameters['qa_bandpass_intent'] = self.__qa_bandpass_intent( local_global )
_invocation_parameters['qa_spw'] = self.__qa_spw( local_global )
_invocation_parameters['accept_threshold'] = self.__accept_threshold( 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['sourceflag'] = self.__sourceflag( _invocation_parameters ) if sourceflag is None else sourceflag
_invocation_parameters['hm_tie'] = self.__hm_tie( _invocation_parameters ) if hm_tie is None else hm_tie
_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['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['qa_intent'] = self.__qa_intent( self.__globals_( ) )
_invocation_parameters['qa_bandpass_intent'] = self.__qa_bandpass_intent( self.__globals_( ) )
_invocation_parameters['qa_spw'] = self.__qa_spw( self.__globals_( ) )
_invocation_parameters['accept_threshold'] = self.__accept_threshold( 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("%-18s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
_f.write("#hifa_wvrgcal( ")
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_wvrgcal_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['qa_intent'],_invocation_parameters['qa_bandpass_intent'],_invocation_parameters['qa_spw'],_invocation_parameters['accept_threshold'],_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_wvrgcal')
casalog.post("Exception Reported: Error in hifa_wvrgcal: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hifa_wvrgcal = _hifa_wvrgcal( )