def getSkyMeanSDinAnnulus(ann,delta=5): iraf.noao() iraf.digiphot() iraf.apphot() iraf.photpars.setParam('apertures','1') iraf.phot.setParam('interactive','no') iraf.phot.setParam('image',fitsDir+fitsFile) iraf.phot.setParam('coords',fitsDir+fitsFile+".coo") outmag=".maglim" try: os.remove(fitsDir+fitsFile+outmag) except: print "File does not exist BEFORE running phot, so no need to delete." iraf.phot.setParam('output',fitsDir+fitsFile+outmag) iraf.phot.setParam('interac','no') iraf.fitskypars.setParam('annulus',str(ann)) iraf.fitskypars.setParam('dannulus',str(delta)) ## NO SIGMA CLIPPING! JUST TO BE SAFE: (6/2013) iraf.fitskypars.setParam('sloclip',"0") iraf.fitskypars.setParam('shiclip',"0") iraf.phot(fitsDir+fitsFile,Stdin=cr) aa, nn, xx, ss = ao.readPhotMagFile(fitsDir,fitsFile,outmag) try: os.remove(fitsDir+fitsFile+outmag) except: print "File not found to delete AFTER running phot; that's odd." return xx
def obsNotesForKOI(koi): #print settings[koi] if ((koi in koiDict["J"]) & (koi in koiDict["Ks"])): filtersUsed = "J and Ks" filterList=["J","Ks"] seeingText = str(round(longtext[koi,"J","seeing"],2))+"\" in J and "+str(round(longtext[koi,"Ks","seeing"],2))+"\" in Ks." fov = 1024.*eval(settings[koi]["Plate_scale_Ks"]) limitsLinkText = linkForFile(koi,"Ks","lim.tsv") + ", " + linkForFile(koi,"J","lim.tsv") ## imageLinkText = "PNG images: "+linkForFile(koi,"Ks",".png") + ", " + linkForFile(koi,"J",".png") + "\nFITS images: " + linkForFile(koi,"Ks",".fits") + ", " + linkForFile(koi,"J",".fits") imageLinkText = "\nFITS images: " + linkForFile(koi,"Ks",".fits") + ", " + linkForFile(koi,"J",".fits") elif (koi in koiDict["Ks"]): filtersUsed = "Ks" filterList=["Ks"] fov = 1024.*eval(settings[koi]["Plate_scale_Ks"]) seeingText = str(round(longtext[koi,"Ks","seeing"],2))+"\" in Ks." limitsLinkText = linkForFile(koi,"Ks","lim.tsv") ## imageLinkText = "PNG image: "+linkForFile(koi,"Ks",".png") + "\nFITS image: " + linkForFile(koi,"Ks",".fits") imageLinkText = "\nFITS image: " + linkForFile(koi,"Ks",".fits") else: # only J filtersUsed = "J" filterList=["J"] fov = 1024.*eval(settings[koi]["Plate_scale_J"]) seeingText = str(round(longtext[koi,"J","seeing"],2))+"\" in J." limitsLinkText = linkForFile(koi,"J","lim.tsv") ## imageLinkText = "PNG image: "+linkForFile(koi,"J",".png") + "\nFITS image: " + linkForFile(koi,"J",".fits") imageLinkText = "\nFITS image: " + linkForFile(koi,"J",".fits") ## Does this object have additional nearby stars on the image? for filt in filterList: apertures, starn, xySkyDict, starDict = ao.readPhotMagFile(ao.koiFilterDir(koi,filt), ao.finalKOIimageFile(koi,filt), magSuffix=".mag") closeComps = [] if (len(xySkyDict)>1): print "Found ",len(xySkyDict)," companions" ### Okay, how close are they? for nn in range(2,len(xySkyDict)+1): distPx = math.sqrt( (eval(xySkyDict[nn][0])-eval(xySkyDict[1][0]))**2 + (eval(xySkyDict[nn][1])-eval(xySkyDict[1][1]))**2 ) deltaMag = eval(starDict[nn,'5.00'][3])-eval(starDict[1,'5.00'][3]) distArcsec = eval(settings[koi]["Plate_scale_"+filt]) * distPx print koi, nn,distArcsec if distArcsec <= closeDist: closeComps.append([round(distArcsec,2),round(deltaMag,2)]) else: print koi," has no companions" ### Now figure out the text to output if closeComps == []: binaryText = "No companions were detected on the field of view." else: binaryText = str(len(closeComps))+" companion star(s) detected within "+str(closeDist)+"\" of the target: " if len(closeComps)>=1: for nn,comp in enumerate(closeComps): if (nn == len(closeComps)-1): post = ". " else: post = "; " #if comp[1] < closeDist: binaryText = binaryText + str(comp[1])+ " mag fainter in Ks at "+str(comp[0])+"\""+post else: binaryText = "No companions were detected within "+str(closeDist)+"\"." # print binaryText ## combine text = "ARIES AO observations for "+koi+" were taken on "+settings[koi]["Night"]+" in "+settings[koi]["Mode"]+" in "+filtersUsed+" (plate scale = "+settings[koi]["Plate_scale_Ks"]+"\" per pixel, FOV = "+str(round(fov,1))+"\"). The seeing was "+seeingText + " \n\n"+binaryText+"\n\nLimits on additional companions: "+limitsLinkText+"\n"+imageLinkText g = open(obsNotesBatchDir+koi+".txt",'w') print >>g, text
settingsDict=ao.readSettingsFile(settingsFile) #### Change if some other Speckle instrument besides Steve Howell's first one (i.e., if Gemini) if instrUsed == "Speckle": try: plateScale = eval(settingsDict['Plate_scale_Speckle']) except: print "\n\nWARNING! using hardcoded plate scale in magLimits.py\n\n" plateScale = 0.0228156 #### Should we ever have plate scales differ on different filters, this will need to change else: plateScale = eval(settingsDict['Plate_scale_Ks']) ### Read in .mag file apertures, numStars, xySkyDict, starDict = ao.readPhotMagFile(fitsDir,fitsFile,magSuffix=".mag") print "Read .mag file: numStars=",numStars," apertures: ",apertures #### How significant do we want our contours to be? nSigma=5 ### Set up ranges of arcsec; they have different spacing so we don't waste time on a fine grid away from the star #### We could set the inner angle based on the seeing, but it's easier to just get rid of the close ones later ### This is set up to mimic the way the code was run back in summer '12 legacyMode = False if legacyMode == True: plateScale = 0.02 ### you'll have a problem if it is actually 0.04 ### How wide are our annuli? deltaArcsec=0.1 # arcsec wide disks
def tableForEachStar(obj, distLimit): print "Output all stars within",distLimit,"arcsec to:",ao.starsFile(obj,instr=instrUsed) g = open(ao.starsFile(obj,instr=instrUsed),"w") print >>g, "\t".join(["object",obj]) for filt in filters: if obj in objectDict[filt]: ### Output fwhm for filter print >>g, "\t".join([ filt, "fwhm", str(round(fwhmDict[obj,filt],2)) ]) ### Does this object have additional nearby stars on the image? apertures, starn, xySkyDict, starDict = ao.readPhotMagFile(ao.koiFilterDir(obj,filt,instrUsed), ao.finalKOIimageFile(obj,filt,instrUsed), magSuffix=".mag") # print os.path.isfile(ao.koiFilterDir(obj,filt,instrUsed)+ao.finalKOIimageFile(obj,filt,instrUsed)+".mag") ### Make a koi class for use in undoing rotations k = koiPlusFilter.koiPlusFilter(obj,filt,instrUsed) refX = eval(xySkyDict[1][0]) refY = eval(xySkyDict[1][1]) refXerr = eval(xySkyDict[1][4]) refYerr = eval(xySkyDict[1][5]) if k.dir12 == "N": northDeltaX = k.arrowDeltaX12 northDeltaY = k.arrowDeltaY12 eastDeltaX = k.arrowDeltaX10 eastDeltaY = k.arrowDeltaY10 else: northDeltaX = k.arrowDeltaX10 northDeltaY = k.arrowDeltaY10 eastDeltaX = k.arrowDeltaX12 eastDeltaY = k.arrowDeltaY12 closeComps = [] print obj, " has ",len(xySkyDict)-1," comp stars (any distance) in",filt ### Note stars are 1, not 0, indexed for nn in range(1,len(xySkyDict)+1): #### Distance #### # distPx = math.sqrt( (eval(xySkyDict[nn][0])-eval(xySkyDict[1][0]))**2 + (eval(xySkyDict[nn][1])-eval(xySkyDict[1][1]))**2 ) thisX = eval(xySkyDict[nn][0]) thisY = eval(xySkyDict[nn][1]) thisXerr = eval(xySkyDict[nn][4]) thisYerr = eval(xySkyDict[nn][5]) # print thisX, thisXerr, thisY, thisYerr, obj, refXerr, refYerr deltaX = thisX - refX deltaY = thisY - refY deltaXerr = math.sqrt(thisXerr**2+refXerr**2) deltaYerr = math.sqrt(thisYerr**2+refYerr**2) ## in pixels if ((thisX == refX) & (thisY == refY)): distPx = math.sqrt( (thisX-refX)**2 + (thisY-refY)**2 ) distErrPx = 0 else: distPx, distErrPx = gb.distanceWithErrors(deltaX,deltaY,deltaXerr,deltaYerr) ## in arcsec distArcsec = eval(settings[obj]["Plate_scale_"+filt]) * distPx distArcsecErr = eval(settings[obj]["Plate_scale_"+filt]) * distErrPx ## Get position angles in degrees useDeltaX, useDeltaY = undoRotations(k.rotation, deltaX, deltaY) # print "\nDiag:",useDeltaX, useDeltaY, "unflipped from",deltaX,deltaY,k.rotation if ((thisX == refX) & (thisY == refY)): angle = 0 else: angle = getPA(useDeltaX, useDeltaY,northDeltaX,northDeltaY,eastDeltaX,eastDeltaY) # print "Diag PA:", useDeltaX, useDeltaY, northDeltaX, northDeltaY, eastDeltaX, eastDeltaY, angle #### Delta-magnitude #### try: deltaMag = eval(starDict[nn,'5.00'][3])-eval(starDict[1,'5.00'][3]) except: deltaMag = eval(starDict[nn,'1.00'][3])-eval(starDict[1,'1.00'][3]) print obj,"WARNING: aperture of 1 instead of 5 px; mag values unreliable. A PSF fit binary?\n" ### Now check if it is within our desired cutoff distance if distArcsec <= distLimit: closeComps.append([str(round(distArcsec,2)), str(round(deltaMag,2)), xySkyDict[nn][0], xySkyDict[nn][1], str(round(angle,1))]) #### We want to output the target star even if there are no others (for its pixel location and fwhm) ## print obj,closeComps,"\n\n" print >>g, "Star","Dist","Delta-mag","X_pixel","Y_pixel","PA" for nn,comp in enumerate(closeComps): listOut = gb.flattenList([[str(nn)], closeComps[nn]]) print >>g, gb.listToString(listOut,tab="\t") else: print "object wasn't found for this filter:",obj,filt g.close()