Source code for pipeline.hifa.cli.hifa_bandpassflag

##################### generated by xml-casa (v2) from hifa_bandpassflag.xml #########
##################### 5df97ea7120ffe62bf98c4322f4de6fd ##############################
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_hifa_bandpassflag import hifa_bandpassflag as _hifa_bandpassflag_t
from casatasks.private.task_logging import start_log as _start_log
from casatasks.private.task_logging import end_log as _end_log

class _hifa_bandpassflag:
    """
    hifa_bandpassflag ---- Bandpass calibration flagging

    
    This task performs a preliminary phased-up bandpass solution and temporarily
    applies it, then computes the flagging heuristics by calling
    hif_correctedampflag which looks for outlier visibility points by statistically
    examining the scalar difference of the corrected amplitudes minus model
    amplitudes, and then flags those outliers. The philosophy is that only outlier
    data points that have remained outliers after calibration will be flagged. Note
    that the phase of the data is not assessed.
    
    Plots are generated at two points in this workflow: after bandpass calibration
    but before flagging heuristics are run, and after flagging heuristics have been
    run and applied. If no points were flagged, the 'after' plots are not generated
    or displayed.
    
    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. Defaults to the list of
                   MeasurementSets specified in the pipeline context.
                   
                   Example: vis=['ngc5921.ms']
    caltable       List of names for the output calibration tables. Defaults
                   to the standard pipeline naming convention.
                   
                   Example: caltable=['ngc5921.gcal']
    intent         A string containing a comma delimited list of intents against
                   which the selected fields are matched. Set to intent='' by default, which
                   means the task will select all data with the BANDPASS intent.
                   
                   Example: intent='*PHASE*'
    field          The list of field names or field ids for which bandpasses are
                   computed. Set to field='' by default, which means the task will select all
                   fields.
                   
                   Example: field='3C279', field='3C279,M82'
    spw            The list of spectral windows and channels for which bandpasses are
                   computed. Set to spw='' by default, which means the task will select all
                   science spectral windows.
                   
                   Example: spw='11,13,15,17'
    antenna        Set of data selection antenna IDs
    hm_phaseup     The pre-bandpass solution phaseup gain heuristics. The options are:
                   'snr': compute solution required to achieve the specified SNR
                   'manual': use manual solution parameters
                   '': skip phaseup
                   
                   Example: hm_phaseup='manual'
    phaseupsolint  The phase correction solution interval in CASA syntax.
                   Used when hm_phaseup='manual' or as a default if the hm_phaseup='snr'
                   heuristic computation fails.
                   
                   Example: phaseupsolint='300s'
    phaseupbw      Bandwidth to be used for phaseup. Used when hm_phaseup='manual'.
                   
                   Example: phaseupbw='' to use entire bandpass
                            phaseupbw='500MHz' to use central 500MHz
    phaseupsnr     The required SNR for the phaseup solution. Used only if
                   hm_phaseup='snr'.
                   
                   Example: phaseupsnr=10.0
    phaseupnsols   The minimum number of phaseup gain solutions. Used only if
                   hm_phaseup='snr'.
                   
                   Example: phaseupnsols=4
    hm_bandpass    The bandpass solution heuristics. The options are:
                   'snr': compute the solution required to achieve the specified SNR
                   'smoothed': simple smoothing heuristics
                   'fixed': use the user defined parameters for all spws
    solint         Time and channel solution intervals in CASA syntax.
                   
                   Default is solint='inf', which is used when hm_bandpass='fixed'.
                   If hm_bandpass is set to 'snr', then the task will attempt to compute and use
                   an optimal SNR-based solint (and warn if this solint is not good enough).
                   If hm_bandpass is set to 'smoothed', the task will use a smoothed solint.
    maxchannels    The bandpass solution smoothing factor in channels. The
                   solution interval is bandwidth / 240. Set to 0 for no smoothing.
                   Used if hm_bandpass='smoothed'.
                   
                   Example: maxchannels=0
    evenbpints     Force the per spw frequency solint to be evenly divisible
                   into the spw bandpass if hm_bandpass='snr'.
                   
                   Example: evenbpints=False
    bpsnr          The required SNR for the bandpass solution. Used only if
                   hm_bandpass='snr'.
                   
                   Example: bpsnr=30.0
    minbpsnr       The minimum required SNR for the bandpass solution
                   when strong atmospheric lines exist in Tsys spectra.
                   Used only if hm_bandpass='snr'.
                   
                   Example: minbpsnr=10.0
    bpnsols        The minimum number of bandpass solutions. Used only if
                   hm_bandpass='snr'.
    combine        Data axes to combine for solving. Axes are '', 'scan', 'spw',
                   'field' or any comma-separated combination.
                   
                   Example: combine='scan,field'
    refant         List of reference antenna names. Defaults to the value(s) stored in the
                   pipeline context. If undefined in the pipeline context defaults to
                   the CASA reference antenna naming scheme.
                   
                   Example: refant='DV06,DV07'
    minblperant    Minimum number of baselines required per antenna for each solve.
                   Antennas with fewer baselines are excluded from solutions.
    minsnr         Solutions below this SNR are rejected
    solnorm        Normalise the bandpass solution
    antnegsig      Lower sigma threshold for identifying outliers as a result of bad
                   antennas within individual timestamps.
    antpossig      Upper sigma threshold for identifying outliers as a result of bad
                   antennas within individual timestamps.
    tmantint       Threshold for maximum fraction of timestamps that are allowed to
                   contain outliers.
    tmint          Initial threshold for maximum fraction of 'outlier timestamps'
                   over 'total timestamps' that a baseline may be a part of.
    tmbl           Initial threshold for maximum fraction of 'bad baselines' over
                   'all baselines' that an antenna may be a part of.
    antblnegsig    Lower sigma threshold for identifying outliers as a result of
                   'bad baselines' and/or 'bad antennas' within baselines (across all
                   timestamps).
    antblpossig    Upper sigma threshold for identifying outliers as a result of
                   'bad baselines' and/or 'bad antennas' within baselines (across all
                   timestamps).
    relaxed_factor Relaxed value to set the threshold scaling factor to under
                   certain conditions (see task description).
    niter          Maximum number of times to iterate on evaluation of flagging
                   heuristics. If an iteration results in no new flags, then subsequent
                   iterations are skipped.
    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  Automatically accept the results of the task into the pipeline context (True)
                   or reject them (False).

    --------- examples -----------------------------------------------------------

    
    1. run with recommended settings to create bandpass solution with flagging
    using recommended thresholds:
    
    hifa_bandpassflag()


    """

    _info_group_ = """pipeline"""
    _info_desc_ = """Bandpass calibration flagging"""

    def __call__( self, vis=[  ], caltable=[  ], intent='', field='', spw='', antenna='', hm_phaseup='snr', phaseupsolint='int', phaseupbw='', phaseupsnr=float(20.0), phaseupnsols=int(2), hm_bandpass='snr', solint='inf', maxchannels=int(240), evenbpints=True, bpsnr=float(50.0), minbpsnr=float(20.0), bpnsols=int(8), combine='scan', refant='', minblperant=int(4), minsnr=float(3.0), solnorm=True, antnegsig=float(4.0), antpossig=float(4.6), tmantint=float(0.063), tmint=float(0.085), tmbl=float(0.175), antblnegsig=float(3.4), antblpossig=float(3.2), relaxed_factor=float(2.0), niter=int(2), 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]}, 'intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'field': {'type': 'cStr', 'coerce': _coerce.to_str}, 'spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'antenna': {'type': 'cStr', 'coerce': _coerce.to_str}, 'hm_phaseup': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'snr', 'manual', '' ]}, 'phaseupsolint': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'phaseupbw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'phaseupsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'phaseupnsols': {'type': 'cInt'}, 'hm_bandpass': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'snr', 'smoothed', 'fixed' ]}, 'solint': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'maxchannels': {'type': 'cInt'}, 'evenbpints': {'type': 'cBool'}, 'bpsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'minbpsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'bpnsols': {'type': 'cInt'}, 'combine': {'type': 'cStr', 'coerce': _coerce.to_str}, 'refant': {'type': 'cStr', 'coerce': _coerce.to_str}, 'minblperant': {'type': 'cInt'}, 'minsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'solnorm': {'type': 'cBool'}, 'antnegsig': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'antpossig': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'tmantint': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'tmint': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'tmbl': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'antblnegsig': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'antblpossig': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'relaxed_factor': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'niter': {'type': 'cInt'}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}}
        doc = {'vis': vis, 'caltable': caltable, 'intent': intent, 'field': field, 'spw': spw, 'antenna': antenna, 'hm_phaseup': hm_phaseup, 'phaseupsolint': phaseupsolint, 'phaseupbw': phaseupbw, 'phaseupsnr': phaseupsnr, 'phaseupnsols': phaseupnsols, 'hm_bandpass': hm_bandpass, 'solint': solint, 'maxchannels': maxchannels, 'evenbpints': evenbpints, 'bpsnr': bpsnr, 'minbpsnr': minbpsnr, 'bpnsols': bpnsols, 'combine': combine, 'refant': refant, 'minblperant': minblperant, 'minsnr': minsnr, 'solnorm': solnorm, 'antnegsig': antnegsig, 'antpossig': antpossig, 'tmantint': tmantint, 'tmint': tmint, 'tmbl': tmbl, 'antblnegsig': antblnegsig, 'antblpossig': antblpossig, 'relaxed_factor': relaxed_factor, 'niter': niter, 'pipelinemode': pipelinemode, 'dryrun': dryrun, 'acceptresults': acceptresults}
        assert _pc.validate(doc,schema), str(_pc.errors)
        _logging_state_ = _start_log( 'hifa_bandpassflag', [ 'vis=' + repr(_pc.document['vis']), 'caltable=' + repr(_pc.document['caltable']), 'intent=' + repr(_pc.document['intent']), 'field=' + repr(_pc.document['field']), 'spw=' + repr(_pc.document['spw']), 'antenna=' + repr(_pc.document['antenna']), 'hm_phaseup=' + repr(_pc.document['hm_phaseup']), 'phaseupsolint=' + repr(_pc.document['phaseupsolint']), 'phaseupbw=' + repr(_pc.document['phaseupbw']), 'phaseupsnr=' + repr(_pc.document['phaseupsnr']), 'phaseupnsols=' + repr(_pc.document['phaseupnsols']), 'hm_bandpass=' + repr(_pc.document['hm_bandpass']), 'solint=' + repr(_pc.document['solint']), 'maxchannels=' + repr(_pc.document['maxchannels']), 'evenbpints=' + repr(_pc.document['evenbpints']), 'bpsnr=' + repr(_pc.document['bpsnr']), 'minbpsnr=' + repr(_pc.document['minbpsnr']), 'bpnsols=' + repr(_pc.document['bpnsols']), 'combine=' + repr(_pc.document['combine']), 'refant=' + repr(_pc.document['refant']), 'minblperant=' + repr(_pc.document['minblperant']), 'minsnr=' + repr(_pc.document['minsnr']), 'solnorm=' + repr(_pc.document['solnorm']), 'antnegsig=' + repr(_pc.document['antnegsig']), 'antpossig=' + repr(_pc.document['antpossig']), 'tmantint=' + repr(_pc.document['tmantint']), 'tmint=' + repr(_pc.document['tmint']), 'tmbl=' + repr(_pc.document['tmbl']), 'antblnegsig=' + repr(_pc.document['antblnegsig']), 'antblpossig=' + repr(_pc.document['antblpossig']), 'relaxed_factor=' + repr(_pc.document['relaxed_factor']), 'niter=' + repr(_pc.document['niter']), 'pipelinemode=' + repr(_pc.document['pipelinemode']), 'dryrun=' + repr(_pc.document['dryrun']), 'acceptresults=' + repr(_pc.document['acceptresults']) ] )
        return _end_log( _logging_state_, 'hifa_bandpassflag', _hifa_bandpassflag_t( _pc.document['vis'], _pc.document['caltable'], _pc.document['intent'], _pc.document['field'], _pc.document['spw'], _pc.document['antenna'], _pc.document['hm_phaseup'], _pc.document['phaseupsolint'], _pc.document['phaseupbw'], _pc.document['phaseupsnr'], _pc.document['phaseupnsols'], _pc.document['hm_bandpass'], _pc.document['solint'], _pc.document['maxchannels'], _pc.document['evenbpints'], _pc.document['bpsnr'], _pc.document['minbpsnr'], _pc.document['bpnsols'], _pc.document['combine'], _pc.document['refant'], _pc.document['minblperant'], _pc.document['minsnr'], _pc.document['solnorm'], _pc.document['antnegsig'], _pc.document['antpossig'], _pc.document['tmantint'], _pc.document['tmint'], _pc.document['tmbl'], _pc.document['antblnegsig'], _pc.document['antblpossig'], _pc.document['relaxed_factor'], _pc.document['niter'], _pc.document['pipelinemode'], _pc.document['dryrun'], _pc.document['acceptresults'] ) )

hifa_bandpassflag = _hifa_bandpassflag( )