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
def PConvBeam(CCTab, Beam, Template, err): """ Convolve a set of Clean components with a beam image CCTab CC Table, following parameters on infoList member "BComp" OBIT_int (1,1,1) Start CC to use, 1-rel [def 1 ] "EComp" OBIT_int (1,1,1) Highest CC to use, 1-rel [def to end ] Beam Beam Image to convolve with CCs Template Template FArray for output array err Obit Error stack Returns an ObitFArray whose size is that of Template, spacing is that of Beam with the CCs in CCTab convolved with Beam and the (0,0) position is (nx/2,ny/2) (0-rel) """ ################################################################ # Checks if not Table.PIsA(CCTab): raise TypeError, "CCTab MUST be a Python Obit Table" if not OErr.OErrIsA(err): raise TypeError, "err MUST be a Python ObitErr" # out = FArray.FArray("Convolved CCs") if err.isErr: # existing error? return out out.me = Obit.OTFUtilConvBeam(CCTab.me, Beam.me, Template.me, err.me) return out
def PBigger (naxis, inImage, outImage, err): """ Increases the size of an image and zero pads Any blanked values are replaced with zeroes * naxis = dimension array of desired output * 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 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)) # Get data arrays inArray = inImage.FArray outArray = FArray.FArray("Padded array", naxis) # Copy/pad/deblank array 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
def PImPix(inPixHistFDR): """ Return the Image Pixel FArray returns Image Pixel FArray inPixHistFDR = Python PixHistFDR object """ ################################################################ # Checks if not PIsA(inPixHistFDR): raise TypeError("inPixHistFDR MUST be a Python Obit PixHistFDR") # out = FArray.FArray("ImPix") out.me = Obit.FArrayUnref(out.me) out.me = Obit.PixHistFDRGetImPix(inPixHistFDR.me) return out
def PDifHist(inPixHistFDR): """ Return the differential pixel histogram returns differential pixel histogram inPixHistFDR = Python PixHistFDR object """ ################################################################ # Checks if not PIsA(inPixHistFDR): raise TypeError("inPixHistFDR MUST be a Python Obit PixHistFDR") # out = FArray.FArray("DifHist") out.me = Obit.FArrayUnref(out.me) out.me = Obit.PixHistFDRGetHisto(inPixHistFDR.me) return out
def PIntHist(inPixHistFDR): """ Return the integrated pixel histogram returns integrated pixel histogram inPixHistFDR = Python PixHistFDR object """ ################################################################ # Checks if not PIsA(inPixHistFDR): raise TypeError("inPixHistFDR MUST be a Python Obit PixHistFDR") # out = FArray.FArray("IntHist") out.me = Obit.FArrayUnref(out.me) out.me = Obit.PixHistFDRGetIntHisto(inPixHistFDR.me) return out
def PGetFArray(inFI): """ Get Associated FArray reference return FArray (data being interpolated) reference * inFI = Python Obit input FInterpolate """ ################################################################ # Checks if not PIsA(inFI): raise TypeError("inFI MUST be a Python Obit FInterpolate") # out = FArray.FArray("None") out.me = Obit.FInterpolateGetFArray(inFI.me) return out
def PDifHist(inPixHistFDR): """ Return the differential pixel histogram returns differential pixel histogram inPixHistFDR = Python PixHistFDR object """ ################################################################ # Checks if not PIsA(inPixHistFDR): raise TypeError, "inPixHistFDR MUST be a Python Obit PixHistFDR" # sm = inPixHistFDR.cast(myClass) # cast pointer out = FArray.FArray("DifHist") out.me = Obit.FArrayUnref(out.me) out.me = Obit.PixHistFDRGetHisto(sm) return out
def PImPix(inPixHistFDR): """ Return the Image Pixel FArray returns Image Pixel FArray inPixHistFDR = Python PixHistFDR object """ ################################################################ # Checks if not PIsA(inPixHistFDR): raise TypeError, "inPixHistFDR MUST be a Python Obit PixHistFDR" # sm = inPixHistFDR.cast(myClass) # cast pointer out = FArray.FArray("ImPix") out.me = Obit.FArrayUnref(out.me) out.me = Obit.PixHistFDRGetImPix(sm) return out
def PMakeF(Cin): """ Make an FArray with the same geometry as a CArray return FArray size of CArray * Cin = input Python CArray """ ################################################################ # Checks if not PIsA(Cin): print("Actually ", iCn.__class__) raise TypeError("Cin MUST be a Python Obit CArray") outFA = FArray.FArray("None") outFA.me = Obit.CArrayMakeF(Cin.me) return outFA
def PGetFArray(inImageMF): """ Return FArray used to buffer Image data returns FArray with image pixel data * inImageMF = Python Image object """ ################################################################ if inImageMF.myClass == 'AIPSImage': raise TypeError("Function unavailable for " + inImage.myClass) # Checks if not inImageMF.ImageMFIsA(): raise TypeError("inImageMF MUST be a Python Obit Image") # out = FArray.FArray("None") out.me = Obit.ImageMFGetFArray(inImageMF.me) return out
def PUVGaus(naxis, cells, maprot, maj, min, pa): """ Create a Gaussian UV tapering image corresponding to an image plane Gaussian Returns an FArray with a Gaussian taper, as [u,v] * naxis = dimension as [nx,ny] * cells = cell spacing in x and y in units of maj,min (asec) * maprot = Map rotation (deg) * maj = Major axis of Gaussian in image plane (same units as cells) * min = Minor axis of Gaussian in image plane (same units as cells) * pa = Position angle of Gaussian in image plane, from N thru E, (deg) """ ################################################################ # Create output outFA = FArray.FArray("UVpix", naxis) outFA.me = Obit.FArrayUtilUVGaus(naxis, cells, maprot, maj, min, pa) return outFA
def PGetFArray(inImageMF): """ Return FArray used to buffer Image data returns FArray with image pixel data * inImageMF = Python Image object """ ################################################################ if ('myClass' in inImageMF.__dict__) and (inImageMF.myClass == 'AIPSImage'): raise TypeError("Function unavailable for " + inImageMF.myClass) inCast = inImageMF.cast('ObitImageMF') # Checks if not PIsA(inImageMF): raise TypeError("inImageMF MUST be a Python Obit ImageMF") # out = FArray.FArray("None") out.me = Obit.ImageMFGetFArray(inImageMF.me) return out
def PGaus(inImage, Beam): """ Create an ObitFArray containing a unit area Gaussian in the center returns Python FArray object with normalized Gaussian * inImage = Obit Image with geometry * Beam = [maj, min, PA] defining eliptical Gaussian size in image cell units or pixels if none given """ ################################################################ # Checks if not Image.PIsA(inImage): print "Actually ", inImage.__class__ raise TypeError, "inImage MUST be a Python Obit Image" if len(Beam) < 3: raise TypeError, "Beam MUST have 3 elements" # outFA = FArray.FArray("None") outFA.me = Obit.ConvUtilGaus(inImage.me, Beam[0], Beam[1], Beam[2]) return outFA
def PConvolve(inFA1, inFA2, err): """ Return the convolution of two 2-D arrays inFA1 and inFA2 must be compatible size and should not contain magic value blanks. Convolved array returned. * inFA1 = First array * inFA2 = Second array * err = Python Obit Error/message stack """ ################################################################ # Checks if not FArray.PIsA(inFA1): raise TypeError, "inFA1 MUST be a Python Obit FArray" if not FArray.PIsA(inFA2): raise TypeError, "inFA2 MUST be a Python Obit FArray" # outFA = FArray.FArray("None") outFA.me = Obit.FArrayUtilConvolve(inFA1.me, inFA2.me, err.me) return outFA
imagDict["crpix"][0] = nx / 2 + 1 imagDict["crpix"][1] = ny / 2 + 1 imagDict["bitpix"] = -32 imagDict["bunit"] = "JY/BEAM" imagDict["beamMin"] = beamsize imagDict["beamMaj"] = beamsize imagDict["beamPA"] = 0.0 # Update descriptor outImage.Desc.Dict = imagDict # Image.PFullInstantiate(outImage, 2, err) OErr.printErrMsg(err, "Error creating image") # Create FArray for image data = FArray.FArray("Image Data", [nx, ny]) # Add Gaussian FWHM = beamsize / abs(xCells) # beam size in pixels FArray.PCGauss2D(data, [nx / 2, ny / 2], FWHM) # Write output Image.PWritePlane(outImage, data, err) # Say something print "Wrote beam with size", beamsize * 3600.0, "to", outFile # Shutdown Obit OErr.printErr(err) del ObitSys
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)
outRow['IF FREQ'][i * inNIF + j] = rrr['IF FREQ'][j] + inRefFreq - outRefFreq outRow['SIDEBAND'][i * inNIF + j] = rrr['SIDEBAND'][j] outRow['CH WIDTH'][i * inNIF + j] = rrr['CH WIDTH'][j] outRow['TOTAL BANDWIDTH'][i * inNIF + j] = rrr['TOTAL BANDWIDTH'][j] xfq.Close(err) del xfq, rrr outFQ.WriteRow(1, outRow, err) outFQ.Close(err) OErr.printErrMsg(err, message='Error creating output FQ Table') # Cleanup del outRow # Work arrays work = FArray.FArray('work', [ncell, ncell]) # work array for interpolated image work2 = FArray.FArray('work2', [ncell, ncell]) # work array for interpolated image accWI = FArray.FArray('accWI', [ncell, ncell]) # Sum wt * image accW = FArray.FArray('accW', [ncell, ncell]) # Sum wt # Pixel array images XPixIm = Image.Image("XPixIm") YPixIm = Image.Image("YPixIm") outIm.List.set('BLC', [1, 1, 1, 1, 1, 1, 1]) outIm.List.set('TRC', [0, 0, 1, 1, 1, 1, 1]) outIm.Open(Image.READWRITE, err) outIm.Close(err) Image.PCloneMem(outIm, XPixIm, err) Image.PCloneMem(outIm, YPixIm, err) outIm.List.set('TRC', [0, 0, 0, 0, 1, 1, 1])
import OErr, OSystem, Image, InfoList, FArray err = OErr.OErr() ObitSys = OSystem.OSystem("Python", 1, 103, 1, ["None"], 1, ["../PythonData/"], 1, 0, err) OErr.printErrMsg(err, "Error with Obit startup") # for debugging #OErr.Bomb() list = InfoList.InfoList() dim = [1, 0, 0, 0, 0] InfoList.PPutLong(list, "longItem", dim, [321], err) x = InfoList.PGet(list, "longItem") x = FArray.FArray("MyFArray", [30, 50]) FArray.PSetVal(x, [25, 25], 3.1415926) pos = [-1, -1] result = FArray.PMax(x, pos) print "FArray max is", result, "should be 3.1415926" result = FArray.PMin(x, pos) print "FArray min is", result, "should be 0" file = "testPcube.fits" disk = 1 image = Image.newPFImage("myImage", file, disk, True, err) OErr.printErr(err) Image.POpen(image, 1, err) OErr.printErr(err) Image.PRead(image, err) OErr.printErr(err)
def PMakeMaster(template, size, SumWtImage, SumWt2, err): """ Create a pair of images to accumulation of partial products Create an image to contain the Sum of the input Images times the weights, and another for the sum of the weights squared. The descriptive material is from image template * template = Image with position etc, to be copied * size = output image size in pixels, e.g. [200,200] * SumWtImage = First output image, must be defined (i.e. files named) but not fully created. * SumWt2 = Second output image, like SumWtImage * err = Python Obit Error/message stack """ ################################################################ # Checks if not Image.PIsA(template): print "Actually ",template.__class__ raise TypeError,"template MUST be a Python Obit Image" if not Image.PIsA(SumWtImage): print "Actually ",SumWtImage.__class__ raise TypeError,"SumWtImage MUST be a Python Obit Image" if not Image.PIsA(SumWt2): print "Actually ",SumWt2.__class__ raise TypeError,"SumWt2 MUST be a Python Obit Image" if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" # # Get image info from template Image.POpen (template, 1, err) Image.PRead (template, err) desc = Image.PGetDesc(template) descDict = ImageDesc.PGetDict(desc) # Python dict object listDict = template.Desc.List.Dict Image.PClose (template, err) #OErr.printErrMsg(err, "Error reading input image "+Image.PGetName(template)) # # Create zero filled array for data outArray = FArray.FArray("Initial array", size) # # Modify the descriptor for output. naxis = size[0:3] # Update reference pixel, pixel shift an integral number dim = descDict["inaxes"] pixOff = [naxis[0]/2-dim[0]/2, naxis[1]/2-dim[1]/2] crpix = descDict["crpix"] crpix[0] = crpix[0] + pixOff[0] crpix[1] = crpix[1] + pixOff[1] # Update size dim[0] = naxis[0]; dim[1] = naxis[1] #print "debug dim",dim descDict["inaxes"] = dim descDict["bitpix"] = -32 # output floating # # Do SumWtImage desc = Image.PGetDesc(SumWtImage) InfoList.PSetDict(desc.List, listDict) # Copy list stuff ImageDesc.PSetDict(desc, descDict) # set output descriptor # Write output image Image.POpen(SumWtImage, 2, err) nplane = template.Desc.Dict["inaxes"][2] for iplane in range(1,(nplane+1)): plane = [iplane,1,1,1,1] SumWtImage.PutPlane(outArray, plane, err) Image.PClose(SumWtImage, err) #OErr.printErrMsg(err, "Error writing image for "+Image.PGetName(SumWtImage)) # # Do SumWt2Image desc = Image.PGetDesc(SumWt2) InfoList.PSetDict(desc.List, listDict) # Copy list stuff ImageDesc.PSetDict(desc, descDict) # set output descriptor # Write output image Image.POpen(SumWt2, 2, err) for iplane in range(1,(nplane+1)): plane = [iplane,1,1,1,1] SumWt2.PutPlane(outArray, plane, err) Image.PClose(SumWt2, err) #OErr.printErrMsg(err, "Error writing image for "+Image.PGetName(SumWt2)) # Write history - sorta inHistory = History.History("history", template.List, err) outHistory = History.History("history", SumWtImage.List, err) # Copy History History.PCopy(inHistory, outHistory, err) outHistory.Open(History.READWRITE, err) outHistory.TimeStamp(" Start Obit PMakeMaster",err) outHistory.Close(err)
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
def RestorePeel(peelMod, CCVer, image, err): """ Restore CCs from one image onto another If images are ImageMF then multiple planes restored. * peelMod Image with CC table (as Image) * CCver CC version on peelMod to restore * image Output Image to which components to be added * err Python Obit Error/message stack * nThreads number of threads to use """ ################################################################ import Obit, Image, ImageDesc, SkyGeom, Table, History, OErr import UV, UVDesc, OSystem, UVSelfCal, FArray # Checks if not Image.PIsA(peelMod): raise TypeError("uv MUST be a Python Obit Image") if not Image.PIsA(image): raise TypeError("imp MUST be a Python Obit Image") ph = peelMod.Desc.Dict ih = image.Desc.Dict # Descriptors ph_x = ph['crval'][0] ph_y = ph['crval'][1] ph_rot = ph['crota'][1] ph_dx = ph['cdelt'][0] ph_dy = ph['cdelt'][1] ph_type = ph['ctype'][0][4:] ph_ref_x = ph['crpix'][0] ph_ref_y = ph['crpix'][1] ih_x = ih['crval'][0] ih_y = ih['crval'][1] ih_rot = ih['crota'][1] ih_dx = ih['cdelt'][0] ih_dy = ih['cdelt'][1] ih_type = ih['ctype'][0][4:] ih_ref_x = ih['crpix'][0] ih_ref_y = ih['crpix'][1] bmaj = ih['beamMaj'] bmin = ih['beamMin'] bpa = ih['beamPA'] bmaj /= abs(ih_dx) bmin /= abs(ih_dx) # Beam in pixels (square grid) #Beam to insert beam = FArray.FArray('beam', naxis=[21, 21]) bx = 10. by = 10. FArray.PEGauss2D(beam, 1.0, [bx, by], [bmaj, bmin, bpa]) cctab = peelMod.NewTable(Table.READONLY, 'AIPS CC', CCVer, err) # CC Table cctab.Open(Table.READONLY, err) OErr.printErr(err) # First plane image.GetPlane(None, [1, 1, 1, 1, 1], err) imArr = image.FArray ncc = cctab.Desc.Dict['nrow'] # Number of CCs for irow in range(1, ncc + 1): row = cctab.ReadRow(irow, err) flux = row['FLUX'][0] dx = row['DELTAX'][0] dy = row['DELTAY'][0] dz = row['DELTAZ'][0] [ierr, ra, dec] = SkyGeom.PWorldPosLM(dx, dy, ph_x, ph_y, ph_dx, ph_dy, ph_rot, ph_type) # output pixel [ierr, xpix, ypix] = SkyGeom.PXYpix(ra, dec, ih_x, ih_y, ih_ref_x, ih_ref_y, ih_dx, ih_dy, ih_rot, ih_type) # Need beam if correct location tbx = xpix - int(xpix + 0.5) tby = ypix - int(ypix + 0.5) FArray.PFill(beam, 0.0) FArray.PEGauss2D(beam, 1.0, [bx + tbx, by + tby], [bmaj, bmin, bpa]) # Add FArray.PShiftAdd( imArr, [int(xpix + 0.5) - 1, int(ypix + 0.5) - 1], beam, [int(bx + 0.5), int(by + 0.5)], flux, imArr) # end loop image.PutPlane(None, [1, 1, 1, 1, 1], err) # rewrite # MFImage Planes if ih['ctype'][2] == 'SPECLNMF ': nterm = image.Desc.List.Dict['NTERM'][2][0] nspec = image.Desc.List.Dict['NSPEC'][2][0] for ip in range(nterm + 1, nterm + nspec + 1): image.GetPlane(None, [ip, 1, 1, 1, 1], err) imArr = image.FArray for irow in range(1, ncc + 1): row = cctab.ReadRow(irow, err) flux = row['PARMS'][3 + ip - nterm] dx = row['DELTAX'][0] dy = row['DELTAY'][0] dz = row['DELTAZ'][0] [ierr, ra, dec] = SkyGeom.PWorldPosLM(dx, dy, ph_x, ph_y, ph_dx, ph_dy, ph_rot, ph_type) # output pixel [ierr, xpix, ypix] = SkyGeom.PXYpix(ra, dec, ih_x, ih_y, ih_ref_x, ih_ref_y, ih_dx, ih_dy, ih_rot, ih_type) # Need beam in correct location tbx = xpix - int(xpix + 0.5) tby = ypix - int(ypix + 0.5) FArray.PFill(beam, 0.0) FArray.PEGauss2D(beam, 1.0, [bx + tbx, by + tby], [bmaj, bmin, bpa]) # Add FArray.PShiftAdd(imArr, [int(xpix + 0.5) - 1, int(ypix + 0.5) - 1], beam, [int(bx + 0.5), int(by + 0.5)], flux, imArr) # end loop image.PutPlane(None, [ip, 1, 1, 1, 1], err) # rewrite # end plane loop # end MFImage Planes # History x = image y = peelMod hi = x.History(3, err) hi.Open(3, err) hi.TimeStamp('Restore Peel', err) if x.FileType == 'FITS': hiCard = y.FileName.strip() + '.' + str(y.Disk) else: hiCard = y.Aname.strip() + '.' + y.Aclass.strip() + '.' + str( y.Aseq) + '.' + str(y.Disk) hi.WriteRec(-1, "RestorePeel / file=" + hiCard, err) hi.Close(err)
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) # Create complex arrays for FFT size inCArray = CArray.CArray("inC", naxis=FFTdim) outCArray = CArray.CArray("outC", naxis=FFTdim)