Source code for pipeline.hifa.cli.hifa_wvrgcal

##################### generated by xml-casa (v2) from hifa_wvrgcal.xml ##############
##################### 6cb055d7c8307b96c81fab81131fe1f8 ##############################
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_wvrgcal import hifa_wvrgcal as _hifa_wvrgcal_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_wvrgcal:
    """
    hifa_wvrgcal ---- 
    Generate a gain table based on Water Vapor Radiometer data, and calculate
    a QA score based on its effect on the interferometric data.

    
    Generate a gain table based on the Water Vapor Radiometer data in each vis
    file. By applying the wvr calibration to the data specified by 'qa_intent' and
    'qa_spw', calculate a QA score to indicate its effect on interferometric data;
    a score > 1 implies that the phase noise is improved, a score < 1 implies
    that it is made worse. If the score is less than 'accept_threshold' then the
    wvr gain table is not accepted into the context for subsequent use.

    --------- parameter descriptions ---------------------------------------------

    vis                List of input visibility files.
                       
                       default: none, in which case the vis files to be used will be read
                                from the context. 
                       example: vis=['ngc5921.ms']
    caltable           List of output gain calibration tables.
                       
                       default: none, in which case the names of the caltables will be
                                generated automatically.
                       example: caltable='ngc5921.wvr'
    offsetstable       List of input temperature offsets table files to subtract from
                       WVR measurements before calculating phase corrections.
                       
                       default: none, in which case no offsets are applied.
                       example: offsetstable=['ngc5921.cloud_offsets']
    hm_toffset         If 'manual', set the 'toffset' parameter to the user-specified value.
                       If 'automatic', set the 'toffset' parameter according to the
                       date of the MeasurementSet; toffset=-1 if before 2013-01-21T00:00:00
                       toffset=0 otherwise.
    toffset            Time offset (sec) between interferometric and WVR data.
    segsource          If True calculate new atmospheric phase correction coefficients
                       for each source, subject to the constraints of the 'tie' parameter.
                       'segsource' is forced to be True if the 'tie' parameter is set to a
                       non-empty value by the user or by the automatic heuristic.
    sourceflag         Flag the WVR data for these source(s) as bad and do not produce
                       corrections for it. Requires segsource=True.
                       
                       example: ['3C273']
    hm_tie             If 'manual', set the 'tie' parameter to the user-specified value.
                       If 'automatic', set the 'tie' parameter to include with the
                       target all calibrators that are within 15 degrees of it:
                       if no calibrators are that close then 'tie' is left empty.
    tie                Use the same atmospheric phase correction coefficients when 
                       calculating the wvr correction for all sources in the 'tie'. If 'tie'
                       is not empty then 'segsource' is forced to be True. Ignored unless
                       hm_tie='manual'.
                       
                       example: ['3C273,NGC253', 'IC433,3C279']
    nsol               Number of solutions for phase correction coefficients during this
                       observation, evenly distributed in time throughout the observation. It
                       is used only if segsource=False because if segsource=True then the
                       coefficients are recomputed whenever the telescope moves to a new source
                       (within the limits imposed by 'tie').
    disperse           Apply correction for dispersion.
    wvrflag            Flag the WVR data for the listed antennas as bad and replace 
                       their data with values interpolated from the 3 nearest antennas with
                       unflagged data.
                       
                       example: ['DV03','DA05','PM02']
    hm_smooth          If 'manual' set the 'smooth' parameter to the user-specified value.
                       If 'automatic', run the wvrgcal task with the range of 'smooth' parameters
                       required to match the integration time of the wvr data to that of the
                       interferometric data in each spectral window.
    smooth             Smooth WVR data on this timescale before calculating the correction.
                       Ignored unless hm_smooth='manual'.
    scale              Scale the entire phase correction by this factor.
    maxdistm           Maximum distance in meters of an antenna used for interpolation
                       from a flagged antenna.
                       
                       default: -1  (automatically set to 100m if >50% of antennas are 7m
                           antennas without WVR and otherwise set to 500m)
                       example: maxdistm=550
    minnumants         Minimum number of nearby antennas (up to 3) used for
                       interpolation from a flagged antenna.
                       
                       example: minnumants=3
    mingoodfrac        Minimum fraction of good data per antenna.
    refant             Ranked comma delimited list of reference antennas.
                       
                       example: refant='DV01,DV02'
    qa_intent          The list of data intents on which the wvr correction is to be 
                       tried as a means of estimating its effectiveness.
                       
                       A QA 'view' will be calculated for each specified intent, in each spectral
                       window in each vis file.
                       
                       Each QA 'view' will consist of a pair of 2-d images with dimensions
                       ['ANTENNA', 'TIME'], one showing the data phase-noise before the 
                       wvr application, the second showing the phase noise after (both 'before'
                       and 'after' images have a bandpass calibration applied as well).
                       
                       An overall QA score is calculated for each vis file, by dividing the
                       'before' images by the 'after' and taking the median of the result. An
                       overall score of 1 would correspond to no change in the phase noise,
                       a score > 1 implies an improvement.
                       
                       If the overall score for a vis file is less than the value in          
                       'accept_threshold' then the wvr calibration file is not made available 
                       for merging into the context for use in the subsequent reduction.
                       
                       If you do not want any QA calculations then set qa_intent=''.
                       
                       example: qa_intent='PHASE'
    qa_bandpass_intent The data intent to use for the bandpass calibration in
                       the qa calculation. The default is blank to allow the underlying bandpass
                       task to select a sensible intent if the dataset lacks BANDPASS data.
    qa_spw             The SpW(s) to use for the qa calculation, in the order that they
                       should be tried. Input as a comma-separated list. The default is blank, in
                       which case the task will try SpWs in order of decreasing median sky
                       opacity.
    accept_threshold   The phase-rms improvement ratio
                       (rms without wvr / rms with wvr) above which the wrvg file will be
                       accepted into the context for subsequent application.
    pipelinemode       
    dryrun             
    acceptresults      

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

    
    Example
    
    1. Compute the WVR calibration for all the MeasurementSets:
    
    hifa_wvrgcal(hm_tie='automatic')


    """

    _info_group_ = """pipeline"""
    _info_desc_ = """
Generate a gain table based on Water Vapor Radiometer data, and calculate
a QA score based on its effect on the interferometric data.
"""

    def __call__( self, vis=[  ], caltable=[  ], offsetstable=[  ], hm_toffset='automatic', toffset=float(0), segsource=True, sourceflag=[  ], hm_tie='automatic', tie=[  ], nsol=int(1), disperse=False, wvrflag=[  ], hm_smooth='automatic', smooth='', scale=float(1.), maxdistm=float(-1), minnumants=int(2), mingoodfrac=float(0.8), refant='', qa_intent='', qa_bandpass_intent='', qa_spw='', accept_threshold=float(1.0), 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]}, 'offsetstable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_toffset': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'manual', 'automatic' ]}, 'toffset': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'segsource': {'type': 'cBool'}, 'sourceflag': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_tie': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'manual', 'automatic' ]}, 'tie': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'nsol': {'type': 'cInt'}, 'disperse': {'type': 'cBool'}, 'wvrflag': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'hm_smooth': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'manual', 'automatic' ]}, 'smooth': {'type': 'cStr', 'coerce': _coerce.to_str}, 'scale': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'maxdistm': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'minnumants': {'type': 'cInt', 'allowed': [ 1, 2, 3 ]}, 'mingoodfrac': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'refant': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_bandpass_intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'qa_spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'accept_threshold': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}}
        doc = {'vis': vis, 'caltable': caltable, 'offsetstable': offsetstable, 'hm_toffset': hm_toffset, 'toffset': toffset, 'segsource': segsource, 'sourceflag': sourceflag, 'hm_tie': hm_tie, 'tie': tie, 'nsol': nsol, 'disperse': disperse, 'wvrflag': wvrflag, 'hm_smooth': hm_smooth, 'smooth': smooth, 'scale': scale, 'maxdistm': maxdistm, 'minnumants': minnumants, 'mingoodfrac': mingoodfrac, 'refant': refant, 'qa_intent': qa_intent, 'qa_bandpass_intent': qa_bandpass_intent, 'qa_spw': qa_spw, 'accept_threshold': accept_threshold, 'pipelinemode': pipelinemode, 'dryrun': dryrun, 'acceptresults': acceptresults}
        assert _pc.validate(doc,schema), str(_pc.errors)
        _logging_state_ = _start_log( 'hifa_wvrgcal', [ 'vis=' + repr(_pc.document['vis']), 'caltable=' + repr(_pc.document['caltable']), 'offsetstable=' + repr(_pc.document['offsetstable']), 'hm_toffset=' + repr(_pc.document['hm_toffset']), 'toffset=' + repr(_pc.document['toffset']), 'segsource=' + repr(_pc.document['segsource']), 'sourceflag=' + repr(_pc.document['sourceflag']), 'hm_tie=' + repr(_pc.document['hm_tie']), 'tie=' + repr(_pc.document['tie']), 'nsol=' + repr(_pc.document['nsol']), 'disperse=' + repr(_pc.document['disperse']), 'wvrflag=' + repr(_pc.document['wvrflag']), 'hm_smooth=' + repr(_pc.document['hm_smooth']), 'smooth=' + repr(_pc.document['smooth']), 'scale=' + repr(_pc.document['scale']), 'maxdistm=' + repr(_pc.document['maxdistm']), 'minnumants=' + repr(_pc.document['minnumants']), 'mingoodfrac=' + repr(_pc.document['mingoodfrac']), 'refant=' + repr(_pc.document['refant']), 'qa_intent=' + repr(_pc.document['qa_intent']), 'qa_bandpass_intent=' + repr(_pc.document['qa_bandpass_intent']), 'qa_spw=' + repr(_pc.document['qa_spw']), 'accept_threshold=' + repr(_pc.document['accept_threshold']), 'pipelinemode=' + repr(_pc.document['pipelinemode']), 'dryrun=' + repr(_pc.document['dryrun']), 'acceptresults=' + repr(_pc.document['acceptresults']) ] )
        return _end_log( _logging_state_, 'hifa_wvrgcal', _hifa_wvrgcal_t( _pc.document['vis'], _pc.document['caltable'], _pc.document['offsetstable'], _pc.document['hm_toffset'], _pc.document['toffset'], _pc.document['segsource'], _pc.document['sourceflag'], _pc.document['hm_tie'], _pc.document['tie'], _pc.document['nsol'], _pc.document['disperse'], _pc.document['wvrflag'], _pc.document['hm_smooth'], _pc.document['smooth'], _pc.document['scale'], _pc.document['maxdistm'], _pc.document['minnumants'], _pc.document['mingoodfrac'], _pc.document['refant'], _pc.document['qa_intent'], _pc.document['qa_bandpass_intent'], _pc.document['qa_spw'], _pc.document['accept_threshold'], _pc.document['pipelinemode'], _pc.document['dryrun'], _pc.document['acceptresults'] ) )

hifa_wvrgcal = _hifa_wvrgcal( )