コード例 #1
0
ファイル: PeelScripts.py プロジェクト: bill-cotton/Obit
def SubPeel(uv, source, imp, uvp, err, addBack=False, seq=999, \
                flagVer=0, nThreads=1, doGPU=False, noScrat=[0,0,0], taskLog='', debug=False):
    """
    Subtract Peel model w/ solutions, then optionally add back w/o corruptions
    
    UV data should have calibration tables from self calibration
    Output data will be on the same disk as the input, seq=seq, class='PelSub' and
    with name = source (up to 12 char).
    Returns Peel source subtracted/replaced data
    * uv        Dataset with cal tables
                Needs at least the self cal gain table
    * source    source name
    * imp       Peel source model (CC table from ImagePeel)
    * uvp       UV data the result of peel (ImagePeel)
    * err       Python Obit Error/message stack
    * seq       Sequence number for output
    * addBack   Add model back to data w/o corruptions? Not recommended.
    * flagVer   FG table to apply, -1=> no flag
    * nThreads  number of threads to use
    * doGPU     Use GPU if available?
    * noScrat   AIPS disks not to use for scratch
    * taskLog   Log file
    * debug     If True leave debug Input file in /tmp
    """
    ################################################################
    # Checks
    if not UV.PIsA(uv):
        raise TypeError("uv MUST be a Python Obit UV data")
    if not Image.PIsA(imp):
        raise TypeError("imp MUST be a Python Obit Image")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    # Split main data set
    OErr.PLog(err, OErr.Info, "Copy data")
    OErr.printErr(err)
    split = ObitTask('Split')
    setname(uv, split)
    split.outDisk = split.inDisk
    split.outSeq = seq
    split.outClass = 'UPeel'
    split.Sources[0] = source
    split.flagVer = flagVer
    if uv.GetHighVer('AIPS SN') > 0:
        split.doCalib = 2
        split.gainUse = 0
        split.doCalWt = True
    else:
        split.doCalib = -1
    split.taskLog = taskLog
    split.debug = debug
    split.g
    outClass = split.outClass
    outDisk = split.outDisk
    outSeq = split.outSeq

    # Get data
    OErr.PLog(err, OErr.Info, "Make Peel model with corruptions")
    OErr.printErr(err)
    if UV.AExist(source[0:12], outClass, outDisk, outSeq, err):
        datauv = UV.newPAUV('data', source[0:12], outClass, outDisk, outSeq,
                            True, err)
    else:
        datauv = UV.newPAUV('data', source[0:8], outClass, outDisk, outSeq,
                            True, err)
    # Make data set with the model peel source with peel cal applied
    uvsub = ObitTask('UVSub')
    setname(uv, uvsub)
    uvsub.outName = source[0:12]
    uvsub.outDisk = uvsub.inDisk
    uvsub.outSeq = 1
    uvsub.outClass = 'Model'
    uvsub.Sources[0] = source
    uvsub.flagVer = flagVer
    uvsub.doCalib = -1
    uvsub.gainUse = 0
    set2name(imp, uvsub)
    uvsub.CCVer = 1
    uvsub.nfield = 1
    uvsub.Cmethod = 'DFT'
    uvsub.Opcode = 'MODL'
    uvsub.PBCor = False
    uvsub.noScrat = noScrat
    uvsub.noNeg = False
    uvsub.taskLog = taskLog
    uvsub.nThreads = nThreads
    uvsub.doGPU = doGPU
    uvsub.debug = debug
    uvsub.g

    # Get model data
    modeluv = UV.newPAUV('model', uvsub.outName, uvsub.outClass, uvsub.outDisk,
                         uvsub.outSeq, True, err)
    # Copy/invert/unblank SN table from peeluv
    hiPeelSN = uvp.GetHighVer('AIPS SN')
    inTab = max(1, hiPeelSN)
    sntab = uvp.NewTable(Table.READONLY, 'AIPS SN', inTab, err)
    z = UVSelfCal.PInvertSN(sntab, modeluv, 1, True, err)
    # Apply calibration table in subtract
    modeluv.List.set('doCalSelect', True)
    modeluv.List.set('doCalib', 2)
    modeluv.List.set('gainUse', 1)
    modeluv.List.set('passAll', True)

    # Subtract model from main data
    OErr.PLog(err, OErr.Info, "Subtract Corrupted Peel model from uv data")
    UV.PUtilVisSub(datauv, modeluv, datauv, err)
    OErr.printErr(err)

    # Add model without corrupting calibration
    if addBack:
        OErr.PLog(err, OErr.Info, "Add Peel model without corruptions")
        uvsub = ObitTask('UVSub')
        setname(datauv, uvsub)
        setoname(datauv, uvsub)
        uvsub.outSeq = uvsub.inSeq + 1
        uvsub.Sources[0] = source
        uvsub.flagVer = flagVer
        uvsub.doCalib = -1
        uvsub.gainUse = 0
        set2name(imp, uvsub)
        uvsub.CCVer = 1
        uvsub.nfield = 1
        uvsub.Cmethod = 'DFT'
        uvsub.Factor = -1.
        uvsub.PBCor = False
        uvsub.noScrat = noScrat
        uvsub.noNeg = False
        uvsub.taskLog = taskLog
        uvsub.nThreads = nThreads
        uvsub.doGPU = doGPU
        uvsub.debug = debug
        uvsub.g
        outClass = uvsub.outClass
        outDisk = uvsub.outDisk
        outSeq = uvsub.outSeq
        # end add back
    OErr.printErr(err)
    # Delete model dataset
    if not debug:
        modeluv.Zap(err)

# final data
    if UV.AExist(source[0:12], outClass, outDisk, outSeq, err):
        datauv2 = UV.newPAUV('data', source[0:12], outClass, outDisk, outSeq,
                             True, err)
    else:
        datauv2 = UV.newPAUV('data', source[0:8], outClass, outDisk, outSeq,
                             True, err)
    return datauv2
コード例 #2
0
ファイル: PeelScripts.py プロジェクト: bill-cotton/Obit
def UVSub4Peel(uv, source, im, inCC, err, \
                   nfield=1, doGPU=False, gainUse=1, flagVer=-1, \
                   nThreads=1, noScrat=[0,0,0], taskLog='', debug=False):
    """
    Sets up for subtraction of non peel sources from data
    
    UV data should be have calibration tables from self calibration
    Output data will be on the same disk as the input, seq=1, class='4Peel' and
    with the name of the source (up to 12 char)
    Returns UVSub task object
    * uv        Dataset to be subtracted from
    * source    source name
    * im        Python Image with CC Tables
    * inCC      input CC version, should have had the peel source CCs removed
                using SelectCC
    * err       Python Obit Error/message stack
    * doGPU     Use GPU if available?
    * nfield    Number of facet images
    * gainUse   CL (SN) table to apply, -1=> no cal
    * flagVer   FG table to apply, -1=> no flag
    * noThreads number of threads to use
    * noScrat   AIPS disks not to use for scratch
    * taskLog   Log file
    * debug     If True leave debug Input file in /tmp
    """
    ################################################################
    # Checks
    if not UV.PIsA(uv):
        raise TypeError("uv MUST be a Python Obit UV data")
    if not Image.PIsA(im):
        raise TypeError("im MUST be a Python Obit Image")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    uvsub = ObitTask('UVSub')
    setname(uv, uvsub)
    set2name(im, uvsub)
    uvsub.CCVer = inCC
    uvsub.nfield = nfield
    if uv.FileType == 'AIPS':
        uvsub.DataType = 'AIPS'
    else:
        uvsub.DataType = 'FITS'
    if im.FileType == 'AIPS':
        uvsub.DataType2 = 'AIPS'
    else:
        uvsub.DataType2 = 'FITS'
    uvsub.outDisk = uvsub.inDisk
    uvsub.outSeq = 1
    uvsub.outClass = '4Peel'
    uvsub.outName = source[0:12]
    uvsub.nThreads = nThreads
    uvsub.noScrat = noScrat
    uvsub.Cmethod = 'DFT'
    uvsub.noNeg = False
    uvsub.doGPU = doGPU
    uvsub.PBCor = False
    uvsub.taskLog = taskLog
    uvsub.debug = debug
    uvsub.flagVer = flagVer
    uvsub.Sources[0] = source
    if gainUse >= 0:
        uvsub.doCalib = 2
        uvsub.gainUse = gainUse
    return uvsub