##################### generated by xml-casa (v2) from hifa_flagdata.xml #############
##################### 3a2d143eac81bfcdab5a9bc42506d4d9 ##############################
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_flagdata as _hifa_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 _hifa_flagdata:
"""
hifa_flagdata ---- Do meta data based flagging of a list of MeasurementSets.
The hifa_flagdata data performs basic flagging operations on a list of
measurements including:
o applying online flags
o applying a flagging template
o autocorrelation data flagging
o shadowed antenna data flagging
o scan-based flagging by intent or scan number
o edge channel flagging, as needed
About the spectral window edge channel flagging:
o For TDM spectral windows, a number of edge channels are always flagged,
according to the fracspw and fracspwfps parameters (the latter operates only
on spectral windows with 62, 124, or 248 channels). With the default setting
of fracspw, the number of channels flagged on each edge is 2, 4, or 8 for 64,
128, or 256-channel spectral windows, respectively.
o For most FDM spectral windows, no edge flagging is done. The only exceptions
are ACA spectral windows that encroach too close to the baseband edge.
Channels that lie closer to the baseband edge than the following values are
flagged: 62.5, 40, 20, 10, and 5 MHz for spectral windows with bandwidths of
1000, 500, 250, 125, and 62.5 MHz, respectively. A warning is generated in
the weblog if flagging occurs due to proximity to the baseband edge.
By definition, 2000 MHz spectral windows always encroach the baseband edge on
both sides of the spectral window, and thus are always flagged on both sides
in order to achieve 1875 MHz bandwidth (in effect, they are flagged by
62.5 MHz on each side), and thus no warning is generated.
Output
results -- If pipeline mode is 'getinputs' then None is returned. Otherwise
the results object for the pipeline task is returned.
--------- parameter descriptions ---------------------------------------------
vis The list of input MeasurementSets. Defaults to the list of
MeasurementSets defined in the pipeline context.
autocorr Flag autocorrelation data.
shadow Flag shadowed antennas.
tolerance Amount of antenna shadowing tolerated, in meters. A positive number
allows antennas to overlap in projection. A negative number forces antennas
apart in projection. Zero implies a distance of radius_1+radius_2 between
antenna centers.
scan Flag a list of specified scans.
scannumber A string containing a comma delimited list of scans to be
flagged.
example: scannumber='3,5,6'
intents A string containing a comma delimited list of intents against
which the scans to be flagged are matched.
example: intents='*BANDPASS*'
edgespw Flag the edge spectral window channels.
fracspw Fraction of channels to flag at both edges of TDM spectral windows.
fracspwfps Fraction of channels to flag at both edges of ACA TDM
spectral windows that were created with the earlier (original)
implementation of the frequency profile synthesis (FPS) algorithm.
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 flagging templates
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 heuristic for computing the default time interval padding
parameter. The options are 'halfint' and 'manual'. In 'halfint' mode tbuff
is set to half the maximum of the median integration time of the science
and calibrator target observations. The value of 0.048 seconds is
subtracted from the lower time limit to accommodate the behavior of the
ALMA Control system.
tbuff The time in seconds used to pad flagging command time intervals if
hm_tbuff='manual'. The default in manual mode is no flagging.
qa0 QA0 flags.
qa2 QA2 flags.
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 Back up any pre-existing flags.
dryrun Run the commands (True) or generate the commands to be run but do not
execute (False).
acceptresults Add the results of the task to the pipeline context (True) or
reject them (False).
--------- examples -----------------------------------------------------------
1. Do basic flagging on a MeasurementSet:
hifa_flagdata()
2. Do basic flagging on a MeasurementSet flagging additional scans selected
by number as well:
hifa_flagdata(scannumber='13,18')
"""
_info_group_ = """pipeline"""
_info_desc_ = """Do meta data based flagging of a list of MeasurementSets."""
__schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'autocorr': {'type': 'cBool'}, 'shadow': {'type': 'cBool'}, 'tolerance': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'scan': {'type': 'cBool'}, 'scannumber': {'type': 'cStr', 'coerce': _coerce.to_str}, 'intents': {'type': 'cStr', 'coerce': _coerce.to_str}, 'edgespw': {'type': 'cBool'}, 'fracspw': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'fracspwfps': {'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': [ 'halfint', 'manual' ]}, 'tbuff': {'anyof': [{'type': 'cFloat', 'coerce': _coerce.to_float}, {'type': 'cFloatVec', 'coerce': [_coerce.to_list,_coerce.to_floatvec]}]}, 'qa0': {'type': 'cBool'}, 'qa2': {'type': 'cBool'}, '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 __qa2_dflt( self, glb ):
return True
def __qa2( self, glb ):
if 'qa2' in glb: return glb['qa2']
return True
def __shadow_dflt( self, glb ):
return True
def __shadow( self, glb ):
if 'shadow' in glb: return glb['shadow']
return True
def __online_dflt( self, glb ):
return True
def __online( self, glb ):
if 'online' in glb: return glb['online']
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 __pipelinemode_dflt( self, glb ):
return 'automatic'
def __pipelinemode( self, glb ):
if 'pipelinemode' in glb: return glb['pipelinemode']
return 'automatic'
def __hm_tbuff_dflt( self, glb ):
return 'halfint'
def __hm_tbuff( self, glb ):
if 'hm_tbuff' in glb: return glb['hm_tbuff']
return 'halfint'
def __qa0_dflt( self, glb ):
return True
def __qa0( self, glb ):
if 'qa0' in glb: return glb['qa0']
return True
#--------- 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.03125)
return None
def __tolerance_dflt( self, glb ):
if self.__shadow( glb ) == bool(True): return float()
return None
def __fracspwfps_dflt( self, glb ):
if self.__edgespw( glb ) == bool(True): return float(0.048387)
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"
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 []
return None
def __flagbackup_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(True)
if self.__pipelinemode( glb ) == "getinputs": return bool(True)
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 __tolerance( self, glb ):
if 'tolerance' in glb: return glb['tolerance']
dflt = self.__tolerance_dflt( glb )
if dflt is not None: return dflt
return float(0.0)
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'
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.03125)
def __fracspwfps( self, glb ):
if 'fracspwfps' in glb: return glb['fracspwfps']
dflt = self.__fracspwfps_dflt( glb )
if dflt is not None: return dflt
return float(0.048387)
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 [ ]
def __flagbackup( self, glb ):
if 'flagbackup' in glb: return glb['flagbackup']
dflt = self.__flagbackup_dflt( glb )
if dflt is not None: return dflt
return True
def __dryrun( self, glb ):
if 'dryrun' in glb: return glb['dryrun']
dflt = self.__dryrun_dflt( glb )
if dflt is not None: return dflt
return False
def __acceptresults( self, glb ):
if 'acceptresults' in glb: return glb['acceptresults']
dflt = self.__acceptresults_dflt( glb )
if dflt is not None: return dflt
return True
#--------- subparam inp output ----------------------------------------------------
def __vis_inp(self):
if self.__vis_dflt( self.__globals_( ) ) is not None:
description = 'List of input MeasurementSets to flag'
value = self.__vis( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'vis': value},{'vis': self.__schema['vis']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('vis',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __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('\x1B[1m\x1B[47m%-16.16s =\x1B[0m %s%-23s%s' % ('shadow',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __tolerance_inp(self):
if self.__tolerance_dflt( self.__globals_( ) ) is not None:
description = 'Amount of antenna shadowing tolerated'
value = self.__tolerance( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'tolerance': value},{'tolerance': self.__schema['tolerance']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('tolerance',pre,self.__to_string_(value),post),description,9+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 __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 channels to flag at edges of TDM spectral windows'
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 __fracspwfps_inp(self):
if self.__fracspwfps_dflt( self.__globals_( ) ) is not None:
description = 'Fraction of channels to flag at edges of ACA FPS TDM spectral windows'
value = self.__fracspwfps( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'fracspwfps': value},{'fracspwfps': self.__schema['fracspwfps']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('fracspwfps',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 __qa0_inp(self):
description = 'QA0 flags'
value = self.__qa0( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'qa0': value},{'qa0': self.__schema['qa0']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('qa0',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __qa2_inp(self):
description = 'QA2 flags'
value = self.__qa2( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'qa2': value},{'qa2': self.__schema['qa2']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-16.16s = %s%-23s%s' % ('qa2',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%-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'
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 the command (True)'
value = self.__dryrun( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'dryrun': value},{'dryrun': self.__schema['dryrun']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-13.13s =\x1B[0m %s%-23s%s' % ('dryrun',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __acceptresults_inp(self):
if self.__acceptresults_dflt( self.__globals_( ) ) is not None:
description = 'Add the results 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 'shadow' in glb: del glb['shadow']
if 'qa0' in glb: del glb['qa0']
if 'dryrun' in glb: del glb['dryrun']
if 'filetemplate' in glb: del glb['filetemplate']
if 'fracspw' in glb: del glb['fracspw']
if 'pipelinemode' in glb: del glb['pipelinemode']
if 'online' in glb: del glb['online']
if 'tolerance' in glb: del glb['tolerance']
if 'hm_tbuff' in glb: del glb['hm_tbuff']
if 'fracspwfps' in glb: del glb['fracspwfps']
if 'scan' in glb: del glb['scan']
if 'vis' in glb: del glb['vis']
if 'acceptresults' in glb: del glb['acceptresults']
if 'qa2' in glb: del glb['qa2']
if 'intents' in glb: del glb['intents']
if 'scannumber' in glb: del glb['scannumber']
if 'template' in glb: del glb['template']
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("# hifa_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.__tolerance_inp( )
self.__scan_inp( )
self.__scannumber_inp( )
self.__intents_inp( )
self.__edgespw_inp( )
self.__fracspw_inp( )
self.__fracspwfps_inp( )
self.__online_inp( )
self.__fileonline_inp( )
self.__template_inp( )
self.__filetemplate_inp( )
self.__hm_tbuff_inp( )
self.__tbuff_inp( )
self.__qa0_inp( )
self.__qa2_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("hifa_flagdata.last"):
filename = "hifa_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, tolerance=None, scan=None, scannumber=None, intents=None, edgespw=None, fracspw=None, fracspwfps=None, online=None, fileonline=None, template=None, filetemplate=None, hm_tbuff=None, tbuff=None, qa0=None, qa2=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('hifa_flagdata.pre')
_postfile = os.path.realpath('hifa_flagdata.last')
_return_result_ = None
_arguments = [vis,autocorr,shadow,tolerance,scan,scannumber,intents,edgespw,fracspw,fracspwfps,online,fileonline,template,filetemplate,hm_tbuff,tbuff,qa0,qa2,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 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 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 qa0 is not None: local_global['qa0'] = qa0
if qa2 is not None: local_global['qa2'] = qa2
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['autocorr'] = self.__autocorr( local_global )
_invocation_parameters['shadow'] = self.__shadow( local_global )
_invocation_parameters['scan'] = self.__scan( 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['qa0'] = self.__qa0( local_global )
_invocation_parameters['qa2'] = self.__qa2( 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['tolerance'] = self.__tolerance( _invocation_parameters ) if tolerance is None else tolerance
_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['fracspwfps'] = self.__fracspwfps( _invocation_parameters ) if fracspwfps is None else fracspwfps
_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['tolerance'] = self.__tolerance( self.__globals_( ) )
_invocation_parameters['scan'] = self.__scan( self.__globals_( ) )
_invocation_parameters['scannumber'] = self.__scannumber( 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['fracspwfps'] = self.__fracspwfps( 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['qa0'] = self.__qa0( self.__globals_( ) )
_invocation_parameters['qa2'] = self.__qa2( 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("#hifa_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_ = _hifa_flagdata_t( _invocation_parameters['vis'],_invocation_parameters['autocorr'],_invocation_parameters['shadow'],_invocation_parameters['tolerance'],_invocation_parameters['scan'],_invocation_parameters['scannumber'],_invocation_parameters['intents'],_invocation_parameters['edgespw'],_invocation_parameters['fracspw'],_invocation_parameters['fracspwfps'],_invocation_parameters['online'],_invocation_parameters['fileonline'],_invocation_parameters['template'],_invocation_parameters['filetemplate'],_invocation_parameters['hm_tbuff'],_invocation_parameters['tbuff'],_invocation_parameters['qa0'],_invocation_parameters['qa2'],_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('hifa_flagdata')
casalog.post("Exception Reported: Error in hifa_flagdata: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hifa_flagdata = _hifa_flagdata( )