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

##################### generated by xml-casa (v2) from hifa_tsysflag.xml #############
##################### 42e35fa40d01f3554f57bcfe9a33424d ##############################
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_tsysflag as _hifa_tsysflag_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_tsysflag: """ hifa_tsysflag ---- Flag deviant system temperatures for ALMA interferometry measurements. This is done by running a sequence of flagging subtasks, each looking for a different type of possible error. Flag deviant system temperatures for ALMA interferometry measurements. Flag all deviant system temperature measurements in the system temperature calibration table by running a sequence of flagging tests, each designed to look for a different type of error. If a file with manual Tsys flags is provided with the 'filetemplate' parameter, then these flags are applied prior to the evaluation of the flagging heuristics listed below. The tests are: 1. Flag Tsys spectra with high median values 2. Flag Tsys spectra with high median derivatives. This is meant to spot spectra that are 'ringing'. 3. Flag the edge channels of the Tsys spectra in each SpW. 4. Flag Tsys spectra whose shape is different from that associated with the BANDPASS intent. 5. Flag 'birdies'. 6. Flag the Tsys spectra of all antennas in a timestamp and spw if proportion of antennas already flagged in this timestamp and spw exceeds a threshold, and flag Tsys spectra for all antennas and all timestamps in a spw, if proportion of antennas that are already entirely flagged in all timestamps exceeds a threshold. Output results -- If pipeline mode is 'getinputs' then None is returned. Otherwise the results object for the pipeline task is returned. --------- parameter descriptions --------------------------------------------- vis List of input MeasurementSets (Not used). caltable List of input Tsys calibration tables. default: [] - Use the table currently stored in the pipeline context. example: caltable=['X132.ms.tsys.s2.tbl'] flag_nmedian True to flag Tsys spectra with high median value. fnm_limit Flag spectra with median value higher than fnm_limit * median of this measure over all spectra. fnm_byfield Evaluate the nmedian metric separately for each field. flag_derivative True to flag Tsys spectra with high median derivative. fd_max_limit Flag spectra with median derivative higher than fd_max_limit * median of this measure over all spectra. flag_edgechans True to flag edges of Tsys spectra. fe_edge_limit Flag channels whose channel to channel difference > fe_edge_limit * median across spectrum. flag_fieldshape True to flag Tsys spectra with a radically different shape to those of the ff_refintent. ff_refintent Data intent that provides the reference shape for 'flag_fieldshape'. ff_max_limit Flag Tsys spectra with 'fieldshape' metric values > ff_max_limit. flag_birdies True to flag channels covering sharp spectral features. fb_sharps_limit Flag channels bracketing a channel to channel difference > fb_sharps_limit. flag_toomany True to flag Tsys spectra for which a proportion of antennas for given timestamp and/or proportion of antennas that are entirely flagged in all timestamps exceeds their respective thresholds. tmf1_limit Flag Tsys spectra for all antennas in a timestamp and spw if proportion of antennas already flagged in this timestamp and spw exceeds tmf1_limit. tmef1_limit Flag Tsys spectra for all antennas and all timestamps in a spw, if proportion of antennas that are already entirely flagged in all timestamps exceeds tmef1_limit. metric_order Order in which to evaluate the flagging metrics that are enables. Disabled metrics are skipped. normalize_tsys True to create a normalized Tsys table that is used to evaluate the Tsys flagging metrics. All newly found flags are also applied to the original Tsys caltable that continues to be used for subsequent calibration. filetemplate The name of a text file that contains the manual Tsys flagging template. If the template flags file is undefined, a name of the form 'msname.flagtsystemplate.txt' is assumed. pipelinemode The pipeline operating mode. In 'automatic' mode the pipeline determines the values of all context defined pipeline inputs automatically. In interactive mode the user can set the pipeline context defined parameters manually. In 'getinputs' mode the user can check the settings of all pipeline parameters without running the task. dryrun Run the commands (True) or generate the commands to be run but do not execute (False). acceptresults Add the results of the task to the pipeline context (True) or reject them (False). --------- examples ----------------------------------------------------------- 1. Flag Tsys measurements using currently recommended tests: hifa_tsysflag() 2. Flag Tsys measurements using all recommended tests apart from that using the 'fieldshape' metric: hifa_tsysflag(flag_fieldshape=False) """ _info_group_ = """pipeline""" _info_desc_ = """Flag deviant system temperatures for ALMA interferometry measurements. This is done by running a sequence of flagging subtasks, each looking for a different type of possible error. """ __schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'caltable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'flag_nmedian': {'type': 'cBool'}, 'fnm_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'fnm_byfield': {'type': 'cBool'}, 'flag_derivative': {'type': 'cBool'}, 'fd_max_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'flag_edgechans': {'type': 'cBool'}, 'fe_edge_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'flag_fieldshape': {'type': 'cBool'}, 'ff_refintent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'ff_max_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'flag_birdies': {'type': 'cBool'}, 'fb_sharps_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'flag_toomany': {'type': 'cBool'}, 'tmf1_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'tmef1_limit': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'metric_order': {'type': 'cStr', 'coerce': _coerce.to_str}, 'normalize_tsys': {'type': 'cBool'}, 'filetemplate': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, '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 __filetemplate_dflt( self, glb ): return [ ] def __filetemplate( self, glb ): if 'filetemplate' in glb: return glb['filetemplate'] return [ ] def __flag_nmedian_dflt( self, glb ): return True def __flag_nmedian( self, glb ): if 'flag_nmedian' in glb: return glb['flag_nmedian'] return True def __metric_order_dflt( self, glb ): return 'nmedian,derivative,edgechans,fieldshape,birdies,toomany' def __metric_order( self, glb ): if 'metric_order' in glb: return glb['metric_order'] return 'nmedian,derivative,edgechans,fieldshape,birdies,toomany' def __normalize_tsys_dflt( self, glb ): return False def __normalize_tsys( self, glb ): if 'normalize_tsys' in glb: return glb['normalize_tsys'] return False def __vis_dflt( self, glb ): return [ ] def __vis( self, glb ): if 'vis' in glb: return glb['vis'] return [ ] def __flag_edgechans_dflt( self, glb ): return True def __flag_edgechans( self, glb ): if 'flag_edgechans' in glb: return glb['flag_edgechans'] return True def __flag_toomany_dflt( self, glb ): return True def __flag_toomany( self, glb ): if 'flag_toomany' in glb: return glb['flag_toomany'] return True def __pipelinemode_dflt( self, glb ): return 'automatic' def __pipelinemode( self, glb ): if 'pipelinemode' in glb: return glb['pipelinemode'] return 'automatic' def __flag_birdies_dflt( self, glb ): return True def __flag_birdies( self, glb ): if 'flag_birdies' in glb: return glb['flag_birdies'] return True def __flag_fieldshape_dflt( self, glb ): return True def __flag_fieldshape( self, glb ): if 'flag_fieldshape' in glb: return glb['flag_fieldshape'] return True def __flag_derivative_dflt( self, glb ): return True def __flag_derivative( self, glb ): if 'flag_derivative' in glb: return glb['flag_derivative'] return True #--------- return inp/go default -------------------------------------------------- def __dryrun_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(False) return None def __tmf1_limit_dflt( self, glb ): if self.__flag_toomany( glb ) == bool(True): return float(0.666) return None def __fe_edge_limit_dflt( self, glb ): if self.__flag_edgechans( glb ) == bool(True): return float(3.0) return None def __fnm_limit_dflt( self, glb ): if self.__flag_nmedian( glb ) == bool(True): return float(2.0) return None def __fd_max_limit_dflt( self, glb ): if self.__flag_derivative( glb ) == bool(True): return float(13.0) return None def __tmef1_limit_dflt( self, glb ): if self.__flag_toomany( glb ) == bool(True): return float(0.666) return None def __acceptresults_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return bool(True) return None def __fb_sharps_limit_dflt( self, glb ): if self.__flag_birdies( glb ) == bool(True): return float(0.05) return None def __ff_max_limit_dflt( self, glb ): if self.__flag_fieldshape( glb ) == bool(True): return float(13) return None def __fnm_byfield_dflt( self, glb ): if self.__flag_nmedian( glb ) == bool(True): return bool(True) return None def __caltable_dflt( self, glb ): if self.__pipelinemode( glb ) == "interactive": return [] if self.__pipelinemode( glb ) == "getinputs": return [] return None def __ff_refintent_dflt( self, glb ): if self.__flag_fieldshape( glb ) == bool(True): return "BANDPASS" 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 __fnm_limit( self, glb ): if 'fnm_limit' in glb: return glb['fnm_limit'] dflt = self.__fnm_limit_dflt( glb ) if dflt is not None: return dflt return float(2.0) def __fnm_byfield( self, glb ): if 'fnm_byfield' in glb: return glb['fnm_byfield'] dflt = self.__fnm_byfield_dflt( glb ) if dflt is not None: return dflt return True def __fd_max_limit( self, glb ): if 'fd_max_limit' in glb: return glb['fd_max_limit'] dflt = self.__fd_max_limit_dflt( glb ) if dflt is not None: return dflt return float(13.0) def __fe_edge_limit( self, glb ): if 'fe_edge_limit' in glb: return glb['fe_edge_limit'] dflt = self.__fe_edge_limit_dflt( glb ) if dflt is not None: return dflt return float(3.0) def __ff_refintent( self, glb ): if 'ff_refintent' in glb: return glb['ff_refintent'] dflt = self.__ff_refintent_dflt( glb ) if dflt is not None: return dflt return 'BANDPASS' def __ff_max_limit( self, glb ): if 'ff_max_limit' in glb: return glb['ff_max_limit'] dflt = self.__ff_max_limit_dflt( glb ) if dflt is not None: return dflt return float(13) def __fb_sharps_limit( self, glb ): if 'fb_sharps_limit' in glb: return glb['fb_sharps_limit'] dflt = self.__fb_sharps_limit_dflt( glb ) if dflt is not None: return dflt return float(0.05) def __tmf1_limit( self, glb ): if 'tmf1_limit' in glb: return glb['tmf1_limit'] dflt = self.__tmf1_limit_dflt( glb ) if dflt is not None: return dflt return float(0.666) def __tmef1_limit( self, glb ): if 'tmef1_limit' in glb: return glb['tmef1_limit'] dflt = self.__tmef1_limit_dflt( glb ) if dflt is not None: return dflt return float(0.666) 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 (Not used)' 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 input caltables' value = self.__caltable( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'caltable': value},{'caltable': self.__schema['caltable']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('caltable',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_nmedian_inp(self): description = 'True to flag Tsys spectra with high median value' value = self.__flag_nmedian( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_nmedian': value},{'flag_nmedian': self.__schema['flag_nmedian']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_nmedian',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __fnm_limit_inp(self): if self.__fnm_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag spectra with median greater than fnm_limit * median over all spectra' value = self.__fnm_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fnm_limit': value},{'fnm_limit': self.__schema['fnm_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('fnm_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __fnm_byfield_inp(self): if self.__fnm_byfield_dflt( self.__globals_( ) ) is not None: description = 'Evaluate the nmedian metric separately for each field.' value = self.__fnm_byfield( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fnm_byfield': value},{'fnm_byfield': self.__schema['fnm_byfield']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('fnm_byfield',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_derivative_inp(self): description = 'True to flag Tsys spectra with high median derivative' value = self.__flag_derivative( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_derivative': value},{'flag_derivative': self.__schema['flag_derivative']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_derivative',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __fd_max_limit_inp(self): if self.__fd_max_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag spectra with median derivative higher than fd_max_limit * median of this measure over all spectra' value = self.__fd_max_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fd_max_limit': value},{'fd_max_limit': self.__schema['fd_max_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('fd_max_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_edgechans_inp(self): description = 'True to flag edges of Tsys spectra' value = self.__flag_edgechans( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_edgechans': value},{'flag_edgechans': self.__schema['flag_edgechans']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_edgechans',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __fe_edge_limit_inp(self): if self.__fe_edge_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag channels whose channel to channel difference greater than fe_edge_limit * median across spectrum' value = self.__fe_edge_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fe_edge_limit': value},{'fe_edge_limit': self.__schema['fe_edge_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('fe_edge_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_fieldshape_inp(self): description = 'True to flag Tsys spectra with a radically different shape to those of the ff_refintent' value = self.__flag_fieldshape( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_fieldshape': value},{'flag_fieldshape': self.__schema['flag_fieldshape']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_fieldshape',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __ff_refintent_inp(self): if self.__ff_refintent_dflt( self.__globals_( ) ) is not None: description = 'Data intent providing the reference shape for \'flag_fieldshape\'' value = self.__ff_refintent( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'ff_refintent': value},{'ff_refintent': self.__schema['ff_refintent']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('ff_refintent',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __ff_max_limit_inp(self): if self.__ff_max_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag Tsys spectra with \'fieldshape\' metric greater than ff_max_limit' value = self.__ff_max_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'ff_max_limit': value},{'ff_max_limit': self.__schema['ff_max_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('ff_max_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_birdies_inp(self): description = 'True to flag channels covering sharp spectral features' value = self.__flag_birdies( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_birdies': value},{'flag_birdies': self.__schema['flag_birdies']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_birdies',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __fb_sharps_limit_inp(self): if self.__fb_sharps_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag channels bracketing a channel to channel difference greater than fb_sharps_limit' value = self.__fb_sharps_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'fb_sharps_limit': value},{'fb_sharps_limit': self.__schema['fb_sharps_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('fb_sharps_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __flag_toomany_inp(self): description = 'True to flag Tsys spectra for which a proportion of timestamps or proportion of antennas that are entirely flagged exceeds their respective thresholds.' value = self.__flag_toomany( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'flag_toomany': value},{'flag_toomany': self.__schema['flag_toomany']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('\x1B[1m\x1B[47m%-18.18s =\x1B[0m %s%-23s%s' % ('flag_toomany',pre,self.__to_string_(value),post),description,13+len(pre)+len(post)) def __tmf1_limit_inp(self): if self.__tmf1_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag all Tsys spectra within a timestamp for an antenna if proportion flagged already exceeds tmf1_limit' value = self.__tmf1_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'tmf1_limit': value},{'tmf1_limit': self.__schema['tmf1_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('tmf1_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __tmef1_limit_inp(self): if self.__tmef1_limit_dflt( self.__globals_( ) ) is not None: description = 'Flag all Tsys spectra for all antennas in a spw, if proportion of antennas that are already entirely flagged in all timestamps exceeds tmef1_limit' value = self.__tmef1_limit( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'tmef1_limit': value},{'tmef1_limit': self.__schema['tmef1_limit']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output(' \x1B[92m%-15.15s =\x1B[0m %s%-23s%s' % ('tmef1_limit',pre,self.__to_string_(value),post),description,9+len(pre)+len(post)) def __metric_order_inp(self): description = 'Order in which to evaluate the flagging metric(s); inactive metrics are skipped.' value = self.__metric_order( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'metric_order': value},{'metric_order': self.__schema['metric_order']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-18.18s = %s%-23s%s' % ('metric_order',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __normalize_tsys_inp(self): description = 'Normalize Tsys prior to computing the flagging metric(s)' value = self.__normalize_tsys( self.__globals_( ) ) (pre,post) = ('','') if self.__validate_({'normalize_tsys': value},{'normalize_tsys': self.__schema['normalize_tsys']}) else ('\x1B[91m','\x1B[0m') self.__do_inp_output('%-18.18s = %s%-23s%s' % ('normalize_tsys',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __filetemplate_inp(self): description = 'File containing manual Tsys flags to apply.' 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('%-18.18s = %s%-23s%s' % ('filetemplate',pre,self.__to_string_(value),post),description,0+len(pre)+len(post)) def __pipelinemode_inp(self): description = 'The pipeline operations 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 list commands (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 = 'Automatically apply results to 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 'dryrun' in glb: del glb['dryrun'] if 'tmf1_limit' in glb: del glb['tmf1_limit'] if 'flag_toomany' in glb: del glb['flag_toomany'] if 'filetemplate' in glb: del glb['filetemplate'] if 'flag_edgechans' in glb: del glb['flag_edgechans'] if 'fe_edge_limit' in glb: del glb['fe_edge_limit'] if 'pipelinemode' in glb: del glb['pipelinemode'] if 'flag_nmedian' in glb: del glb['flag_nmedian'] if 'fnm_limit' in glb: del glb['fnm_limit'] if 'fd_max_limit' in glb: del glb['fd_max_limit'] if 'tmef1_limit' in glb: del glb['tmef1_limit'] if 'vis' in glb: del glb['vis'] if 'acceptresults' in glb: del glb['acceptresults'] if 'flag_fieldshape' in glb: del glb['flag_fieldshape'] if 'flag_derivative' in glb: del glb['flag_derivative'] if 'flag_birdies' in glb: del glb['flag_birdies'] if 'fb_sharps_limit' in glb: del glb['fb_sharps_limit'] if 'ff_max_limit' in glb: del glb['ff_max_limit'] if 'normalize_tsys' in glb: del glb['normalize_tsys'] if 'fnm_byfield' in glb: del glb['fnm_byfield'] if 'caltable' in glb: del glb['caltable'] if 'metric_order' in glb: del glb['metric_order'] if 'ff_refintent' in glb: del glb['ff_refintent'] #--------- inp function ----------------------------------------------------------- def inp(self): print("# hifa_tsysflag -- %s" % self._info_desc_) self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24)) self.__vis_inp( ) self.__caltable_inp( ) self.__flag_nmedian_inp( ) self.__fnm_limit_inp( ) self.__fnm_byfield_inp( ) self.__flag_derivative_inp( ) self.__fd_max_limit_inp( ) self.__flag_edgechans_inp( ) self.__fe_edge_limit_inp( ) self.__flag_fieldshape_inp( ) self.__ff_refintent_inp( ) self.__ff_max_limit_inp( ) self.__flag_birdies_inp( ) self.__fb_sharps_limit_inp( ) self.__flag_toomany_inp( ) self.__tmf1_limit_inp( ) self.__tmef1_limit_inp( ) self.__metric_order_inp( ) self.__normalize_tsys_inp( ) self.__filetemplate_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_tsysflag.last"): filename = "hifa_tsysflag.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, flag_nmedian=None, fnm_limit=None, fnm_byfield=None, flag_derivative=None, fd_max_limit=None, flag_edgechans=None, fe_edge_limit=None, flag_fieldshape=None, ff_refintent=None, ff_max_limit=None, flag_birdies=None, fb_sharps_limit=None, flag_toomany=None, tmf1_limit=None, tmef1_limit=None, metric_order=None, normalize_tsys=None, filetemplate=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_tsysflag.pre') _postfile = os.path.realpath('hifa_tsysflag.last') _return_result_ = None _arguments = [vis,caltable,flag_nmedian,fnm_limit,fnm_byfield,flag_derivative,fd_max_limit,flag_edgechans,fe_edge_limit,flag_fieldshape,ff_refintent,ff_max_limit,flag_birdies,fb_sharps_limit,flag_toomany,tmf1_limit,tmef1_limit,metric_order,normalize_tsys,filetemplate,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 flag_nmedian is not None: local_global['flag_nmedian'] = flag_nmedian if flag_derivative is not None: local_global['flag_derivative'] = flag_derivative if flag_edgechans is not None: local_global['flag_edgechans'] = flag_edgechans if flag_fieldshape is not None: local_global['flag_fieldshape'] = flag_fieldshape if flag_birdies is not None: local_global['flag_birdies'] = flag_birdies if flag_toomany is not None: local_global['flag_toomany'] = flag_toomany if metric_order is not None: local_global['metric_order'] = metric_order if normalize_tsys is not None: local_global['normalize_tsys'] = normalize_tsys if filetemplate is not None: local_global['filetemplate'] = filetemplate 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['flag_nmedian'] = self.__flag_nmedian( local_global ) _invocation_parameters['flag_derivative'] = self.__flag_derivative( local_global ) _invocation_parameters['flag_edgechans'] = self.__flag_edgechans( local_global ) _invocation_parameters['flag_fieldshape'] = self.__flag_fieldshape( local_global ) _invocation_parameters['flag_birdies'] = self.__flag_birdies( local_global ) _invocation_parameters['flag_toomany'] = self.__flag_toomany( local_global ) _invocation_parameters['metric_order'] = self.__metric_order( local_global ) _invocation_parameters['normalize_tsys'] = self.__normalize_tsys( local_global ) _invocation_parameters['filetemplate'] = self.__filetemplate( 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['fnm_limit'] = self.__fnm_limit( _invocation_parameters ) if fnm_limit is None else fnm_limit _invocation_parameters['fnm_byfield'] = self.__fnm_byfield( _invocation_parameters ) if fnm_byfield is None else fnm_byfield _invocation_parameters['fd_max_limit'] = self.__fd_max_limit( _invocation_parameters ) if fd_max_limit is None else fd_max_limit _invocation_parameters['fe_edge_limit'] = self.__fe_edge_limit( _invocation_parameters ) if fe_edge_limit is None else fe_edge_limit _invocation_parameters['ff_refintent'] = self.__ff_refintent( _invocation_parameters ) if ff_refintent is None else ff_refintent _invocation_parameters['ff_max_limit'] = self.__ff_max_limit( _invocation_parameters ) if ff_max_limit is None else ff_max_limit _invocation_parameters['fb_sharps_limit'] = self.__fb_sharps_limit( _invocation_parameters ) if fb_sharps_limit is None else fb_sharps_limit _invocation_parameters['tmf1_limit'] = self.__tmf1_limit( _invocation_parameters ) if tmf1_limit is None else tmf1_limit _invocation_parameters['tmef1_limit'] = self.__tmef1_limit( _invocation_parameters ) if tmef1_limit is None else tmef1_limit _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['flag_nmedian'] = self.__flag_nmedian( self.__globals_( ) ) _invocation_parameters['fnm_limit'] = self.__fnm_limit( self.__globals_( ) ) _invocation_parameters['fnm_byfield'] = self.__fnm_byfield( self.__globals_( ) ) _invocation_parameters['flag_derivative'] = self.__flag_derivative( self.__globals_( ) ) _invocation_parameters['fd_max_limit'] = self.__fd_max_limit( self.__globals_( ) ) _invocation_parameters['flag_edgechans'] = self.__flag_edgechans( self.__globals_( ) ) _invocation_parameters['fe_edge_limit'] = self.__fe_edge_limit( self.__globals_( ) ) _invocation_parameters['flag_fieldshape'] = self.__flag_fieldshape( self.__globals_( ) ) _invocation_parameters['ff_refintent'] = self.__ff_refintent( self.__globals_( ) ) _invocation_parameters['ff_max_limit'] = self.__ff_max_limit( self.__globals_( ) ) _invocation_parameters['flag_birdies'] = self.__flag_birdies( self.__globals_( ) ) _invocation_parameters['fb_sharps_limit'] = self.__fb_sharps_limit( self.__globals_( ) ) _invocation_parameters['flag_toomany'] = self.__flag_toomany( self.__globals_( ) ) _invocation_parameters['tmf1_limit'] = self.__tmf1_limit( self.__globals_( ) ) _invocation_parameters['tmef1_limit'] = self.__tmef1_limit( self.__globals_( ) ) _invocation_parameters['metric_order'] = self.__metric_order( self.__globals_( ) ) _invocation_parameters['normalize_tsys'] = self.__normalize_tsys( self.__globals_( ) ) _invocation_parameters['filetemplate'] = self.__filetemplate( 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("%-15s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i])))) _f.write("#hifa_tsysflag( ") 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_tsysflag_t( _invocation_parameters['vis'],_invocation_parameters['caltable'],_invocation_parameters['flag_nmedian'],_invocation_parameters['fnm_limit'],_invocation_parameters['fnm_byfield'],_invocation_parameters['flag_derivative'],_invocation_parameters['fd_max_limit'],_invocation_parameters['flag_edgechans'],_invocation_parameters['fe_edge_limit'],_invocation_parameters['flag_fieldshape'],_invocation_parameters['ff_refintent'],_invocation_parameters['ff_max_limit'],_invocation_parameters['flag_birdies'],_invocation_parameters['fb_sharps_limit'],_invocation_parameters['flag_toomany'],_invocation_parameters['tmf1_limit'],_invocation_parameters['tmef1_limit'],_invocation_parameters['metric_order'],_invocation_parameters['normalize_tsys'],_invocation_parameters['filetemplate'],_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_tsysflag') casalog.post("Exception Reported: Error in hifa_tsysflag: %s" % str(e),'SEVERE') casalog.post(format_exc( )) _return_result_ = False try: os.rename(_prefile,_postfile) except: pass return _return_result_ hifa_tsysflag = _hifa_tsysflag( )