def computeLimits (raHex, decHex, raMid = -1000, raBoxSize=5., decBoxSize=5, mod_ra=0, mod_dec=0, allSky = False) : from equalArea import mcbryde verbose = False mod_alpha = 0 mod_beta = 0 if allSky : decMin = -89.9999; decMax = 89.9999 raMin = -179.9999; raMax = 179.9999 raBoxSize = 0.; decBoxSize = 0. mod_dec = 0; mod_ra = 0 else : # autoscaling decMin = decHex.min(); decMax = decHex.max() raMin = raHex.min(); raMax = raHex.max() decMin = decMin-decBoxSize+mod_dec decMax = decMax+decBoxSize+mod_dec decMid = decMin+(decMax-decMin)/2. beta=-1*(decMid+mod_beta) boxRa = raBoxSize/np.cos(decMid*2*np.pi/360.) raMin = raMin-boxRa+mod_ra raMax = raMax+boxRa+mod_ra if raMid == -1000 : raMid = raMin+(raMax-raMin)/2. alpha= -1*(raMid+mod_alpha) print "\t raMin, raMax, decMin, decMax:", raMin, raMax, decMin, decMax #raise Exception if allSky : #x,y = mcbryde.mcbryde(np.array([-179.999,179.999]), np.array([-60,60]), alpha=alpha, beta=beta) #decMin = -60; decMax = 60.0 x,y = mcbryde.mcbryde(np.array([raMin,raMax]), np.array([-1,1]), alpha=alpha, beta=beta) xmin = x.min(); xmax = x.max() x,y = mcbryde.mcbryde(np.array([-1,1]), np.array([decMin,decMax]), alpha=alpha, beta=beta) ymin = y.min(); ymax = y.max() xbox = 0.01*(xmax-xmin) ybox = 0.01*(ymax-ymin) else : # autoscaling #x,y = mcbryde.mcbryde(raHex, decHex, alpha=alpha, beta=beta) x,y = mcbryde.mcbryde(np.array([raMin,raMax]), np.array([1,1]), alpha=alpha, beta=beta) xmin = x.min(); xmax = x.max() x,y = mcbryde.mcbryde(np.array([-1,1]), np.array([decMin,decMax]), alpha=alpha, beta=beta) ymin = y.min(); ymax = y.max() xbox = 0.1*(xmax-xmin) ybox = 0.1*(ymax-ymin) xmin = xmin-xbox; xmax = xmax+xbox ymin = ymin-ybox; ymax= ymax+ybox if verbose: print "ra box, dec box",raMin, raMax, decMin, decMax print "x box, y box", xmin, xmax, ymin, ymax print "alpha, beta",alpha, beta #raw_input("wait for human to press") return raMin, raMax, decMin, decMax, xmin, xmax, ymin, ymax, alpha, beta
def equalAreaPlot(figure,slot,simNumber,data_dir,mapDir, title="") : import matplotlib.pyplot as plt from equalArea import mcplot from equalArea import mcbryde import insideDesFootprint ra, dec, ligo, maglim, prob, ha, x,y, hx,hy = \ readMaps(mapDir, simNumber, slot) # x,y are the mcbryde projection of ra, dec # hx,hy are the mcbryde projection of ha, dec ra, dec = x, y # des footprint # plots the DES footprint on the maps desra, desdec = insideDesFootprint.getFootprintRaDec() desx, desy = mcbryde.mcbryde(desra, desdec) plt.axes().set_aspect('equal') name = os.path.join(data_dir,str(simNumber)+"-"+str(slot)+"-ligo-eq.png") print "making ",name, plt.clf();mcplot.plot(ra,dec,ligo) plt.plot(desx,desy,color="w") plt.xlabel("RA");plt.ylabel("Dec") plt.title(title) plt.savefig(name) name = os.path.join(data_dir,str(simNumber)+"-"+str(slot)+"-maglim-eq.png") print name, plt.clf();mcplot.plot(ra,dec,maglim,vmin=17); plt.plot(desx,desy,color="w") plt.xlabel("RA");plt.ylabel("Dec") plt.title(title) plt.savefig(name) name = os.path.join(data_dir,str(simNumber)+"-"+str(slot)+"-prob-eq.png") print name, plt.clf();mcplot.plot(ra,dec,prob) plt.plot(desx,desy,color="w") plt.xlabel("RA");plt.ylabel("Dec") plt.title(title) plt.savefig(name) name = os.path.join(data_dir,str(simNumber)+"-"+str(slot)+"-probXligo-eq.png") print name plt.clf();mcplot.plot(ra,dec,prob*ligo) plt.plot(desx,desy,color="w") plt.xlabel("RA");plt.ylabel("Dec") plt.title(title) plt.savefig(name) # return the number of plots made return 4
def graticule (alpha, beta, xmin, xmax, ymin, ymax, raGratRa1=-179.99, raGratRa2=180+30, raGratDelRa=30., raGratDec1=-89.99, raGratDec2=91, raGratDelDec= 0.1 , decGratRa1=-179.99, decGratRa2=180+30, decGratDelRa=0.1, decGratDec1=-89.99, decGratDec2=91, decGratDelDec=10, redRa = 90., redRaDec1=-90, redRaDec2=-80, redRaDelDec = 0.1) : import matplotlib.pyplot as plt from equalArea import mcbryde for i in np.arange( raGratRa1, raGratRa2, raGratDelRa ) : raLine, decLine = np.array([]), np.array([]) for j in np.arange( raGratDec1, raGratDec2, raGratDelDec ) : raLine = np.append(raLine, i) decLine = np.append(decLine, j) xLine,yLine = mcbryde.mcbryde(raLine, decLine, alpha=alpha, beta=beta) ixg = (xLine > xmin) & (xLine < xmax) & (yLine > ymin) & (yLine < ymax) plt.plot(xLine[ixg],yLine[ixg],c="k",alpha=0.5, linewidth=0.5) doRedLine = True doRedLine = False if doRedLine : i = redRa raLine, decLine = np.array([]), np.array([]) for j in np.arange( redRaDec1, redRaDec2, redRaDelDec ) : raLine = np.append(raLine, i) decLine = np.append(decLine, j) xLine,yLine = mcbryde.mcbryde(raLine, decLine, alpha=alpha, beta=beta) ixg, = np.where((xLine > xmin) & (xLine < xmax) & (yLine > ymin) & (yLine < ymax)) if ixg.size > 0: plt.plot(xLine[ixg],yLine[ixg],c="r",alpha=1.0, linewidth=0.5) for i in np.arange( decGratDec1, decGratDec2, decGratDelDec ) : raLine, decLine = np.array([]), np.array([]) for j in np.arange( decGratRa1, decGratRa2, decGratDelRa ) : raLine = np.append(raLine, j) decLine = np.append(decLine, i) xLine,yLine = mcbryde.mcbryde(raLine, decLine, alpha=alpha, beta=beta, isLine=True) ixg, = np.where((xLine > xmin) & (xLine < xmax) & (yLine > ymin) & (yLine < ymax)) if ixg.size > 0: plt.plot(xLine[ixg],yLine[ixg],c="k",alpha=0.5, linewidth=0.5)
def plotDesFootprint(alpha, beta, xmin, xmax, ymin, ymax, ax) : import matplotlib.pyplot as plt import matplotlib.path import matplotlib.patches from equalArea import mcbryde desRa, desDec = getDesFootprint() x,y = mcbryde.mcbryde(desRa, desDec, alpha=alpha, beta=beta) ix = (x > xmin) & (x < xmax) & (y > ymin) & (y < ymax) #plt.plot(x[ix],y[ix],c="k",alpha=0.5) footprint = matplotlib.path.Path(zip(x,y)) patch = matplotlib.patches.PathPatch(footprint, facecolor='gold', lw=1, alpha=0.066, fill=True) ax.add_patch(patch) patch = matplotlib.patches.PathPatch(footprint, edgecolor='gold', lw=1, alpha=1, fill=False) #patch = matplotlib.patches.PathPatch(footprint, edgecolor='gold', lw=1, alpha=0.33, fill=False) ax.add_patch(patch)
def limitMag(self, filter, exposure=30): #print "\t limiting magnitude" mjd = self.mjd zd = self.zd sun_zd = self.sunZD moon_zd = self.moonZD moon_phase = self.moonPhase moon_sep = self.moonSep airmass = self.airmass ebv = self.ebv alpha = self.mcbryde_alpha sunIsUp = self.sunBrightnessModel(sun_zd) if sunIsUp: m = np.copy(ebv) * 0.1 + -10.0 mglobal = np.copy(ebv) * 0.1 + -10.0 print "\t ... the sun is up" else: dust = self.dustTransmission(filter, ebv) atmo = self.atmosphereTransmission(zd, airmass, filter, moon_sep) seeing = self.seeing(airmass, filter, seeingAtZenith=0.9) sky = self.skyBrightness(zd, moon_zd, moon_sep, moon_phase, filter) skyFid = self.skyBrightnessFid(filter) telescope = self.telescopeLimits(self.ha, self.dec) self.limits = telescope if filter == "g": m_zp = 23.3 elif filter == "r": m_zp = 23.4 elif filter == "i": m_zp = 22.9 elif filter == "z": m_zp = 22.5 elif filter == "y": m_zp = 20.6 else: raise Exception("no such filter") SN = telescope * dust * atmo * (1. / seeing) * np.sqrt( exposure / 30.) ix = np.nonzero(SN <= 0) SN[ix] = 1.0e-12 m = m_zp + 2.5 * np.log10(SN) + 0.5 * (sky - skyFid) # arbitarily limit limiting mag to that of moon ix = np.nonzero(m < 0) m[ix] = 0 ix, = np.where(telescope == 0) m[ix] = -11.0 SNglobal = dust * atmo * (1. / seeing) * np.sqrt(exposure / 30.) ix = np.nonzero(SNglobal <= 0) SNglobal[ix] = 1.0e-12 mglobal = m_zp + 2.5 * np.log10(SNglobal) + 0.5 * (sky - skyFid) # arbitarily limit limiting mag to that of moon ix = np.nonzero(mglobal < 0) mglobal[ix] = 0 # project into equal area map x, y = mcbryde.mcbryde(self.ra / self.degToRad, self.dec / self.degToRad, alpha=alpha) self.x = x self.y = y hx, hy = mcbryde.mcbryde(self.ha / self.degToRad, self.dec / self.degToRad, alpha=alpha) self.hx = hx self.hy = hy self.maglim = m self.maglimall = mglobal
def plotDecamHexen(ax, ra,dec,alpha, camera, beta=0, color="r", lw=1, plateCaree=False, allSky=False) : if camera == 'decam': import decam2hp import matplotlib.patches import matplotlib.path from equalArea import mcbryde import matplotlib.pyplot as plt nHex = ra.size for i in range(0,nHex) : hexRa,hexDec = decam2hp.cameraOutline(ra[i], dec[i], camera) hexX,hexY = mcbryde.mcbryde(hexRa,hexDec, alpha=alpha, beta=beta, ) if plateCaree: hexX,hexY = hexRa, hexDec if not allSky : hex_path = matplotlib.path.Path(zip(hexX,hexY)) hex_patch = matplotlib.patches.PathPatch(hex_path, edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) else : # long section dealing with hexes that get split across the singularity # and cause lines from one side of map to another # split them into separate entities # ugly, but it seems to work. ix_pos = np.nonzero(hexRa>180)[0] ix_neg = np.nonzero(hexRa<-180)[0] ix, = np.where(np.nonzero((hexRa>=-180)&(hexRa<=180))[0]) if ix.size > 0 : hex_path = matplotlib.path.Path(zip(hexX[ix],hexY[ix])) hex_patch = matplotlib.patches.PathPatch(hex_path, edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) if ix_pos.size > 0: hex_path = matplotlib.path.Path(zip(hexX[ix_pos],hexY[ix_pos])) hex_patch = matplotlib.patches.PathPatch(hex_path, edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) if ix_neg.size > 0: hex_path = matplotlib.path.Path(zip(hexX[ix_neg],hexY[ix_neg])) hex_patch = matplotlib.patches.PathPatch(hex_path, edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) #x,y=mcbryde.mcbryde(tra[i],tdec[i], alpha=alpha, beta=beta) #plt.text(x,y,"{}".format(i), ha="center", va="center", color="w") if camera == 'hsc': import decam2hp import matplotlib.patches import matplotlib.path from equalArea import mcbryde import matplotlib.pyplot as plt nHex = ra.size radius = 1.5 / 2 for i in range(0,nHex) : hexRa,hexDec = decam2hp.cameraOutline(ra[i], dec[i], camera) hexX,hexY = mcbryde.mcbryde(hexRa,hexDec, alpha=alpha, beta=beta, ) ix_pos = np.nonzero(hexRa>180)[0] ix_neg = np.nonzero(hexRa<-180)[0] ix, = np.where(np.nonzero((hexRa>=-180)&(hexRa<=180))[0]) if ix.size > 0 : hex_path = matplotlib.path.Path(zip(hexX[ix],hexY[ix])) hex_patch = matplotlib.patches.PathPatch(hex_path, facecolor='none', edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) if ix_pos.size > 0: hex_path = matplotlib.path.Path(zip(hexX[ix],hexY[ix])) hex_patch = matplotlib.patches.PathPatch(hex_path, facecolor='none', edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) if ix_neg.size > 0: hex_path = matplotlib.path.Path(zip(hexX[ix],hexY[ix])) hex_patch = matplotlib.patches.PathPatch(hex_path, facecolor='none', edgecolor=color, lw=lw, fill=False) ax.add_patch(hex_patch) return ax
def coreMapAndHex(figure, hexRa, hexDec, raMap, decMap, camera, map, low_limit, high_limit, ligoMap, origLigoMap, doLigoMap=True, doOrigLigoMap=False, resolution=512, image=False, scale=1., badData=False, badDataVal=-11.0, redRa = 90., title="", raMid=-1000, raBoxSize=5., decBoxSize=5., mod_ra = 0, mod_dec=0., doHexes = True, gradRedHiDec = -80, raGratDelRa=30., decGratDelDec=10. , colorbar=True, contourLabels=True , slots=np.zeros(0), thisSlot=0, allSky = False) : from equalArea import mcbryde import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import insideDesFootprint import matplotlib from scipy.ndimage.filters import gaussian_filter cmap = "cubehelix_r" cmap = "YlGnBu" cmap = matplotlib.cm.get_cmap("YlGnBu") cmap.set_under("w") cmap.set_bad("0.30") ;# a dark gray # compute the image limits and midpoints (alpha, beta) raMin, raMax, decMin, decMax, xmin, xmax, ymin, ymax, alpha, beta = \ computeLimits (hexRa, hexDec, raMid=raMid, raBoxSize=raBoxSize, decBoxSize=decBoxSize, mod_ra=mod_ra, mod_dec = mod_dec, allSky = allSky) #j,j,s_hexRa, s_hexDec = lmcHexes() #raMin, raMax, decMin, decMax, xmin, xmax, ymin, ymax, alpha, beta = \ # computeLimits (s_hexRa,s_hexDec, raMid=raMid, raBoxSize=raBoxSize, # decBoxSize=decBoxSize, mod_ra=mod_ra, mod_dec = mod_dec) # project into mcbryde xMap,yMap = mcbryde.mcbryde(raMap, decMap, alpha=alpha, beta=beta) x,y = mcbryde.mcbryde(hexRa, hexDec, alpha=alpha, beta=beta) if xmin==xmax and ymin==ymax: ix = np.ones(xMap.size).astype(bool) xmin=xMap.min(); xmax=xMap.max() ymin=yMap.min(); ymax=yMap.max() doHexes=False else : ix=np.nonzero((xMap > xmin) & (xMap <= xmax) & (yMap > ymin) & (yMap <= ymax) ) # plot the image, either as an image or as a hexbin plt.clf() if image : data = makeImage (xMap[ix], yMap[ix], map[ix], xmin, xmax, ymin, ymax, scale, badData=badData, badDataVal=badDataVal) # hack to make this 5 sigma, not 10 sigma limitin mag print "\t\t 10sigma -> 5 sigma hack", data = data +0.75257 low_limit = low_limit+ 0.75257 high_limit = high_limit+ 0.75257 plt.imshow(data, cmap=cmap, vmin=low_limit, vmax=high_limit, extent=[xmin, xmax, ymin, ymax]) else : gridsize = 150 gridsize = 66 plt.hexbin(xMap[ix],yMap[ix],map[ix],vmin=low_limit, vmax=high_limit, gridsize=gridsize, cmap=cmap) # put on a graticule graticule (alpha, beta, xmin, xmax, ymin, ymax, redRa = redRa, redRaDec2 = gradRedHiDec, raGratDelRa= raGratDelRa, decGratDelDec= decGratDelDec) # fig 1 ax = figure.add_subplot(1,1,1) #Plot Dec Footprint in the observing plots plotDesFootprint(alpha, beta, xmin, xmax, ymin, ymax, ax) if colorbar and not allSky: cb = plt.colorbar(shrink=0.5,pad=0.03); cb.set_label("5$\sigma$ point source limiting magnitude") # put on the ligo contours gaussSigma = 7. gaussSigma = 3. if doLigoMap : cl_ligoMap = confidenceLevels(ligoMap) if gaussSigma > 0 : cl_ligoMap = gaussian_filter(cl_ligoMap, gaussSigma) plotLigoContours(xMap[ix],yMap[ix], cl_ligoMap[ix], color="w", lw=1.2, labels=contourLabels) if doOrigLigoMap : cl_origLigoMap = confidenceLevels(origLigoMap) if gaussSigma > 0 : cl_origLigoMap = gaussian_filter(cl_origLigoMap, gaussSigma) plotLigoContours(xMap[ix],yMap[ix], cl_origLigoMap[ix], color="cyan", alpha=1.0, lw=1.3, ls="dashed",labels=contourLabels) #plotLigoContours(xMap[ix],yMap[ix], cl_origLigoMap[ix], color="cyan", alpha=1.0, lw=1.3, #labels=contourLabels) # put on the hexes if doHexes : linewidth=0.5 linewidth=1.0 #ax = figure.add_subplot(1,1,1) # this is needed for search fig 1 ax=plotDecamHexen(ax, hexRa, hexDec, alpha, camera, beta, color="r", lw=linewidth, allSky=allSky) #ix =np.invert( insideDesFootprint.insideFootprint(hexRa, hexDec)) #ax=plotDecamHexen(ax, hexRa[ix],hexDec[ix],alpha, beta, color="orange", lw=linewidth, allSky=allSky) if slots.size > 0 : # plot the already observed hexes as maroon ix = slots<thisSlot ax=plotDecamHexen(ax, hexRa[ix],hexDec[ix],alpha, camera, beta, color="maroon", lw=linewidth, allSky=allSky) # plot the current slots hexes as yellow ix = slots==thisSlot ax=plotDecamHexen(ax, hexRa[ix],hexDec[ix],alpha, camera, beta, color="yellow", lw=linewidth, allSky=allSky) # fig1 and fig2, lmc paper, #plotLmcHexes(alpha,beta,ax) # and not the fig1 marcelle paper, which is change lmcHexes2 to lmcHexes # deal with titles, axes, etc plt.title(title) plt.xlim(xmin, xmax) plt.ylim(ymin, ymax) plt.axes().set_aspect('equal'); #plt.axes().set_frame_on(False); plt.axes().set_xticks([]); plt.axes().set_yticks([]) plt.show() return alpha, beta