def contour(post, ax, levels=[0.1, 0.5, 0.9], alpha=1.0, colors='b', linewidths=1): ''' generate mollweide projection of contours with requested annotations ''' cpost = np.empty(post.shape) indecies = np.argsort(post)[::-1] cpost[indecies] = np.cumsum(post[indecies]) plt.sca(ax) lalinf_plot.healpix_contour(cpost, levels=levels, alpha=alpha, colors=colors, linewidths=linewidths)
# Plot sky map. vmax = probperdeg2.max() plot.healpix_heatmap( probperdeg2, dlon=dlon, nest=metadata['nest'], vmin=0., vmax=vmax) # Add colorbar. if opts.colorbar: cb = plot.colorbar() cb.set_label(r'prob. per deg$^2$') # Add contours. if opts.contour: cls = 100 * postprocess.find_greedy_credible_levels(skymap) cs = plot.healpix_contour( cls, dlon=dlon, nest=metadata['nest'], colors='k', linewidths=0.5, levels=opts.contour) fmt = r'%g\%%' if rcParams['text.usetex'] else '%g%%' plt.clabel(cs, fmt=fmt, fontsize=6, inline=True) # Add continents. if opts.geo: geojson_filename = os.path.join(os.path.dirname(plot.__file__), 'ne_simplified_coastline.json') with open(geojson_filename, 'r') as geojson_file: geojson = json.load(geojson_file) for shape in geojson['geometries']: verts = np.deg2rad(shape['coordinates']) plt.plot(verts[:, 0], verts[:, 1], color='0.5', linewidth=0.5) radecs = np.deg2rad(opts.radec)
vmin=0., vmax=vmax, cmap=plt.get_cmap(opts.colormap)) if opts.colorbar: # Plot colorbar. cb = plot.colorbar() # Set colorbar label. cb.set_label(r'prob. per deg$^2$') # Add contours. if opts.contour: indices = np.argsort(-skymap) region = np.empty(skymap.shape) region[indices] = 100 * np.cumsum(skymap[indices]) cs = plot.healpix_contour( region, dlon=dlon, nest=metadata['nest'], colors='k', linewidths=0.5, levels=opts.contour) fmt = r'%g\%%' if rcParams['text.usetex'] else '%g%%' plt.clabel(cs, fmt=fmt, fontsize=6, inline=True) if opts.geo: geojson_filename = os.path.join(os.path.dirname(plot.__file__), 'ne_simplified_coastline.json') with open(geojson_filename, 'r') as geojson_file: geojson = json.load(geojson_file) for shape in geojson['geometries']: verts = np.deg2rad(shape['coordinates']) plt.plot(verts[:, 0], verts[:, 1], color='0.5', linewidth=0.5) # Add markers (e.g., for injections or external triggers). for ra, dec in np.deg2rad(opts.radec):
if opts.colormap is None: colors = ['k'] * len(opts.fitsfilenames) else: colors = matplotlib.cm.get_cmap(opts.colormap) colors = colors(np.linspace(0, 1, len(opts.fitsfilenames))) for count_records, (color, fitsfilename) in enumerate(zip(colors, opts.fitsfilenames)): progress.update(count_records, fitsfilename) skymap, metadata = fits.read_sky_map(fitsfilename, nest=None) nside = hp.npix2nside(len(skymap)) gmst = lal.GreenwichMeanSiderealTime(metadata['gps_time']) % (2 * np.pi) indices = np.argsort(-skymap) region = np.empty(skymap.shape) region[indices] = 100 * np.cumsum(skymap[indices]) plot.healpix_contour(region, nest=metadata['nest'], dlon=-gmst, colors=[color], linewidths=0.5, levels=[opts.contour], alpha=opts.alpha) progress.update(-1, 'saving figure') # Add a white outline to all text to make it stand out from the background. plot.outline_text(ax) opts.output()
def mollweideScaffold( post, post_masked, mask=None, projection="astro mollweide", contours=False, color_map='OrRd', contour_color='grey', LatLon=None): """ a standardized plotting routine for the mollweide projections needed in simPlot.py each mask supplied via *masks is overlayed on the masked plot LatLon will be marked with a red dot iff projection=="mollweide" (assumed EarthFixed coords) """ ### set up figure and axis objects figwidth = 10 figheight = 10 fig = plt.figure(figsize=(figwidth,figheight)) ax1 = plt.subplot(2,1,1, projection=projection) ax2 = plt.subplot(2,1,2, projection=projection) ### establish color map cmap = plt.get_cmap(color_map) ### establish range for color map vmin = min(np.min(post), np.min(post_masked)) vmax = max(np.max(post), np.max(post_masked)) ### plot heatmaps plt.sca( ax1 ) lalinf_plot.healpix_heatmap( post, cmap=cmap, vmin=vmin, vmax=vmax, nest=False ) plt.sca( ax2 ) lalinf_plot.healpix_heatmap( post_masked, cmap=cmap, vmin=vmin, vmax=vmax, nest=False ) if mask!=None: ### plot the mask as a shaded region mask = np.ma.masked_where(mask==1, mask) lalinf_plot.healpix_heatmap( mask, cmap=plt.get_cmap('Greys_r'), vmin=0, vmax=1, nest=False, alpha=0.1 ) if projection=="mollweide": ### add continents geojson_filename = os.path.join(os.path.dirname(lalinf_plot.__file__), 'ne_simplified_coastline.json') with open(geojson_filename, 'r') as geojson_file: geojson = json.load(geojson_file) for shape in geojson['geometries']: verts = np.deg2rad(shape['coordinates']) color='k' ax1.plot(verts[:, 0], verts[:, 1], color=color, linewidth=0.5) ax2.plot(verts[:, 0], verts[:, 1], color=color, linewidth=0.5) ### plot contours if contours: if np.sum(post): cpost = np.empty(post.shape) indecies = np.argsort(post)[::-1] cpost[indecies] = np.cumsum(post[indecies]) plt.sca( ax1 ) lalinf_plot.healpix_contour( cpost, alpha=0.25, levels=[0.1, 0.5, 0.9], colors=contour_color ) if np.sum(post_masked): cpost = np.empty(post_masked.shape) indecies = np.argsort(post_masked)[::-1] cpost[indecies] = np.cumsum(post_masked[indecies]) plt.sca( ax2 ) lalinf_plot.healpix_contour( cpost, alpha=0.25, levels=[0.1, 0.5, 0.9], colors=contour_color ) ### set titles ax1.set_title('posterior') ax2.set_title('masked posterior') ### decoration for ax in [ax1, ax2]: if LatLon!=None: lat, lon = LatLon ax.plot( lon, lat, marker='o', markeredgecolor='r', markerfacecolor='r', markersize=3, linestyle='none') ax.patch.set_alpha(0.) ax.set_alpha(0.) ### return fig and ax handles return fig, [ax1, ax2]
# Convert sky map from probability to probability per square degree. probperdeg2 = skymap / hp.nside2pixarea(nside, degrees=True) # Plot sky map. vmax = probperdeg2.max() plot.healpix_heatmap(probperdeg2, dlon=dlon, nest=metadata["nest"], vmin=0.0, vmax=vmax) # Add colorbar. if opts.colorbar: cb = plot.colorbar() cb.set_label(r"prob. per deg$^2$") # Add contours. if opts.contour: cls = 100 * postprocess.find_greedy_credible_levels(skymap) cs = plot.healpix_contour(cls, dlon=dlon, nest=metadata["nest"], colors="k", linewidths=0.5, levels=opts.contour) fmt = r"%g\%%" if rcParams["text.usetex"] else "%g%%" plt.clabel(cs, fmt=fmt, fontsize=6, inline=True) # Add continents. if opts.geo: geojson_filename = os.path.join(os.path.dirname(plot.__file__), "ne_simplified_coastline.json") with open(geojson_filename, "r") as geojson_file: geojson = json.load(geojson_file) for shape in geojson["geometries"]: verts = np.deg2rad(shape["coordinates"]) plt.plot(verts[:, 0], verts[:, 1], color="0.5", linewidth=0.5) radecs = np.deg2rad(opts.radec) if opts.inj_database: query = """SELECT longitude, latitude FROM sim_inspiral AS si
progress.max = len(fitsfilenames) matplotlib.rc('path', simplify=True, simplify_threshold=1) for count_records, fitsfilename in enumerate(fitsfilenames): progress.update(count_records, fitsfilename) skymap, metadata = fits.read_sky_map(fitsfilename, nest=None) nside = hp.npix2nside(len(skymap)) gmst = lal.GreenwichMeanSiderealTime(metadata['gps_time']) % (2*np.pi) indices = np.argsort(-skymap) region = np.empty(skymap.shape) region[indices] = 100 * np.cumsum(skymap[indices]) plot.healpix_contour( region, nest=metadata['nest'], dlon=-gmst, colors='k', linewidths=0.5, levels=[opts.contour], alpha=opts.alpha) progress.update(-1, 'saving figure') # If we are using a new enough version of matplotlib, then # add a white outline to all text to make it stand out from the background. plot.outline_text(ax) if opts.transparent: fig.patch.set_alpha(0.) ax.patch.set_alpha(0.) ax.set_alpha(0.) if opts.output is None: plt.show()