Exemple #1
0
def PMakeBeamMask(inImage, inFFT, err):
    """
    Make uv plane weighting array
    
    Creates an FArray the size of a plane in inImage, FFT,
    takes real part and normalizes the central value to one
    Resulting array is returned.

    * inImage  = Python Image whose FArray is to be converted to a weight mask
    * inFFT    = Python Obit fortward FFT object
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Image.PIsA(inImage):
        print "Actually ", inImage.__class__
        raise TypeError, "inImage MUST be a Python Obit Image"
    if not FFT.PIsA(inFFT):
        print "Actually ", inFFT.__class__
        raise TypeError, "inFFT MUST be a Python Obit FFT"
    #
    # Make copy of data array
    inArray = inImage.FArray
    outArray = FArray.PClone(inArray, err)
    #OErr.printErrMsg(err, "Error duplicating FArray for "+Image.PGetName(inImage))

    # Add model
    PCreateModel(inImage, outArray)

    # Pad for FFT
    FFTdim = FFT.PGetDim(inFFT)
    FFTArray = FArray.PClone(inArray, err)
    naxis = FFTdim[0:2]  # Make output big enough for FFT
    FFTArray = FArray.FArray("FFT array", naxis)
    PPadArray(inFFT, outArray, FFTArray)
    del outArray  # Cleanup

    # Swaparoonie
    FArray.PCenter2D(FFTArray)

    # FFT
    uvArray = PCreateFFTArray(inFFT)
    PFFTR2C(inFFT, FFTArray, uvArray)
    del FFTArray  # Cleanup

    # Extract Real part
    naxis = CArray.PGetNaxis(uvArray)[0:2]
    maskArray = FArray.FArray("Mask array for " + Image.PGetName(inImage),
                              naxis)
    CArray.PReal(uvArray, maskArray)
    del uvArray  # Cleanup

    # Normalize
    pos = [0, 1 + naxis[1] / 2]
    peak = FArray.PMax(maskArray, pos)
    norm = 1.0 / peak
    FArray.PSMul(maskArray, norm)

    return maskArray
Exemple #2
0
def PExtract (inFFT, inArray, outArray, err):
    """
    Extract a Real array from one padded for FFTs
    
    Any blanked values are replaces with zeroes
    returns outArray

    * inFFT    = Gives size of FFT used
    * inArray  = Python FArray with FFT results.
    * outArray = Python FArray describing results
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not FFT.PIsA(inFFT):
        raise TypeError("inFFT MUST be a Python Obit FFT")
    if not FArray.PIsA(inArray):
        print("Actually ",inArray.__class__)
        raise TypeError("inArray MUST be a Python Obit FArray")
    if not FArray.PIsA(outArray):
        print("Actually ",outArray.__class__)
        raise TypeError("outArray MUST be a Python Obit FArray")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    # FFT info
    FFTrank = FFT.PGetRank(inFFT)
    FFTdim  = FFT.PGetDim(inFFT)
    
    # Target Array info
    ArrayNdim  = outArray.Ndim
    ArrayNaxis = outArray.Naxis

    # Get window to extract
    cen = [FFTdim[0]//2, FFTdim[1]//2];
    blc = [0,0]; trc=[0,0]
    blc[0] = cen[0] - ArrayNaxis[0] // 2; trc[0] = cen[0] - 1 + ArrayNaxis[0] // 2
    blc[1] = cen[1] - ArrayNaxis[1] // 2; trc[1] = cen[1] - 1 + ArrayNaxis[1] // 2
    # Make sure to fill output array
    if ((trc[0]-blc[0]+1)<ArrayNaxis[0]):
        trc[0] = blc[0] + ArrayNaxis[0] - 1
    if ((trc[1]-blc[1]+1)<ArrayNaxis[1]):
        trc[1] = blc[1] + ArrayNaxis[1] - 1

    # Extract
    out = FArray.PSubArr(inArray, blc, trc, err)
    return out
Exemple #3
0
def PCreateFFTArray(inFFT):
    """
    Create a half plane CArray suitable for the output of FFTing an image
    
    returns  Python CArray object of suitable size (2D)

    * inFFT  = FFT to be applied
    """
    ################################################################
    # Checks
    if not FFT.PIsA(inFFT):
        raise TypeError("inFFT MUST be a Python Obit FFT")
    #
    # FFT info
    FFTrank = FFT.PGetRank(inFFT)
    FFTdim  = FFT.PGetDim(inFFT)

    naxis = FFTdim[0:2]
    naxis[0] = 1 + naxis[0]//2
    out = CArray.CArray ("Temp CArray for FFT", naxis)
    return out
Exemple #4
0
def PPadArray (inFFT, inArray, outArray):
    """
    Zero Pads an array as needed for an FFT
    
    Any blanked values are replaced with zeroes

    * inFFT    = Gives size of FFT needed
    * inArray  = Python FArray to be padded.
    * outArray = Python FArray containing inArray but zero filled.
      Must previously exist.
    """
    ################################################################
    # Checks
    if not FFT.PIsA(inFFT):
        raise TypeError("inFFT MUST be a Python Obit FFT")
    if not FArray.PIsA(inArray):
        print("Actually ",inArray.__class__)
        raise TypeError("inArray MUST be a Python Obit FArray")
    if not FArray.PIsA(outArray):
        print("Actually ",outArray.__class__)
        raise TypeError("outArray MUST be a Python Obit FArray")
    #
    # FFT info
    FFTrank = FFT.PGetRank(inFFT)
    FFTdim  = FFT.PGetDim(inFFT)

    # Array info
    ArrayNdim  = inArray.Ndim
    ArrayNaxis = inArray.Naxis

    # Zero fill output
    FArray.PFill(outArray, 0.0)

    # Insert inArray into outArray - center as well as possible
    pos1 = [FFTdim[0]//2, FFTdim[1]//2]
    pos2 = [ArrayNaxis[0]//2, ArrayNaxis[1]//2]
    FArray.PShiftAdd (outArray, pos1, inArray, pos2, 1.0, outArray)

    # Replace any blanks with zeroes
    FArray.PDeblank(outArray, 0.0)
Exemple #5
0
def PPad (inFFT, inImage, outImage, err):
    """
    Zero Pads an image as needed for an FFT
    
    Any blanked values are replaced with zeroes

    * inFFT    = Gives size of FFT needed
    * inImage  = Python Obit Image to be padded.
    * outImage = Python Obit Image for output
      Must previously exist
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not FFT.PIsA(inFFT):
        raise TypeError("inFFT MUST be a Python Obit FFT")
    if not Image.PIsA(inImage):
        print("Actually ",inImage.__class__)
        raise TypeError("inImage MUST be a Python Obit Image")
    if not Image.PIsA(outImage):
        print("Actually ",outImage.__class__)
        raise TypeError("outImage MUST be a Python Obit Image")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    # Read input, Copy Descriptor
    inImage.Open(Image.READONLY, err)
    inImage.Read(err)
    desc = inImage.Desc
    inImage.Close(err)
    #OErr.printErrMsg(err, "Error reading input image "+Image.PGetName(inImage))
    
    # FFT info
    FFTrank = FFT.PGetRank(inFFT)
    FFTdim  = FFT.PGetDim(inFFT)

    # Get data arrays
    inArray = inImage.FArray
    naxis = FFTdim[0:2]   # Make output big enough for FFT
    outArray = FArray.FArray("Padded array", naxis)

    # Copy/pad/deblank array
    # debugPPadArray (inFFT, inArray, outArray)
    FArray.PPad(inArray, outArray, 1.0)

    # Reset output image size of first two axes
    naxis = outArray.Naxis                    # output size
    descDict = desc.Dict                      # Input Python dict object
    dim   = descDict["inaxes"]                # input size
    crpix = descDict["crpix"]
    # Update reference pixel, pixel shift an integral number
    pixOff = [naxis[0]//2-dim[0]//2, naxis[1]//2-dim[1]//2]
    crpix[0] = crpix[0] + pixOff[0]
    crpix[1] = crpix[1] + pixOff[1]
    # Update size
    dim[0] = naxis[0];
    dim[1] = naxis[1]
    descDict["inaxes"] = dim   
    descDict["bitpix"] = -32  # output floating
    desc = outImage.Desc    # Replace descriptor on output
    desc.Dict = descDict

    # Write output image
    outImage.Open(Image.WRITEONLY, err)
    outImage.WriteFA(outArray, err)
    outImage.Close(err)
    outImage.FArray = outArray  # Now attach array to image to