def process(fitsfilename): sky_map, metadata = fits.read_sky_map(fitsfilename, nest=None) coinc_event_id = metadata['objid'] try: runtime = metadata['runtime'] except KeyError: runtime = float('nan') simulation_id, true_ra, true_dec, far, snr = db.execute(""" SELECT DISTINCT sim.simulation_id AS simulation_id, sim.longitude AS ra, sim.latitude AS dec, ci.combined_far AS far, ci.snr AS snr FROM coinc_event_map AS cem1 INNER JOIN coinc_event_map AS cem2 ON (cem1.coinc_event_id = cem2.coinc_event_id) INNER JOIN sim_inspiral AS sim ON (cem1.event_id = sim.simulation_id) INNER JOIN coinc_inspiral AS ci ON (cem2.event_id = ci.coinc_event_id) WHERE cem1.table_name = 'sim_inspiral' AND cem2.table_name = 'coinc_event' AND cem2.event_id = ?""", (coinc_event_id,)).fetchone() searched_area, searched_prob, offset, searched_modes, contour_areas, area_probs, contour_modes = postprocess.find_injection( sky_map, true_ra, true_dec, contours=[0.01 * p for p in contours], areas=areas, modes=modes, nest=metadata['nest']) if snr is None: snr = float('nan') if far is None: far = float('nan') ret = [coinc_event_id, simulation_id, far, snr, searched_area, searched_prob, offset, runtime] + contour_areas + area_probs if modes: ret += [searched_modes] + contour_modes return ret
def process(fitsfilename): sky_map, metadata = fits.read_sky_map(fitsfilename, nest=None) coinc_event_id = metadata['objid'] try: runtime = metadata['runtime'] except KeyError: runtime = float('nan') row = db.execute(""" SELECT DISTINCT sim.simulation_id AS simulation_id, sim.longitude AS ra, sim.latitude AS dec, ci.combined_far AS far, ci.snr AS snr FROM coinc_event_map AS cem1 INNER JOIN coinc_event_map AS cem2 ON (cem1.coinc_event_id = cem2.coinc_event_id) INNER JOIN sim_inspiral AS sim ON (cem1.event_id = sim.simulation_id) INNER JOIN coinc_inspiral AS ci ON (cem2.event_id = ci.coinc_event_id) WHERE cem1.table_name = 'sim_inspiral' AND cem2.table_name = 'coinc_event' AND cem2.event_id = ?""", (coinc_event_id,)).fetchone() if row is None: raise ValueError( "No database record found for event '{0}' in '{1}'".format( coinc_event_id, command.sqlite_get_filename(db))) simulation_id, true_ra, true_dec, far, snr = row searched_area, searched_prob, offset, searched_modes, contour_areas, area_probs, contour_modes = postprocess.find_injection( sky_map, true_ra, true_dec, contours=[0.01 * p for p in contours], areas=areas, modes=modes, nest=metadata['nest']) if snr is None: snr = float('nan') if far is None: far = float('nan') distmean = metadata.get('distmean', float('nan')) diststd = metadata.get('diststd', float('nan')) ret = [coinc_event_id, simulation_id, far, snr, searched_area, searched_prob, offset, runtime, distmean, diststd] + contour_areas + area_probs if modes: ret += [searched_modes] + contour_modes return ret
import os import json import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams import healpy as hp import lal from lalinference import fits from lalinference import plot from lalinference.bayestar import postprocess fig = plt.figure(frameon=False) ax = plt.axes(projection='mollweide' if opts.geo else 'astro hours mollweide') ax.grid() skymap, metadata = fits.read_sky_map(opts.input.name, nest=None) nside = hp.npix2nside(len(skymap)) if opts.geo: dlon = -lal.GreenwichMeanSiderealTime(lal.LIGOTimeGPS(metadata['gps_time'])) % (2*np.pi) else: dlon = 0 # 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., vmax=vmax)
import json import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams import healpy as hp import lal from lalinference import fits from lalinference import plot fig = plt.figure(figsize=(opts.figure_width, opts.figure_height), frameon=False) ax = plt.subplot(111, projection='mollweide' if opts.geo else 'astro mollweide') ax.cla() ax.grid() skymap, metadata = fits.read_sky_map(infilename, nest=None) nside = hp.npix2nside(len(skymap)) if opts.geo: dlon = -lal.GreenwichMeanSiderealTime(lal.LIGOTimeGPS(metadata['gps_time'])) % (2*np.pi) else: dlon = 0 # 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., vmax=vmax, cmap=plt.get_cmap(opts.colormap))
# incl_sampler = mcsampler.cos_samp_vector # this is NOT dec_samp_vector, because the angular zero point is different! sampler.add_parameter("inclination", pdf = incl_sampler, cdf_inv = None, left_limit = param_limits["inclination"][0], right_limit = param_limits["inclination"][1], prior_pdf = mcsampler.uniform_samp_theta, adaptive_sampling = not opts.no_adapt) # # Distance - luminosity distance to source in parsecs # sampler: uniform distance over [dmin, dmax), adaptive sampling # dist_sampler = functools.partial(mcsampler.uniform_samp_vector, param_limits["distance"][0], param_limits["distance"][1]) sampler.add_parameter("distance", pdf = dist_sampler, cdf_inv = None, left_limit = param_limits["distance"][0], right_limit = param_limits["distance"][1], prior_pdf = numpy.vectorize(lambda x: x**2/(param_limits["distance"][1]**3/3. - param_limits["distance"][0]**3/3.)), adaptive_sampling = not opts.no_adapt) if opts.skymap_file is not None: # # Right ascension and declination -- use a provided skymap # smap, _ = bfits.read_sky_map(opts.skymap_file) ss_sampler = mcsampler.HealPixSampler(smap) isotropic_bstar_sampler = numpy.vectorize(lambda dec, ra: 1.0/len(smap)) # FIXME: Should the left and right limits be modified? sampler.add_parameter(("declination", "right_ascension"), \ pdf = ss_sampler.pseudo_pdf, \ cdf_inv = ss_sampler.pseudo_cdf_inverse, \ left_limit = (param_limits["declination"][0], param_limits["right_ascension"][0]), \ right_limit = (param_limits["declination"][1], param_limits["right_ascension"][1]), \ prior_pdf = isotropic_bstar_sampler) else: # # Right ascension - angle in radians from prime meridian plus hour angle # sampler: uniform in [0, 2pi), adaptive sampling
# Late imports from matplotlib import pyplot as plt from matplotlib import gridspec from matplotlib import transforms from lalinference import fits from lalinference import marker from lalinference.bayestar.distance import ( principal_axes, volume_render, marginal_pdf) import healpy as hp import numpy as np import scipy.stats # Read input, determine input resolution. progress.update(-1, 'Loading FITS file') (prob, mu, sigma, norm), metadata = fits.read_sky_map( opts.input.name, distances=True) npix = len(prob) nside = hp.npix2nside(npix) progress.update(-1, 'Preparing projection') if opts.align_to is None: prob2, mu2, sigma2 = prob, mu, sigma else: (prob2, mu2, sigma2, _), _ = fits.read_sky_map( opts.align_to.name, distances=True) R = np.ascontiguousarray(principal_axes(prob2, mu2, sigma2)) if opts.chain: chain = np.recfromtxt(opts.chain, names=True) chain = np.dot(R.T, (hp.ang2vec(
nargs="?", help="Input FITS file [default: stdin]", ) opts = parser.parse_args() # Late imports from lalinference import fits from lalinference.bayestar import postprocess import healpy as hp import numpy as np import json # Read input file prob, _ = fits.read_sky_map(opts.input.name, nest=True) # Resample if requested if opts.nside is not None and opts.interpolate in ("nearest", "nested"): prob = hp.ud_grade(prob, opts.nside, order_in="NESTED", power=-2) elif opts.nside is not None and opts.interpolate == "bilinear": prob = postprocess.smooth_ud_grade(prob, opts.nside, nest=True) if opts.interpolate == "nested": prob = postprocess.interpolate_nested(prob, nest=True) # Find credible levels i = np.flipud(np.argsort(prob)) cumsum = np.cumsum(prob[i]) cls = np.empty_like(prob) cls[i] = cumsum * 100
param_limits["distance"][1]) sampler.add_parameter( "distance", pdf=dist_sampler, cdf_inv=None, left_limit=param_limits["distance"][0], right_limit=param_limits["distance"][1], prior_pdf=numpy.vectorize(lambda x: x**2 / (param_limits["distance"][ 1]**3 / 3. - param_limits["distance"][0]**3 / 3.)), adaptive_sampling=not opts.no_adapt) if opts.skymap_file is not None: # # Right ascension and declination -- use a provided skymap # smap, _ = bfits.read_sky_map(opts.skymap_file) ss_sampler = mcsampler.HealPixSampler(smap) isotropic_bstar_sampler = numpy.vectorize(lambda dec, ra: 1.0 / len(smap)) # FIXME: Should the left and right limits be modified? sampler.add_parameter(("declination", "right_ascension"), \ pdf = ss_sampler.pseudo_pdf, \ cdf_inv = ss_sampler.pseudo_cdf_inverse, \ left_limit = (param_limits["declination"][0], param_limits["right_ascension"][0]), \ right_limit = (param_limits["declination"][1], param_limits["right_ascension"][1]), \ prior_pdf = isotropic_bstar_sampler) else: # # Right ascension - angle in radians from prime meridian plus hour angle # sampler: uniform in [0, 2pi), adaptive sampling
# Late imports from matplotlib import pyplot as plt from matplotlib import gridspec from matplotlib import transforms from lalinference import fits from lalinference import marker from lalinference.bayestar.distance import ( principal_axes, volume_render_kernel, marginal_distribution) import healpy as hp import numpy as np import scipy.stats # Read input, determine input resolution. progress.update(-1, 'Loading FITS file') (prob, mu, sigma, norm), metadataa = fits.read_sky_map( opts.input.name, distances=True) npix = len(prob) nside = hp.npix2nside(npix) progress.update(-1, 'Preparing projection') R = np.ascontiguousarray(principal_axes(prob, mu, sigma)) if opts.chain: chain = np.recfromtxt(opts.chain, names=True) chain = np.dot(R.T, (hp.ang2vec( 0.5 * np.pi - chain['dec'], chain['ra']) * np.atleast_2d(chain['dist']).T).T) fig = plt.figure(frameon=False) n = 1 if opts.projection else 2
import numpy as np from matplotlib import pyplot as plt import healpy as hp from matplotlib import collections from matplotlib import patches from matplotlib import ticker ra0 = 130 dec0 = -10 phi0 = np.deg2rad(ra0) theta0 = 0.5 * np.pi - np.deg2rad(dec0) # ra0 = 137.8 # dec0 = -39.9 xyz0 = hp.ang2vec(0.5*np.pi - np.deg2rad(dec0), np.deg2rad(ra0)) prob, meta = fits.read_sky_map('../cbc/emfollowup/papers/first2years/data/2015/compare/18951/bayestar.fits.gz', nest=True) def get_vertices(m): m = np.copy(m) top_npix = len(m) top_nside = hp.npix2nside(top_npix) top_order = int(np.log2(top_nside)) for order in range(top_order + 1): nside = 1 << order npix = hp.nside2npix(nside) stride = 1 << (2 * (top_order - order)) keep = (hp.pix2vec(nside, np.arange(npix), nest=True) * np.expand_dims(xyz0, 1)).sum(0) >= np.cos(np.deg2rad(30)) if order < top_order: mm = m.reshape((-1, stride)) keep &= (mm[:, :-1] == mm[:, 1:]).all(axis=1) m += hp.ud_grade(np.where(keep, np.nan, 0), nside_out=top_nside, order_in='NEST', order_out='NEST')
from matplotlib import pyplot as plt import healpy as hp from matplotlib import collections from matplotlib import patches from matplotlib import ticker ra0 = 130 dec0 = -10 phi0 = np.deg2rad(ra0) theta0 = 0.5 * np.pi - np.deg2rad(dec0) # ra0 = 137.8 # dec0 = -39.9 xyz0 = hp.ang2vec(0.5 * np.pi - np.deg2rad(dec0), np.deg2rad(ra0)) prob, meta = fits.read_sky_map( '../cbc/emfollowup/papers/first2years/data/2015/compare/18951/bayestar.fits.gz', nest=True) def get_vertices(m): m = np.copy(m) top_npix = len(m) top_nside = hp.npix2nside(top_npix) top_order = int(np.log2(top_nside)) for order in range(top_order + 1): nside = 1 << order npix = hp.nside2npix(nside) stride = 1 << (2 * (top_order - order)) keep = (hp.pix2vec(nside, np.arange(npix), nest=True) * np.expand_dims(xyz0, 1)).sum(0) >= np.cos(np.deg2rad(30)) if order < top_order: