Source code for pipeline.hsd.cli.hsd_tsysflag

##################### generated by xml-casa (v2) from hsd_tsysflag.xml ##############
##################### b8b6b1951a7f0e62c953dff248a67ac7 ##############################
from __future__ import absolute_import
import numpy
from casatools.typecheck import CasaValidator as _val_ctor
_pc = _val_ctor( )
from casatools.coercetype import coerce as _coerce
from .private.task_hsd_tsysflag import hsd_tsysflag as _hsd_tsysflag_t
from casatasks.private.task_logging import start_log as _start_log
from casatasks.private.task_logging import end_log as _end_log

class _hsd_tsysflag:
    """
    hsd_tsysflag ---- Flag deviant system temperature measurements

    
    Flag deviant system temperatures for single dish 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 single dish 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:
    
    hsd_tsysflag()
    
    2. Flag Tsys measurements using all recommended tests apart from that
    using the 'fieldshape' metric:
    
    hsd_tsysflag(flag_fieldshape=False)


    """

    _info_group_ = """pipeline"""
    _info_desc_ = """Flag deviant system temperature measurements"""

    def __call__( self, vis=[  ], caltable=[  ], flag_nmedian=True, fnm_limit=float(2.0), fnm_byfield=True, flag_derivative=True, fd_max_limit=float(5.0), flag_edgechans=True, fe_edge_limit=float(3.0), flag_fieldshape=True, ff_refintent='BANDPASS', ff_max_limit=float(13), flag_birdies=True, fb_sharps_limit=float(0.05), flag_toomany=True, tmf1_limit=float(0.666), tmef1_limit=float(0.666), metric_order='nmedian,derivative,edgechans,fieldshape,birdies,toomany', normalize_tsys=False, filetemplate=[  ], pipelinemode='automatic', dryrun=False, acceptresults=True ):
        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'}}
        doc = {'vis': vis, 'caltable': caltable, 'flag_nmedian': flag_nmedian, 'fnm_limit': fnm_limit, 'fnm_byfield': fnm_byfield, 'flag_derivative': flag_derivative, 'fd_max_limit': fd_max_limit, 'flag_edgechans': flag_edgechans, 'fe_edge_limit': fe_edge_limit, 'flag_fieldshape': flag_fieldshape, 'ff_refintent': ff_refintent, 'ff_max_limit': ff_max_limit, 'flag_birdies': flag_birdies, 'fb_sharps_limit': fb_sharps_limit, 'flag_toomany': flag_toomany, 'tmf1_limit': tmf1_limit, 'tmef1_limit': tmef1_limit, 'metric_order': metric_order, 'normalize_tsys': normalize_tsys, 'filetemplate': filetemplate, 'pipelinemode': pipelinemode, 'dryrun': dryrun, 'acceptresults': acceptresults}
        assert _pc.validate(doc,schema), str(_pc.errors)
        _logging_state_ = _start_log( 'hsd_tsysflag', [ 'vis=' + repr(_pc.document['vis']), 'caltable=' + repr(_pc.document['caltable']), 'flag_nmedian=' + repr(_pc.document['flag_nmedian']), 'fnm_limit=' + repr(_pc.document['fnm_limit']), 'fnm_byfield=' + repr(_pc.document['fnm_byfield']), 'flag_derivative=' + repr(_pc.document['flag_derivative']), 'fd_max_limit=' + repr(_pc.document['fd_max_limit']), 'flag_edgechans=' + repr(_pc.document['flag_edgechans']), 'fe_edge_limit=' + repr(_pc.document['fe_edge_limit']), 'flag_fieldshape=' + repr(_pc.document['flag_fieldshape']), 'ff_refintent=' + repr(_pc.document['ff_refintent']), 'ff_max_limit=' + repr(_pc.document['ff_max_limit']), 'flag_birdies=' + repr(_pc.document['flag_birdies']), 'fb_sharps_limit=' + repr(_pc.document['fb_sharps_limit']), 'flag_toomany=' + repr(_pc.document['flag_toomany']), 'tmf1_limit=' + repr(_pc.document['tmf1_limit']), 'tmef1_limit=' + repr(_pc.document['tmef1_limit']), 'metric_order=' + repr(_pc.document['metric_order']), 'normalize_tsys=' + repr(_pc.document['normalize_tsys']), 'filetemplate=' + repr(_pc.document['filetemplate']), 'pipelinemode=' + repr(_pc.document['pipelinemode']), 'dryrun=' + repr(_pc.document['dryrun']), 'acceptresults=' + repr(_pc.document['acceptresults']) ] )
        return _end_log( _logging_state_, 'hsd_tsysflag', _hsd_tsysflag_t( _pc.document['vis'], _pc.document['caltable'], _pc.document['flag_nmedian'], _pc.document['fnm_limit'], _pc.document['fnm_byfield'], _pc.document['flag_derivative'], _pc.document['fd_max_limit'], _pc.document['flag_edgechans'], _pc.document['fe_edge_limit'], _pc.document['flag_fieldshape'], _pc.document['ff_refintent'], _pc.document['ff_max_limit'], _pc.document['flag_birdies'], _pc.document['fb_sharps_limit'], _pc.document['flag_toomany'], _pc.document['tmf1_limit'], _pc.document['tmef1_limit'], _pc.document['metric_order'], _pc.document['normalize_tsys'], _pc.document['filetemplate'], _pc.document['pipelinemode'], _pc.document['dryrun'], _pc.document['acceptresults'] ) )

hsd_tsysflag = _hsd_tsysflag( )