Exemple #1
0
def DescMakeIF(outUV, nIF, err):
    """ 
    Convert outUV descriptor divided into nIF IFs
    
    * outUV       = output Obit UV object
    * nIF         = number of desired output IFs
                    MUST be the same number of channels per IF
    * err         = Obit error/message stack
    """
    ################################################################
    d = outUV.Desc.Dict
    # Have IF axis?
    if d["jlocif"] >= 0:
        jlocif = d["jlocif"]
    else:  # create one
        jlocif = d['naxis']
        d['naxis'] += 1
        d['ctype'][jlocif] = "IF"
        d['crval'][jlocif] = 1.0
        d['crpix'][jlocif] = 1.0
        d['cdelt'][jlocif] = 1.0
        d['crota'][jlocif] = 0.0

    jlocf = d["jlocf"]
    nchan = d["inaxes"][jlocf] / nIF
    d["inaxes"][jlocif] = nIF
    d["inaxes"][jlocf] = nchan
    outUV.Desc.Dict = d
    UV.PGetIODesc(outUV).Dict = d  # And your little dog too
    # Update
    outUV.UpdateDesc(err)
    outUV.Open(UV.WRITEONLY, err)
    outUV.Close(err)
    #outUV.Header(err)
    OErr.printErrMsg(err, "Error converting Descriptor")
Exemple #2
0
def DescAddSource(inUV, outUV, err):
    """ 
    Update outUV descriptor for combined file
       
    * inUV        = input Obit UV object
    * outUV       = output Obit UV object, defined but not instantiated
    * err         = Obit error/message stack
    """
    ################################################################
    inUV.Clone(outUV, err)  # Clone input
    # Add Source id random parameter
    d = outUV.Desc.Dict
    if d["ilocsu"] < 0:
        d["ptype"][d["nrparm"]] = "SOURCE"
        d["nrparm"] += 1
        outUV.Desc.Dict = d
        UV.PGetIODesc(outUV).Dict = d  # And your little dog too
    # Update
    outUV.UpdateDesc(err)
    outUV.Open(UV.WRITEONLY, err)
    outUV.Close(err)
    #outUV.Header(err)
    OErr.printErrMsg(err, "Error converting Descriptor")
Exemple #3
0
def CopyData(inUV, outUV, err):
    """ 
    Copy the raw visibility records from inUV to outUV
    
    * inUV        = input Obit UV object
    * outUV       = output Obit UV object, defined but not instantiated
    * err         = Obit error/message stack
    """
    ################################################################
    # Checks, sizes should be the same
    id = inUV.Desc.Dict
    od = outUV.Desc.Dict
    odd = UV.PGetIODesc(outUV)
    if id['nrparm'] != od['nrparm']:
        raise RuntimeError("Input and output have different numbers of random parameters: " \
              +str(id['nrparm'])+" != "+str(od['nrparm']))
    if id['ncorr'] != od['ncorr']:
        raise RuntimeError("Input and output have different numbers of correlations: " \
              +str(id['ncorr'])+" != "+str(od['ncorr']))

    nvis = inUV.Desc.Dict['nvis']  # Number of records
    lrec = id['nrparm'] + id['ncorr'] * id["inaxes"][
        0]  # Size of record in floats

    # Set data to read one vis per IO
    inUV.List.set("nVisPIO", 1)
    outUV.List.set("nVisPIO", 1)

    # Open files
    zz = inUV.Open(UV.READONLY, err)
    zz = outUV.Open(UV.READWRITE, err)
    if err.isErr:
        OErr.printErrMsg(err, "Error opening UV")
    # Get IO buffers as numpy arrays
    shape = len(inUV.VisBuf) / 4
    ibuffer = numarray.array(sequence=inUV.VisBuf,
                             type=numarray.Float32,
                             shape=shape)
    obuffer = numarray.array(sequence=outUV.VisBuf,
                             type=numarray.Float32,
                             shape=shape)
    od['numVisBuff'] = 1
    # Gotta tell it to write 1 vis
    outUV.Desc.Dict = od
    outUV.IODesc.Dict = od

    # Loop over data, copying 1 vis at a time
    for ivis in range(1, nvis + 1):
        inUV.Read(err, firstVis=ivis)  # Read input
        if err.isErr:
            OErr.printErrMsg(err, "Error reading data")
        # Copy record
        obuffer[0:lrec] = ibuffer[0:lrec]
        outUV.Desc.Dict = od
        outUV.Write(err, firstVis=ivis)  # Write output
        if err.isErr:
            OErr.printErrMsg(err, "Error writing data")
        # end loop over data
    inUV.Close(err)
    outUV.Close(err)
    if err.isErr:
        OErr.printErrMsg(err, "Error closing data")
Exemple #4
0
def CopyData(inUV, outUV, err):
    """ 
    Copy the raw visibility records from inUV to outUV
    
    * inUV        = input Obit UV object
    * outUV       = output Obit UV object, defined but not instantiated
    * err         = Obit error/message stack
    """
    ################################################################
    od = outUV.Desc.Dict
    odd = UV.PGetIODesc(outUV)
    idd = inUV.Desc.Dict
    nvis = idd['nvis']  # Number of records
    ilrec = idd['nrparm'] + idd['ncorr'] * idd["inaxes"][
        0]  # Size of input record in floats
    olrec = od['nrparm'] + od['ncorr'] * od["inaxes"][
        0]  # Size of output record in floats
    inrparm = idd['nrparm']  # number of input random parameters
    onrparm = od['nrparm']  # number of output random parameters
    lcorr = idd['ncorr'] * idd["inaxes"][0]  # length of correlations
    ilocsu = idd['ilocsu']  # Input source ID offset
    olocsu = od['ilocsu']  # output source ID offset

    # Set data to read one vis per IO
    inUV.List.set("nVisPIO", 1)
    outUV.List.set("nVisPIO", 1)

    # Open files
    zz = outUV.Open(UV.READWRITE, err)
    zz = inUV.Open(UV.READONLY, err)
    if err.isErr:
        OErr.printErrMsg(err, "Error opening UVs")
    # Get IO buffers as numpy arrays
    shape = len(inUV.VisBuf) / 4
    ibuffer = numarray.array(sequence=inUV.VisBuf,
                             type=numarray.Float32,
                             shape=shape)
    shape = len(outUV.VisBuf) / 4
    obuffer = numarray.array(sequence=outUV.VisBuf,
                             type=numarray.Float32,
                             shape=shape)
    # Loop over data, copying 1 vis at a time
    for ivis in range(1, nvis + 1):
        inUV.Read(err, firstVis=ivis)  # Read input
        if err.isErr:
            OErr.printErrMsg(err, "Error reading data")
        # Random parameters from first
        obuffer[0:inrparm] = ibuffer[0:inrparm]
        # Source id if making it up
        if ilocsu < 0:
            obuffer[olocsu] = 1.0
        # Copy record parts from input
        obuffer[onrparm:olrec] = ibuffer[inrparm:ilrec]
        od = outUV.Desc.Dict
        od['numVisBuff'] = 1
        outUV.Desc.Dict = od  # Gotta tell it to write 1 vis
        outUV.Write(err, firstVis=ivis)  # Write output
        if err.isErr:
            OErr.printErrMsg(err, "Error writing data")
        # end loop over data
    #   close up
    outUV.Close(err)
    inUV.Close(err)
    if err.isErr:
        OErr.printErrMsg(err, "Error closing data")