Beispiel #1
0
def PCreateFFT(image, dir):
    """
    Create an FFT object suitable for FFTing an image
    
    Create an FFT for an efficient size equal to or larger than image
    One needed for each direction to be FFTed.
    returns  Python FFT object

    * image    = Image to be FFTed
    * dir      = FFT direction 1 -> R2C, 2 -> C2R
    """
    ################################################################
    # Checks
    if not Image.PIsA(image):
        raise TypeError("image MUST be a Python Obit Image")
    #
    # Get image info from descriptor
    desc = image.Desc
    descDict = desc.Dict
    rank = 2    # Only 2D FFTs
    dim  = descDict["inaxes"]
    # Compute size to be efficient
    i = 0
    effDim = []
    for x in dim:
        effDim.append(FFT.PSuggestSize(x))
        i = i+1
    effDim
    name = "FFT for " + Image.PGetName(image)
    out    = FFT.FFT(name, dir, 2, rank, effDim)
    return out
Beispiel #2
0
def PTimeFilterResize (filter, nTime):
    """ Resize Filter

    Change number of time samples in filter
    Note: the actual size will be the result of FFT.PSuggestSize(nTime)
    filter   = time filter
    nTime    = minimum number of time elements
    """
    ################################################################
    # Checks
    if not PIsA(filter):
        print "Actually ",filter.__class__
        raise TypeError,"filter MUST be a Python Obit TimeFilter"
    n = FFT.PSuggestSize(nTime);  # How many actual points?
    Obit.TimeFilterResize (filter.me, n)
Beispiel #3
0
def PImageFFT(inImage, outAImage, outPImage, err):
    """
    FFTs an Image
    
    FFT inImage and write as real and imaginary as full plane (hermetian) 

    * inImage   = input Obit Python Image 1
      Any BLC and/or TRC set will be honored
    * outAImage = output Obit Python Amplitude image of FFT
      must be defined but not instantiated
    * outPImage = output Obit Python Phase (deg) image of FFT
      must be defined but not instantiated
    * err       = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Image.PIsA(inImage):
        raise TypeError("inImage MUST be a Python Obit Image")
    if not Image.PIsA(outAImage):
        raise TypeError("outAImage MUST be a Python Obit Image")
    if not Image.PIsA(outPImage):
        raise TypeError("outPImage MUST be a Python Obit Image")
    if not err.IsA():
        raise TypeError("err MUST be an OErr")
    #
    # Clone output images
    inImage.Clone(outAImage, err)
    inImage.Clone(outPImage, err)
    OErr.printErrMsg(err, "Error initializing images")

    # Size of FFT
    inImage.Open(Image.READONLY, err)
    inImage.Read(err)
    OErr.printErrMsg(err, "Error reading input")
    inHead = inImage.Desc.Dict
    FFTdim = [
        FFT.PSuggestSize(inHead["inaxes"][0]),
        FFT.PSuggestSize(inHead["inaxes"][1])
    ]

    # Create float arrays for FFT size
    inFArray = FArray.FArray("inF", naxis=FFTdim)
    outFArray = FArray.FArray("outF", naxis=FFTdim)

    # Create FFT for full complex FFT
    FFTfor = FFT.FFT("FFT", 1, 1, 2, FFTdim)

    # Create complex arrays for FFT size
    inCArray = CArray.CArray("inC", naxis=FFTdim)
    outCArray = CArray.CArray("outC", naxis=FFTdim)

    #Loop over planes
    nplane = inImage.Desc.Dict['inaxes'][2]
    for iax in range(1, nplane + 1):
        inImage.GetPlane(None, [iax, 1, 1, 1, 1], err)
        OErr.printErrMsg(err, "Error reading input")
        # Pad input into work FArray
        FArray.PPad(inImage.FArray, inFArray, 1.0)
        # and God said "The center of an FFT will be at the corners"
        FArray.PCenter2D(inFArray)
        # Zero output FArray and use as imaginary part
        FArray.PFill(outFArray, 0.0)
        # Copy input to scratch CArray
        CArray.PComplex(inFArray, outFArray, inCArray)

        # FFT
        FFT.PC2C(FFTfor, inCArray, outCArray)

        # Extract amplitude, write
        CArray.PAmp(outCArray, outFArray)
        # and God said "The center of an FFT will be at the corners"
        FArray.PCenter2D(outFArray)
        outAImage.FArray = FeatherUtil.PExtract(FFTfor, outFArray,
                                                outAImage.FArray, err)
        OErr.printErrMsg(err, "Error extracting output amplitude plane")
        outAImage.PutPlane(outAImage.FArray, [iax, 1, 1, 1, 1], err)

        # Extract phase, write
        CArray.PPhase(outCArray, outFArray)
        # To degrees
        FArray.PSMul(outFArray, 57.2956)
        # and God said "The center of an FFT will be at the corners"
        FArray.PCenter2D(outFArray)
        outPImage.FArray = FeatherUtil.PExtract(FFTfor, outFArray,
                                                outPImage.FArray, err)
        OErr.printErrMsg(err, "Error extracting output phase plane")
        outPImage.PutPlane(outPImage.FArray, [iax, 1, 1, 1, 1], err)
        # Error?
        OErr.printErrMsg(err, "Error writing output phase image")
        # end loop over planes

    # Fix headers
    outAImage.Open(Image.READWRITE, err)
    FFTHeaderUpdate(outAImage, FFTdim, err)
    outAImage.Close(err)
    OErr.printErrMsg(err, "Error writing output amplitude image")

    outPImage.Open(Image.READWRITE, err)
    FFTHeaderUpdate(outPImage, FFTdim, err)
    outPImage.Close(err)
    OErr.printErrMsg(err, "Error writing output phase image")

    # get any BLC, TRC for history
    info = inImage.List.Dict
    blc = [1, 1, 1, 1, 1, 1, 1]
    if 'BLC' in info:
        blc = info["BLC"][2]
    trc = [0, 0, 0, 0, 0, 0, 0]
    if 'TRC' in info:
        trc = info["TRC"][2]

    # Write history
    i = 0
    imtype = ("Amplitude", "Phase")
    for outImage in (outAImage, outPImage):
        inHistory = History.History("history", inImage.List, err)
        outHistory = History.History("history", outImage.List, err)
        # Copy History
        # FITS? - copy header
        if ("FileType" in info) and (info["FileType"][2][0] == 0):
            History.PCopyHeader(inHistory, outHistory, err)
        #Not needed History.PCopy(inHistory, outHistory, err)
        # Add this programs history
        outHistory.Open(History.READWRITE, err)
        outHistory.TimeStamp(" Start Obit PImageFFT", err)
        outHistory.TimeStamp(OSystem.PGetPgmName() + " BLC = " + str(blc), err)
        outHistory.TimeStamp(OSystem.PGetPgmName() + " TRC = " + str(trc), err)
        outHistory.TimeStamp(OSystem.PGetPgmName() + " type = " + imtype[i],
                             err)
        i += 1
        outHistory.Close(err)
Beispiel #4
0
outPDisk = 1

# Convert files into Images
inImage  = Image.newPFImage(inFile, inFile, inDisk, True, err)
outAImage  = Image.newPFImage(outAFile, outAFile, outADisk, False, err)
inImage.Clone(outAImage,err)
outPImage  = Image.newPFImage(outPFile, outPFile, outPDisk, False, err)
inImage.Clone(outPImage,err)
OErr.printErrMsg(err, "Error initializing images")

# Size of FFT
inImage.Open(Image.READONLY, err)
inImage.Read(err)
OErr.printErrMsg(err, "Error reading input")
inHead = inImage.Desc.Dict
FFTdim = [FFT.PSuggestSize(inHead["inaxes"][0]), FFT.PSuggestSize(inHead["inaxes"][1])]

# Create float arrays for FFT size
inFArray  = FArray.FArray("inF", naxis=FFTdim)
outFArray = FArray.FArray("outF", naxis=FFTdim)

# Pad input into work FArray
FArray.PPad(inImage.FArray, inFArray, 1.0)
# and God said "The center of an FFT will be at the corners"
FArray.PCenter2D(inFArray)
# Zero output FArray and use as imaginary part
FArray.PFill(outFArray, 0.0)

# Create FFT for full complex FFT
FFTfor = FFT.FFT("FFT", 1, 1, 2, FFTdim)