def MakeMask(im, vlver, maskFile, err, minSNR=5.0): """ Create a CLEAN mask file for Obit Imaging tasks CLEANFile Radius of entries = major axis size. im = Image with VL table vlver = VL Table version, generate with FndSou maskFile = name for output mask file err = Obit error/message stack minSNR = Min. SNR to use """ scale = 1.0 # Open output file fd = open(maskFile, 'w') vltab = im.NewTable(Table.READONLY, 'AIPS VL', vlver, err) maxscale = scale / abs(im.Desc.Dict['cdelt'][0]) nrow = vltab.Desc.Dict['nrow'] vltab.Open(Table.READONLY, err) OErr.printErr(err) for irow in range(1, nrow + 1): row = vltab.ReadRow(irow, err) if row['PEAK INT'][0] / row['I RMS'][0] > minSNR: ra = ImageDesc.PRA2HMS(row['RA(2000)'][0]) dec = ImageDesc.PDec2DMS(row['DEC(2000)'][0]) size = min(50, int(row['MAJOR AX'][0] * maxscale + 0.5)) line = "%s %s %d\n" % (ra, dec, size) fd.write(line) vltab.Close(err) OErr.printErr(err) fd.close()
def PGal2J(Glong, Glat): """ Convert Galactic coordinates to Equatorial (J2000) Converts Galactic coordinates to Convert Equatorial (J2000) glong Galactic longitude as "D:M:S" glat Galactic latitude as "D:M:S Return [ra,dec] Equatorial (J) coordinates as "H M S", "D M S". """ ################################################################ glong = ImageDesc.PDMS2Dec(Glong) glat = ImageDesc.PDMS2Dec(Glat) (raB, decB) = PGal2Eq(glong, glat) # Galactic to equatorial B1950 (ra, dec) = PBtoJ(raB, decB) # to J2000 return [ImageDesc.PRA2HMS(ra), ImageDesc.PDec2DMS(dec)]
def SelectCC(im, inCC, outCC, radius, peelPos, err): """ Select/copy CCs more than radius from peelPos This generates a CC table which can be subtracted from the uv data and remove all sources but the peel source area. * im = Python Image with CC Tables * inCC = input CC version * outCC = output CC version * radius = radius (deg) of zone of exclusion * peelPos= [RA, Dec] in deg. * err = Python Obit Error/message stack """ ################################################################ # Checks if not Image.PIsA(im): raise TypeError("im MUST be a Python Obit Image") if not OErr.OErrIsA(err): raise TypeError("err MUST be an OErr") # # Geometry xref = im.Desc.Dict['crval'][0] yref = im.Desc.Dict['crval'][1] xrefpix = im.Desc.Dict['crpix'][0] yrefpix = im.Desc.Dict['crpix'][1] xinc = abs(im.Desc.Dict['cdelt'][0]) yinc = im.Desc.Dict['cdelt'][1] rot = im.Desc.Dict['crota'][1] imtype = im.Desc.Dict['ctype'][0][4:] # Input CC inTab = im.NewTable(Table.READONLY, "AIPS CC", inCC, err) if err.isErr: OErr.printErrMsg(err, "Error finding input CC Table") return # Output CC nrow = inTab.Desc.Dict['nrow'] noParms = inTab.Desc.List.Dict['NO_PARMS'][2][0] outTab = im.NewTable(Table.WRITEONLY, "AIPS CC", outCC, err, \ noParms = noParms) if err.isErr: OErr.printErrMsg(err, "Error creating output CC Table") return # Open inTab.Open(Table.READONLY, err) outTab.Open(Table.WRITEONLY, err) if err.isErr: OErr.printErrMsg(err, "Error opening CC Tables") return orow = 1 count = 0 sumf = 0.0 OErr.PLog(err, OErr.Info, "Excluding:") for irow in range(1, nrow + 1): row = inTab.ReadRow(irow, err) # Want this one? dx = row['DELTAX'][0] dy = row['DELTAY'][0] [ierr, xpos, ypos] = SkyGeom.PWorldPosLM(dx, dy, xref, yref, xinc, yinc, rot, imtype) # Small angle approximation dra = (xpos - peelPos[0]) * cos(radians(xpos)) delta = ((dra)**2 + (ypos - peelPos[1])**2)**0.5 if delta > radius: outTab.WriteRow(orow, row, err) orow += 1 else: #print irow,xpos,ypos count += 1 sumf += row['FLUX'][0] ras = ImageDesc.PRA2HMS(xpos) decs = ImageDesc.PDec2DMS(ypos) OErr.PLog(err, OErr.Info, "%6d %s %s flux= %f" % (irow, ras, decs, row['FLUX'][0])) # End loop OErr.PLog(err, OErr.Info, "Drop %6d CCs, sum flux= %f" % (count, sumf)) OErr.printErr(err) inTab.Close(err) outTab.Close(err) if err.isErr: OErr.printErrMsg(err, "Error copying CC Table") return
def Print(self, ImDesc, corner, file=None): """ Prepare human readable contents Returns string with description of model * self = object with Model to display * ImDesc = Image Descriptor with Beam, etc. * corner = bottom left corner in selected region of image (0-rel) """ ################################################################ # Start output string id = ImDesc.Dict modelInfo = "" # Collect info type = self.type parms = self.parms eparms = self.eparms # Gaussian if type == GaussMod: # Get celestial position xpix = corner[0] + self.DeltaX ypix = corner[1] + self.DeltaY pos=SkyGeom.PWorldPos (xpix, ypix, id["crval"][0], id["crval"][1], \ id["crpix"][0], id["crpix"][1], \ id["cdelt"][0], id["cdelt"][1], id["crota"][1], \ id["ctype"][0][4:8], 0.0, 0.0) rast = ImageDesc.PRA2HMS(pos[1]) decst = ImageDesc.PDec2DMS(pos[2]) # Position errors era = self.eDeltaX * abs(id["cdelt"][0]) * 3600.0 edec = self.eDeltaY * abs(id["cdelt"][1]) * 3600.0 modelInfo += "RA " + rast + " (%8.3g asec), pixel %8.3f (%8.3g)\n" % ( era, xpix, self.eDeltaX) modelInfo += "Dec " + decst + " (%8.3g asec), pixel %8.3f (%8.3g)\n" % ( edec, ypix, self.eDeltaY) modelInfo += "Peak Flux density %8.3g (%8.3g) %s\n" % ( self.Peak, self.ePeak, id["bunit"]) # Ratio of Gaussian beams if beam in ImDesc if (id["beamMaj"] > 0.0) and (id["beamMin"] > 0.0): ratio = (parms[0] * abs(id["cdelt"][0])*parms[1] * abs(id["cdelt"][1])) / \ (id["beamMaj"]*id["beamMin"]) modelInfo += "Integrated Flux density %8.3g (%8.3g) %s\n" % \ (self.Peak*ratio, self.ePeak*ratio, "Jy") modelInfo += "Fitted Major axis %8.3f (%8.3g) asec, %8.3f (%8.3g) pixels\n" % \ (parms[0]*abs(id["cdelt"][0])*3600.0, eparms[0]*abs(id["cdelt"][0])*3600.0, \ parms[0], eparms[1]) modelInfo += "Fitted Minor axis %8.3f (%8.3g) asec, %8.3f (%8.3g) pixels\n" % \ (parms[1]*abs(id["cdelt"][1])*3600.0, eparms[1]*abs(id["cdelt"][1])*3600.0, \ parms[1], eparms[1]) modelInfo += "Fitted Position angle %8.5g (%8.3g) deg\n" % \ (parms[2]*57.296, eparms[2]*57.296) if (id["beamMaj"] > 0.0) and (id["beamMin"] > 0.0): # Deconvolve deconMod = self.DeconGau(ImDesc) if PIsA(deconMod) and deconMod.type > 0: modelInfo += "\nDeconvolved model\n" dparms = deconMod.parms deparms = deconMod.eparms modelInfo += "Deconvolved Major axis %8.3g (%8.3g) asec, %8.3f (%8.3g) pixels\n" % \ (dparms[0]*abs(id["cdelt"][0])*3600.0, deparms[0]*abs(id["cdelt"][0])*3600.0, \ dparms[0], deparms[1]) modelInfo += "Deconvolved Minor axis %8.3g (%8.3g) asec, %8.3f (%8.3g) pixels\n" % \ (dparms[1]*abs(id["cdelt"][1])*3600.0, deparms[1]*abs(id["cdelt"][1])*3600.0, \ dparms[1], deparms[1]) modelInfo += "Deconvolved Position angle %8.5g (%8.3g) deg\n" % \ (dparms[2]*57.296, deparms[2]*57.296) else: modelInfo += "\nDeconvolution failed\n" # end deconvolved # end Gaussian # done return modelInfo
def PVLScale(inImage, inVL, outVL, scale, err, exclude=None): """ Scale the flux density values in a VL table Copies beam parameters and indexes when done. * inImage = Input image with VL tables * inVL = Input Obit VL Table * outVL = Output Obit VL Table, new data appended to end of old * scale = scale factor for flux densities * err = Python Obit Error/message stack * exclude = list of tuples with (ra, deg, size) all in deg describing regions not to rescale """ ################################################################ # Checks if not Table.PIsA(inVL): print("Actually ", inVL.__class__) raise TypeError("inVL MUST be a Python Obit Table") if not Table.PIsA(outVL): print("Actually ", outVL.__class__) raise TypeError("VLTable MUST be a Python Obit Table") fblank = Obit.FArrayGetBlank() # Blanked value inVL.Open(Table.READONLY, err) outVL.Open(Table.READWRITE, err) if err.isErr: OErr.printErrMsg(err, "Error Opening tables") # Copy beam info outVL.keys["BeamMajor"] = inVL.keys["BeamMajor"] outVL.keys["BeamMinor"] = inVL.keys["BeamMinor"] outVL.keys["BeamPA"] = inVL.keys["BeamPA"] #print "debug",outVL.keys nrow = inVL.Desc.Dict['nrow'] orow = -1 for irow in range(1, nrow + 1): row = inVL.ReadRow(irow, err) if err.isErr: break doScale = True # Need to scale? if exclude: for pos in exclude: (dra, ddec) = SkyGeom.PShiftXY(row["RA(2000)"][0], row["DEC(2000)"][0], 0.0, pos[0], pos[1]) if (abs(dra) <= pos[2]) and (abs(ddec) <= pos[2]): doScale = False print("exclude", irow, ImageDesc.PRA2HMS(row["RA(2000)"][0]), ImageDesc.PDec2DMS(row["DEC(2000)"][0]), \ row["PEAK INT"][0]) break if doScale: row["PEAK INT"][0] *= scale row["I RMS"][0] *= scale row["RES RMS"][0] *= scale row["RES PEAK"][0] *= scale row["RES FLUX"][0] *= scale # Have poln data? if (row["Q CENTER"][0] != fblank) and (row["U CENTER"][0] != fblank): row["Q CENTER"][0] *= scale row["U CENTER"][0] *= scale row["P Flux"][0] *= scale row["POL RMS"][0] *= scale # write outVL.WriteRow(orow, row, err) if err.isErr: break inVL.Close(err) outVL.Close(err) # History #outVL.Open(Table.READWRITE,err) inHistory = History.History("history", inImage.List, err) inHistory.Open(History.READWRITE, err) inHistory.TimeStamp("Start PVLScale", err) inHistory.WriteRec(-1, "PVLScale / scale = " + str(scale), err) if exclude: i = 0 for pos in exclude: i += 1 hi = "PVLScale exclude[%d] = (%9.5f,%9.5f,%8.6f) \ no Scale" % ( i, pos[0], pos[1], pos[2]) inHistory.WriteRec(-1, hi, err) inHistory.Close(err) #outVL.Close(err) # Index print("Index output") PVLIndex(outVL, err)