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
# Make accumulation array and work array print "********** Accumulate Weighted FFTs of images *****************" accArray = FeatherUtil.PCreateFFTArray(FFTfor) CArray.PFill(accArray, [0.0,0.0]) workArray = FeatherUtil.PCreateFFTArray(FFTfor) # Loop accumulating images i = 0 for x in padImage: FeatherUtil.PAccumImage(FFTfor, x, wtArrays[i], accArray, workArray, err) OErr.printErrMsg(err, "Error accumulating array for "+inFile[i]) i = i + 1 # FFT back to image domain print "********** FFT back to image *****************" resultArray = FArray.PClone(Image.PGetFArray(padImage[0]), err); FeatherUtil.PBackFFT(FFTrev, accArray, resultArray, err) OErr.printErrMsg(err, "Error back transforming to image plane ") # Get normalization by repeating but using the padded images replaced by the beam print "********** Get normalization using point models *****************" CArray.PFill(accArray, [0.0,0.0]) # Loop accumulating normalization images i = 0 for x in padImage: modelArray = Image.PGetFArray(x); # get the FArray FeatherUtil.PCreateModel(x, modelArray) FeatherUtil.PAccumImage(FFTfor, x, wtArrays[i], accArray, workArray, err) OErr.printErrMsg(err, "Error accumulating array for "+inFile[i]) i = i + 1
# Get average ratio - loop over planes sumX = 0.0; sumWt = 0.0 # Zero accumulators for plane in range(Idim[2]): print "Plane",plane+1 planeDim = [plane+1,1,1,1,1] # Only 3D IImage.GetPlane(None, planeDim, err) # Read Ipol plane (IData) VImage.GetPlane(None, planeDim, err) # Read Vpol plane (VData) # Get IPol Image plane statistics for clipping pos=[0,0] Imax = FArray.PMax(IData, pos) Irms = IData.RMS Imin = max(Imax*MaxFactor,Irms*RMSFactor) print "Max",Imax,"RMS",Irms,"clip",Imin # Blank noise and below DR limit WtData = FArray.PCopy(IData, err) # Work array copy of IPol DivData = FArray.PClone(IData, err) # Clone of IPol array OErr.printErrMsg(err, "Error copying FArray") FArray.PClipBlank(WtData, Imin, 1.0e30) # Determine mean fractional VPol FArray.PDiv(VData, WtData, DivData) # Print Mean ratio print "Mean ratio",DivData.Mean # Multiple fraction times weight FArray.PMul(DivData, WtData, DivData) # Accumulate sumX = sumX + DivData.Sum sumWt = sumWt + WtData.Sum del WtData, DivData # Some cleanup # Get average instrumental VPol calibration