def PJ2Gal(RA, Dec): """ Convert Equatorial (J2000) to Galactic coordinates Converts Convert Equatorial (J2000)to Galactic coordinates RALong Right Ascension/longitude as "H:M:S" DecLat Declination/latitude as "D:M:S Return [GLong, GLat] Galactic coordinates as "D M S". """ ################################################################ ra = ImageDesc.PHMS2RA(RA) dec = ImageDesc.PDMS2Dec(Dec) (raB, decB) = PJtoB(ra, dec) # to B1950 (glong, glat) = PEq2Gal(raB, decB) # to Galactic return [ImageDesc.PDec2DMS(glong), ImageDesc.PDec2DMS(glat)]
def PJ20002Gal(RA2000, Dec2000): """ Convert Equatorial (J2000) to Galactic coordinates strings Converts Convert Equatorial (B1950)to Galactic coordinates RA2000 J2000 Right Ascension as "hh:mm:ss.s" Dec2000 J2000 Declination as 'dd:mm:ss.s' Return [glong, glat] Galactic coordinates as 'dd mm ss.s' """ ################################################################ raj = ImageDesc.PHMS2RA(RA2000) decj = ImageDesc.PDMS2Dec(Dec2000) [rab, decb] = PJtoB(raj, decj) [glong, glat] = PEq2Gal(rab, decb) return [ImageDesc.PDec2DMS(glong), ImageDesc.PDec2DMS(glat)]
def NVSSPtFlux(RA, Dec, equinox, err, stokes='I',dir="/home/ftp/nvss/MAPS"): """ Determine the NVSS Flux density Returns flux density, None on failure RA = Right ascension as string ("HH MM SS.SS") Dec = Declonation as string ("sDD MM SS.SS") equinox = equinox of RA,Dec, 1950 or 2000 err = Python Obit Error/message stack stokes = Stokes desired, 'I', 'Q' or 'U' dir = directory or url of directory """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" if err.isErr: # existing error? return None # file = NVSSFindFile(RA, Dec, equinox, err, stokes=stokes) if err.isErr: OErr.printErr(err) return None path = dir+"/"+file #print "Image ",path img = Image.newPFImage("Image", path, 0, True, err, verbose=False) if err.isErr: OErr.printErr(err) return None interp = ImageInterp.PCreate("Interpolator", img, err) if err.isErr: OErr.printErr(err) return None ra = ImageDesc.PHMS2RA(RA, sep=' ') dec = ImageDesc.PDMS2Dec(Dec, sep=' ') # Precess 1950 to 2000? if equinox==1950: (ra,dec) = SkyGeom.PBtoJ(ra,dec) # Plane plane = 1 if stokes=='Q': plane = 2 if stokes=='U': plane = 3 # Interpolate value = interp.Value(ra, dec, err, plane=plane) if err.isErr: OErr.printErr(err) return None return value;
# Image info nterm = icube.Desc.List.Dict['NTERM'][2][0] nspec = icube.Desc.List.Dict['NSPEC'][2][0] freqs = [] for i in range(1, nspec + 1): key = 'FREQ%4.4d' % i freqs.append(1.0e-9 * icube.Desc.List.Dict[key][2][0]) # GHz # end loop # Interpolator fi = FInterpolate.FInterpolate('FI', icube.FArray, icube.Desc, 2) # Get pixel locations pixels = [] vals = [] for s in srcpos: pos = [ImageDesc.PHMS2RA(s[1]), ImageDesc.PDMS2Dec(s[2])] pixel = ImageDesc.PGetPixel(icube.Desc, pos, err) pixels.append(pixel) vals.append(nspec * [fblank]) # end loop OErr.printErrMsg(err, message='Finding positions') # Loop over planes interpolating values rms = [] for i in range(0, nspec): # Read plane plane = [i + nterm + 1, 1, 1, 1, 1] Image.PGetPlane(icube, None, plane, err) rms.append(icube.FArray.RMS) # Plane RMS # Interpolate positions for j in range(0, len(pixels)):
def NVSSFindFile(RA, Dec, equinox, err, stokes='I'): """ Determine the NVSS image best suited for a given position Returns name of image RA = Right ascension as string ("HH MM SS.SS") Dec = Declonation as string ("sDD MM SS.SS") equinox = equinox of RA,Dec, 1950 or 2000 err = Python Obit Error/message stack stokes = Stokes desired, 'I', 'Q' or 'U' """ ################################################################ # Checks if not OErr.OErrIsA(err): raise TypeError,"err MUST be an OErr" if err.isErr: # existing error? return if not type(RA)==str: raise TypeError,"RA must be a string (HH MM SS.S)" if not type(Dec)==str: raise TypeError,"Dec must be a string (HH MM SS.S)" # ra = ImageDesc.PHMS2RA(RA, sep=' ') dec = ImageDesc.PDMS2Dec(Dec, sep=' ') # Precess 1950 to 2000? if equinox==1950: (ra,dec) = SkyGeom.PBtoJ(ra,dec) # Must be north of -41 dec if dec<-41.: OErr.PLog(err, OErr.Error, "Dec MUST be > -41") return "No Image" # Maximum distance to "belong" tolDec = 2.0 idec = -1 adec = abs(dec) for i in range(0,23): if abs(adec-NVSSnumMap[i][0])<=tolDec: dd = int(NVSSnumMap[i][0]+0.01) idec = i break; # Find it? if idec<0: OErr.PLog(err, OErr.Error, "Failed on declination "+Dec) return "No Image" # Width of images in RA deltRa = 360.0 / NVSSnumMap[idec][1] racell = int(0.5 + ra/deltRa) # Cell if racell>=NVSSnumMap[idec][1]: # Wrap? racell = 0 # Derive name raCen = racell*deltRa / 15.0 iRAH = int(raCen + 0.5) iRAM = int(60.0 * (raCen-iRAH) + 0.1) if iRAM<0.0: iRAH -= 1 iRAM += 59 if iRAH == -1: iRAH = 23 # Sign of declination if dec>=-2.0: dsign = 'P' else: dsign = 'M' # Stokes type if stokes in ["Q","U"]: itype = 'C' else: itype = 'I' # put it together file = "%s%2.2i%2.2i%s%2.2i"%(itype,iRAH,iRAM,dsign,dd) return file