Esempio n. 1
0
def PBackFFT(FFTrev, inArray, outArray, err):
    """
    Back transform half plane complex to real
    
    inArray is FFTed (half plane complex - real) to outArray

    * FFTref   = FFT object to FT inArray
    * inArray  = CArray with image to be FFTed
      must be a size compatable with FFTrev
    * outArray = FArray for output
      must be a size compatable with FT of inArray
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not FFT.PIsA(FFTrev):
        print("Actually ",FFTrev.__class__)
        raise TypeError("FFTrev MUST be a Python Obit FFT")
    if not CArray.PIsA(inArray ):
        print("Actually ",inArray.__class__)
        raise TypeError("inArray MUST be a Python Obit CArray")
    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
    PFFTC2R (FFTrev, inArray, outArray)

    FArray.PCenter2D (outArray)
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
def PFFTC2R (inFFT, inArray, outArray):
    """
    Half plane complex to Real FFT

    * inFFT    = Python Obit FFT object
    * inArray  = Python CArray To be FFTed
    * outArray = Python FArray to contain the FFT
      Must previously exist
    """
    ################################################################
    if not FFT.PIsA(inFFT):
        raise TypeError("inFFT MUST be a Python Obit FFT")
    if not CArray.PIsA(inArray):
        print("Actually ",inArray.__class__)
        raise TypeError("inArray MUST be a Python Obit CArray")
    if not FArray.PIsA(outArray):
        print("Actually ",outArray.__class__)
        raise TypeError("outArray MUST be a Python Obit FArray")
    #
    FFT.PC2R(inFFT, inArray, outArray)
Esempio n. 5
0
def PFFTR2C(inFFT, inArray, outArray):
    """
    Real to half plane complex FFT

    * inFFT    = Python Obit FFT object
    * inArray  = Python FArray To be FFTed
    * outArray = Python CArray to contain the FFT
      Must previously exist
    """
    ################################################################
    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 CArray.PIsA(outArray):
        print "Actually ", outArray.__class__
        raise TypeError, "outArray MUST be a Python Obit CArray"
    #
    FFT.PR2C(inFFT, inArray, outArray)
Esempio n. 6
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
Esempio n. 7
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)
Esempio n. 8
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
Esempio n. 9
0
def PAccumImage(FFTfor, inImage, wtArray, accArray, workArray, err):
    """
    Accumulate the weighted FT of an FArray
    
    inImage is FFTed, multiplied by wtArray and accumulated into accArray

    * FFTfor   = FFT object to FT inArray
    * inImage  = Image to be accumulated
      must be a size compatable with FFTfor
      returned with contents swapped for FFTs
    * wtArray  = FArray containing accumulation weights
      must be a size compatable with FT of inArray
    * accArray = CArray in which the results are to be accumulated
      must be a size compatable with FT of inArray
    * workArray= CArray for temporary storage of FT of inArray
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not FFT.PIsA(FFTfor):
        print("Actually ",FFTfor.__class__)
        raise TypeError("FFTfor 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 FArray.PIsA(wtArray):
        print("Actually ",wtArray.__class__)
        raise TypeError("wtArray MUST be a Python Obit FArray")
    if not CArray.PIsA(accArray):
        print("Actually ",accArray.__class__)
        raise TypeError("accArray MUST be a Python Obit CArray")
    if not CArray.PIsA(workArray):
        print("Actually ",workArray.__class__)
        raise TypeError("workArray MUST be a Python Obit CArray")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    # Check compatability
    if not CArray.PIsCompatable (accArray, workArray):
        raise TypeError("accArray and workArray incompatible")

    # Get array from image
    inArray = Image.PGetFArray(inImage)

    # Swaparoonie
    FArray.PCenter2D (inArray)
    
    # FFT
    PFFTR2C (FFTfor, inArray, workArray)

    # Multiply by weights
    CArray.PFMul(workArray, wtArray, workArray)

    # Scale by inverse of beam area to get units the same
    # Get image info from descriptor
    desc     = inImage.Desc
    descDict = desc.Dict
    beamMaj = 3600.0 * descDict["beamMaj"]
    beamMin = 3600.0 * descDict["beamMin"]
    cdelt   = descDict["cdelt"]
    factor = (abs(cdelt[1])/beamMaj) * (abs(cdelt[1])/beamMin)
    CArray.PSMul(workArray, factor)

    # Accumulate
    CArray.PAdd(accArray, workArray, accArray)