##################### generated by xml-casa (v2) from hifv_flagdata.xml #############
##################### b7a521fa1a3c4ebc2f0c756f573c7446 ##############################
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.hifv.cli import hifv_flagdata as _hifv_flagdata_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 _hifv_flagdata:
"""
hifv_flagdata ---- Do basic deterministic flagging of a list of MeasurementSets
The hifv_flagdata task performs basic flagging operations on a list of
MeasurementSets.
The hifv_flagdata task performs basic flagging operations on a list of measurements including:
o autocorrelation data flagging
o shadowed antenna data flagging
o scan based flagging
o edge channel flagging
o baseband edge flagging
o applying online flags
o applying a flagging template
o quack, shadow, and basebands
o Antenna not-on-source (ANOS)
--------- parameter descriptions ---------------------------------------------
vis List of visibility data files. These may be ASDMs, tar files of ASDMs,
MSes, or tar files of MSes, If ASDM files are specified, they will be
converted to MS format.
example: vis=['X227.ms', 'asdms.tar.gz']
autocorr Flag autocorrelation data
shadow Flag shadowed antennas
scan Flag specified scans
scannumber A string containing a comma delimited list of scans to be flagged.
example: '3,5,6'
quack Quack scans
clip Clip mode
baseband Flag 20MHz of each edge of basebands
intents A string containing a comma delimited list of intents against
which the scans to be flagged are matched.
example: '*BANDPASS*'
edgespw Fraction of the baseline correlator TDM edge channels to be flagged.
fracspw Fraction of baseline correlator edge channels to be flagged
online Apply the online flags
fileonline File containing the online flags. These are computed by the
h_init or hif_importdata data tasks. If the online flags files
are undefined a name of the form 'msname.flagonline.txt' is assumed.
template Apply a flagging template
filetemplate The name of a text file that contains the flagging template
for RFI, birdies, telluric lines, etc. If the template flags files
is undefined a name of the form 'msname.flagtemplate.txt' is assumed.
hm_tbuff The time buffer computation heuristic
tbuff List of time buffers (sec) to pad timerange in flag commands
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.
flagbackup Backup pre-existing flags before applying new ones. Only can be set in
pipelinemode='interactive'.
dryrun Run the commands (True) or generate the commands to be run but
do not execute (False). This is a pipeline task execution mode.
acceptresults Add the results of the task to the pipeline context (True) or
reject them (False). This is a pipeline task execution mode.
--------- examples -----------------------------------------------------------
Output:
results -- If pipeline mode is 'getinputs' then None is returned. Otherwise
the results object for the pipeline task is returned.
Examples
1. Do basic flagging on a MeasurementSet
hifv_flagdata()
2. Do basic flagging on a MeasurementSet as well as flag pointing and
atmosphere data
hifv_flagdata(scan=True intent='*BANDPASS*')
"""
_info_group_ = """pipeline"""
_info_desc_ = """Do basic deterministic flagging of a list of MeasurementSets"""
__schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'autocorr': {'type': 'cBool'}, 'shadow': {'type': 'cBool'}, 'scan': {'type': 'cBool'}, 'scannumber': {'type': 'cStr', 'coerce': _coerce.to_str}, 'quack': {'type': 'cBool'}, 'clip': {'type': 'cBool'}, 'baseband': {'type': 'cBool'}, 'intents': {'type': 'cStr', 'coerce': _coerce.to_str}, 'edgespw': {'type': 'cBool'}, 'fracspw': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'online': {'type': 'cBool'}, 'fileonline': {'type': 'cStr', 'coerce': _coerce.to_str}, 'template': {'type': 'cBool'}, 'filetemplate': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_tbuff': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ '1.5int', 'halfint', 'manual' ]}, 'tbuff': {'anyof': [{'type': 'cFloat', 'coerce': _coerce.to_float}, {'type': 'cFloatVec', 'coerce': [_coerce.to_list,_coerce.to_floatvec]}]}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'flagbackup': {'type': 'cBool'}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}}
def __init__(self):
self.__stdout = None
self.__stderr = None
self.__root_frame_ = None
def __globals_(self):
if self.__root_frame_ is None:
self.__root_frame_ = _find_frame( )
assert self.__root_frame_ is not None, "could not find CASAshell global frame"
return self.__root_frame_
def __to_string_(self,value):
if type(value) is str:
return "'%s'" % value
else:
return str(value)
def __validate_(self,doc,schema):
return _pc.validate(doc,schema)
def __do_inp_output(self,param_prefix,description_str,formatting_chars):
out = self.__stdout or sys.stdout
description = description_str.split( )
prefix_width = 23 + 16 + 4
output = [ ]
addon = ''
first_addon = True
while len(description) > 0:
## starting a new line.....................................................................
if len(output) == 0:
## for first line add parameter information............................................
if len(param_prefix)-formatting_chars > prefix_width - 1:
output.append(param_prefix)
continue
addon = param_prefix + ' #'
first_addon = True
addon_formatting = formatting_chars
else:
## for subsequent lines space over prefix width........................................
addon = (' ' * prefix_width) + '#'
first_addon = False
addon_formatting = 0
## if first word of description puts us over the screen width, bail........................
if len(addon + description[0]) - addon_formatting + 1 > self.term_width:
## if we're doing the first line make sure it's output.................................
if first_addon: output.append(addon)
break
while len(description) > 0:
## if the next description word puts us over break for the next line...................
if len(addon + description[0]) - addon_formatting + 1 > self.term_width: break
addon = addon + ' ' + description[0]
description.pop(0)
output.append(addon)
out.write('\n'.join(output) + '\n')
#--------- return nonsubparam values ----------------------------------------------
def __template_dflt( self, glb ):
return True
def __template( self, glb ):
if 'template' in glb: return glb['template']
return True
def __hm_tbuff_dflt( self, glb ):
return '1.5int'
def __hm_tbuff( self, glb ):
if 'hm_tbuff' in glb: return glb['hm_tbuff']
return '1.5int'
def __shadow_dflt( self, glb ):
return True
def __shadow( self, glb ):
if 'shadow' in glb: return glb['shadow']
return True
def __baseband_dflt( self, glb ):
return True
def __baseband( self, glb ):
if 'baseband' in glb: return glb['baseband']
return True
def __online_dflt( self, glb ):
return True
def __online( self, glb ):
if 'online' in glb: return glb['online']
return True
def __clip_dflt( self, glb ):
return True
def __clip( self, glb ):
if 'clip' in glb: return glb['clip']
return True
def __edgespw_dflt( self, glb ):
return True
def __edgespw( self, glb ):
if 'edgespw' in glb: return glb['edgespw']
return True
def __scan_dflt( self, glb ):
return True
def __scan( self, glb ):
if 'scan' in glb: return glb['scan']
return True
def __autocorr_dflt( self, glb ):
return True
def __autocorr( self, glb ):
if 'autocorr' in glb: return glb['autocorr']
return True
def __quack_dflt( self, glb ):
return True
def __quack( self, glb ):
if 'quack' in glb: return glb['quack']
return True
def __pipelinemode_dflt( self, glb ):
return 'automatic'
def __pipelinemode( self, glb ):
if 'pipelinemode' in glb: return glb['pipelinemode']
return 'automatic'
#--------- return non subparam/when values ---------------------------------------------
def __vis( self, glb ):
if 'vis' in glb: return glb['vis']
return [ ]
#--------- return inp/go default --------------------------------------------------
def __dryrun_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(False)
return None
def __filetemplate_dflt( self, glb ):
if self.__template( glb ) == bool(True): return []
return None
def __fracspw_dflt( self, glb ):
if self.__edgespw( glb ) == bool(True): return float(0.05)
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 __intents_dflt( self, glb ):
if self.__scan( glb ) == bool(True): return "*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*,*UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*"
return None
def __scannumber_dflt( self, glb ):
if self.__scan( glb ) == bool(True): return ""
return None
def __fileonline_dflt( self, glb ):
if self.__online( glb ) == bool(True): return ""
return None
def __tbuff_dflt( self, glb ):
if self.__hm_tbuff( glb ) == "manual": return 0.0
return None
def __flagbackup_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(False)
if self.__pipelinemode( glb ) == "getinputs": return bool(False)
return None
#--------- return subparam values -------------------------------------------------
def __scannumber( self, glb ):
if 'scannumber' in glb: return glb['scannumber']
dflt = self.__scannumber_dflt( glb )
if dflt is not None: return dflt
return ''
def __intents( self, glb ):
if 'intents' in glb: return glb['intents']
dflt = self.__intents_dflt( glb )
if dflt is not None: return dflt
return '*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*, *UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*'
def __fracspw( self, glb ):
if 'fracspw' in glb: return glb['fracspw']
dflt = self.__fracspw_dflt( glb )
if dflt is not None: return dflt
return float(0.05)
def __fileonline( self, glb ):
if 'fileonline' in glb: return glb['fileonline']
dflt = self.__fileonline_dflt( glb )
if dflt is not None: return dflt
return ''
def __filetemplate( self, glb ):
if 'filetemplate' in glb: return glb['filetemplate']
dflt = self.__filetemplate_dflt( glb )
if dflt is not None: return dflt
return [ ]
def __tbuff( self, glb ):
if 'tbuff' in glb: return glb['tbuff']
dflt = self.__tbuff_dflt( glb )
if dflt is not None: return dflt
return float(0.0)
def __flagbackup( self, glb ):
if 'flagbackup' in glb: return glb['flagbackup']
dflt = self.__flagbackup_dflt( glb )
if dflt is not None: return dflt
return False
def __dryrun( self, glb ):
if 'dryrun' in glb: return glb['dryrun']
dflt = self.__dryrun_dflt( glb )
if dflt is not None: return dflt
return False
def __acceptresults( self, glb ):
if 'acceptresults' in glb: return glb['acceptresults']
dflt = self.__acceptresults_dflt( glb )
if dflt is not None: return dflt
return True
#--------- subparam inp output ----------------------------------------------------
def __vis_inp(self):
description = 'List of input visibility data'
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('%-16.16s = %s%-23s%s' % ('vis',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __autocorr_inp(self):
description = 'Flag autocorrelation data'
value = self.__autocorr( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'autocorr': value},{'autocorr': self.__schema['autocorr']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('autocorr',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __shadow_inp(self):
description = 'Flag shadowed antennas'
value = self.__shadow( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'shadow': value},{'shadow': self.__schema['shadow']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('shadow',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __scan_inp(self):
description = 'Flag specified scans'
value = self.__scan( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'scan': value},{'scan': self.__schema['scan']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('scan',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __scannumber_inp(self):
if self.__scannumber_dflt( self.__globals_( ) ) is not None:
description = 'List of scans to be flagged'
value = self.__scannumber( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'scannumber': value},{'scannumber': self.__schema['scannumber']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('scannumber',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __quack_inp(self):
description = 'Quack scans'
value = self.__quack( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'quack': value},{'quack': self.__schema['quack']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('quack',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __clip_inp(self):
description = 'Clip mode'
value = self.__clip( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'clip': value},{'clip': self.__schema['clip']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('clip',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __baseband_inp(self):
description = 'Flag 20MHz of each edge of basebands'
value = self.__baseband( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'baseband': value},{'baseband': self.__schema['baseband']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('baseband',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __intents_inp(self):
if self.__intents_dflt( self.__globals_( ) ) is not None:
description = 'List of intents of scans to be flagged'
value = self.__intents( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'intents': value},{'intents': self.__schema['intents']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('intents',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __edgespw_inp(self):
description = 'Flag edge channels'
value = self.__edgespw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'edgespw': value},{'edgespw': self.__schema['edgespw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('edgespw',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __fracspw_inp(self):
if self.__fracspw_dflt( self.__globals_( ) ) is not None:
description = 'Fraction of baseline correlator edge channels to be flagged'
value = self.__fracspw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'fracspw': value},{'fracspw': self.__schema['fracspw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('fracspw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __online_inp(self):
description = 'Apply the online flags'
value = self.__online( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'online': value},{'online': self.__schema['online']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('online',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __fileonline_inp(self):
if self.__fileonline_dflt( self.__globals_( ) ) is not None:
description = 'File of online flags to be applied'
value = self.__fileonline( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'fileonline': value},{'fileonline': self.__schema['fileonline']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('fileonline',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __template_inp(self):
description = 'Apply a flagging template'
value = self.__template( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'template': value},{'template': self.__schema['template']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('template',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __filetemplate_inp(self):
if self.__filetemplate_dflt( self.__globals_( ) ) is not None:
description = 'File that contains the flagging template'
value = self.__filetemplate( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'filetemplate': value},{'filetemplate': self.__schema['filetemplate']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('filetemplate',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_tbuff_inp(self):
description = 'The time buffer computation heuristic'
value = self.__hm_tbuff( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_tbuff': value},{'hm_tbuff': self.__schema['hm_tbuff']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('hm_tbuff',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __tbuff_inp(self):
if self.__tbuff_dflt( self.__globals_( ) ) is not None:
description = 'List of time buffers (sec) to pad timerange in flag commands'
value = self.__tbuff( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'tbuff': value},{'tbuff': self.__schema['tbuff']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('tbuff',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 __flagbackup_inp(self):
if self.__flagbackup_dflt( self.__globals_( ) ) is not None:
description = 'Backup pre-existing flags before applying new ones. Only can be set in pipelinemode=\'interactive\'.'
value = self.__flagbackup( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'flagbackup': value},{'flagbackup': self.__schema['flagbackup']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('flagbackup',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __dryrun_inp(self):
if self.__dryrun_dflt( self.__globals_( ) ) is not None:
description = 'Run the task (False) or display task 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 into the pipeline context'
value = self.__acceptresults( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'acceptresults': value},{'acceptresults': self.__schema['acceptresults']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('acceptresults',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
#--------- global default implementation-------------------------------------------
@static_var('state', __sf__('casa_inp_go_state'))
def set_global_defaults(self):
self.set_global_defaults.state['last'] = self
glb = self.__globals_( )
if 'quack' in glb: del glb['quack']
if 'shadow' in glb: del glb['shadow']
if 'dryrun' in glb: del glb['dryrun']
if 'filetemplate' in glb: del glb['filetemplate']
if 'fracspw' in glb: del glb['fracspw']
if 'baseband' in glb: del glb['baseband']
if 'pipelinemode' in glb: del glb['pipelinemode']
if 'online' in glb: del glb['online']
if 'hm_tbuff' in glb: del glb['hm_tbuff']
if 'scan' in glb: del glb['scan']
if 'vis' in glb: del glb['vis']
if 'acceptresults' in glb: del glb['acceptresults']
if 'intents' in glb: del glb['intents']
if 'scannumber' in glb: del glb['scannumber']
if 'template' in glb: del glb['template']
if 'clip' in glb: del glb['clip']
if 'fileonline' in glb: del glb['fileonline']
if 'tbuff' in glb: del glb['tbuff']
if 'flagbackup' in glb: del glb['flagbackup']
if 'edgespw' in glb: del glb['edgespw']
if 'autocorr' in glb: del glb['autocorr']
#--------- inp function -----------------------------------------------------------
def inp(self):
print("# hifv_flagdata -- %s" % self._info_desc_)
self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24))
self.__vis_inp( )
self.__autocorr_inp( )
self.__shadow_inp( )
self.__scan_inp( )
self.__scannumber_inp( )
self.__quack_inp( )
self.__clip_inp( )
self.__baseband_inp( )
self.__intents_inp( )
self.__edgespw_inp( )
self.__fracspw_inp( )
self.__online_inp( )
self.__fileonline_inp( )
self.__template_inp( )
self.__filetemplate_inp( )
self.__hm_tbuff_inp( )
self.__tbuff_inp( )
self.__pipelinemode_inp( )
self.__flagbackup_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("hifv_flagdata.last"):
filename = "hifv_flagdata.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, autocorr=None, shadow=None, scan=None, scannumber=None, quack=None, clip=None, baseband=None, intents=None, edgespw=None, fracspw=None, online=None, fileonline=None, template=None, filetemplate=None, hm_tbuff=None, tbuff=None, pipelinemode=None, flagbackup=None, dryrun=None, acceptresults=None ):
def noobj(s):
if s.startswith('<') and s.endswith('>'):
return "None"
else:
return s
_prefile = os.path.realpath('hifv_flagdata.pre')
_postfile = os.path.realpath('hifv_flagdata.last')
_return_result_ = None
_arguments = [vis,autocorr,shadow,scan,scannumber,quack,clip,baseband,intents,edgespw,fracspw,online,fileonline,template,filetemplate,hm_tbuff,tbuff,pipelinemode,flagbackup,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 vis is not None: local_global['vis'] = vis
if autocorr is not None: local_global['autocorr'] = autocorr
if shadow is not None: local_global['shadow'] = shadow
if scan is not None: local_global['scan'] = scan
if quack is not None: local_global['quack'] = quack
if clip is not None: local_global['clip'] = clip
if baseband is not None: local_global['baseband'] = baseband
if edgespw is not None: local_global['edgespw'] = edgespw
if online is not None: local_global['online'] = online
if template is not None: local_global['template'] = template
if hm_tbuff is not None: local_global['hm_tbuff'] = hm_tbuff
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['vis'] = self.__vis( local_global )
_invocation_parameters['autocorr'] = self.__autocorr( local_global )
_invocation_parameters['shadow'] = self.__shadow( local_global )
_invocation_parameters['scan'] = self.__scan( local_global )
_invocation_parameters['quack'] = self.__quack( local_global )
_invocation_parameters['clip'] = self.__clip( local_global )
_invocation_parameters['baseband'] = self.__baseband( local_global )
_invocation_parameters['edgespw'] = self.__edgespw( local_global )
_invocation_parameters['online'] = self.__online( local_global )
_invocation_parameters['template'] = self.__template( local_global )
_invocation_parameters['hm_tbuff'] = self.__hm_tbuff( 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['scannumber'] = self.__scannumber( _invocation_parameters ) if scannumber is None else scannumber
_invocation_parameters['intents'] = self.__intents( _invocation_parameters ) if intents is None else intents
_invocation_parameters['fracspw'] = self.__fracspw( _invocation_parameters ) if fracspw is None else fracspw
_invocation_parameters['fileonline'] = self.__fileonline( _invocation_parameters ) if fileonline is None else fileonline
_invocation_parameters['filetemplate'] = self.__filetemplate( _invocation_parameters ) if filetemplate is None else filetemplate
_invocation_parameters['tbuff'] = self.__tbuff( _invocation_parameters ) if tbuff is None else tbuff
_invocation_parameters['flagbackup'] = self.__flagbackup( _invocation_parameters ) if flagbackup is None else flagbackup
_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['autocorr'] = self.__autocorr( self.__globals_( ) )
_invocation_parameters['shadow'] = self.__shadow( self.__globals_( ) )
_invocation_parameters['scan'] = self.__scan( self.__globals_( ) )
_invocation_parameters['scannumber'] = self.__scannumber( self.__globals_( ) )
_invocation_parameters['quack'] = self.__quack( self.__globals_( ) )
_invocation_parameters['clip'] = self.__clip( self.__globals_( ) )
_invocation_parameters['baseband'] = self.__baseband( self.__globals_( ) )
_invocation_parameters['intents'] = self.__intents( self.__globals_( ) )
_invocation_parameters['edgespw'] = self.__edgespw( self.__globals_( ) )
_invocation_parameters['fracspw'] = self.__fracspw( self.__globals_( ) )
_invocation_parameters['online'] = self.__online( self.__globals_( ) )
_invocation_parameters['fileonline'] = self.__fileonline( self.__globals_( ) )
_invocation_parameters['template'] = self.__template( self.__globals_( ) )
_invocation_parameters['filetemplate'] = self.__filetemplate( self.__globals_( ) )
_invocation_parameters['hm_tbuff'] = self.__hm_tbuff( self.__globals_( ) )
_invocation_parameters['tbuff'] = self.__tbuff( self.__globals_( ) )
_invocation_parameters['pipelinemode'] = self.__pipelinemode( self.__globals_( ) )
_invocation_parameters['flagbackup'] = self.__flagbackup( self.__globals_( ) )
_invocation_parameters['dryrun'] = self.__dryrun( self.__globals_( ) )
_invocation_parameters['acceptresults'] = self.__acceptresults( self.__globals_( ) )
try:
with open(_prefile,'w') as _f:
for _i in _invocation_parameters:
_f.write("%-13s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
_f.write("#hifv_flagdata( ")
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_ = _hifv_flagdata_t( _invocation_parameters['vis'],_invocation_parameters['autocorr'],_invocation_parameters['shadow'],_invocation_parameters['scan'],_invocation_parameters['scannumber'],_invocation_parameters['quack'],_invocation_parameters['clip'],_invocation_parameters['baseband'],_invocation_parameters['intents'],_invocation_parameters['edgespw'],_invocation_parameters['fracspw'],_invocation_parameters['online'],_invocation_parameters['fileonline'],_invocation_parameters['template'],_invocation_parameters['filetemplate'],_invocation_parameters['hm_tbuff'],_invocation_parameters['tbuff'],_invocation_parameters['pipelinemode'],_invocation_parameters['flagbackup'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'] )
except Exception as e:
from traceback import format_exc
from casatasks import casalog
casalog.origin('hifv_flagdata')
casalog.post("Exception Reported: Error in hifv_flagdata: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hifv_flagdata = _hifv_flagdata( )