# perform sky localization log.info("starting sky localization") sky_map = rasterize(gracedb_sky_map( coinc_file, psd_file, opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, nside=opts.nside, f_high_truncate=opts.f_high_truncate, method=opts.method, chain_dump=chain_dump, enable_snr_series=opts.enable_snr_series)) sky_map.meta['objid'] = str(graceid) sky_map.meta['url'] = 'https://gracedb.ligo.org/events/{0}'.format(graceid) log.info("sky localization complete") # upload FITS file with command.TemporaryDirectory() as fitsdir: fitspath = os.path.join(fitsdir, opts.output) fits.write_sky_map(fitspath, sky_map, nest=True) log.debug('wrote FITS file: %s', opts.output) if opts.dry_run: command.rename(fitspath, os.path.join('.', opts.output)) else: gracedb.writeLog( graceid, "BAYESTAR rapid sky localization ready", filename=fitspath, tagname=("sky_loc", "lvem")) log.debug('uploaded FITS file') except: # Produce log message for any otherwise uncaught exception log.exception("sky localization failed") if opts.dry_run: # Then re-raise the exception if we are in dry-run mode raise
order, ipix = moc.uniq2nest(p['UNIQ']) nside = hp.order2nside(order.astype(int)) max_order = order.max().astype(int) max_nside = hp.order2nside(max_order) theta = 0.5 * np.pi - ranking_samples['dec'] phi = ranking_samples['ra'] ranking_samples['ipix'] = hp.ang2pix(max_nside, theta, phi, nest=True) ranking_samples.sort('ipix') result = np.transpose( [pixstats(ranking_samples, max_nside, n, i) for n, i in zip(nside, ipix)]) # Add distance info if necessary. if 'dist' in ranking_samples.colnames: p['PROBDENSITY'], distmean, diststd = result p['DISTMU'], p['DISTSIGMA'], p['DISTNORM'] = \ distance.moments_to_parameters(distmean, diststd) # Add marginal distance moments p.meta['distmean'] = np.mean(samples['dist']) p.meta['diststd'] = np.std(samples['dist']) else: p['PROBDENSITY'] = result # Write output to FITS file. fits.write_sky_map(opts.output, p, nest=True, creator=parser.prog, objid=opts.objid, gps_time=samples['time'].mean())
opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, opts.cosmology, psds=psds, method=method, nside=opts.nside, chain_dump=chain_dump, phase_convention=opts.phase_convention, snr_series=snrs, enable_snr_series=opts.enable_snr_series) sky_map.meta['objid'] = coinc_event_id except (ArithmeticError, ValueError): log.exception("%s:method '%s':sky localization failed", coinc_event_id, method) count_sky_maps_failed += 1 if not opts.keep_going: raise else: log.info("%s:method '%s':saving sky map", coinc_event_id, method) filename = '%d.%s.fits' % (int_coinc_event_id, method) fits.write_sky_map(os.path.join(opts.output, filename), sky_map, nest=True) if count_sky_maps_failed > 0: raise RuntimeError("{0} sky map{1} did not converge".format( count_sky_maps_failed, 's' if count_sky_maps_failed > 1 else ''))
opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, psds=psds, method=method, nside=opts.nside, chain_dump=chain_dump, phase_convention=opts.phase_convention, snr_series=snrs, enable_snr_series=opts.enable_snr_series)) sky_map.meta['objid'] = str(coinc.coinc_event_id) except (ArithmeticError, ValueError): log.exception("%s:method '%s':sky localization failed", coinc.coinc_event_id, method) count_sky_maps_failed += 1 if not opts.keep_going: raise else: log.info("%s:method '%s':saving sky map", coinc.coinc_event_id, method) fits.write_sky_map('%s.%s.fits.gz' % (int(coinc.coinc_event_id), method), sky_map, nest=True) if count_sky_maps_failed > 0: raise RuntimeError("{0} sky map{1} did not converge".format( count_sky_maps_failed, 's' if count_sky_maps_failed > 1 else ''))
opts.min_distance, opts.max_distance, opts.prior_distance_power, phase_convention=opts.phase_convention, nside=opts.nside, f_high_truncate=opts.f_high_truncate, method=opts.method, chain_dump=chain_dump) prob, distmu, distsigma, _ = sky_map distmean, diststd = distance.parameters_to_marginal_moments( prob, distmu, distsigma) log.info("sky localization complete") # upload FITS file fitsdir = tempfile.mkdtemp() try: fitspath = os.path.join(fitsdir, opts.output) fits.write_sky_map(fitspath, sky_map, gps_time=float(epoch), creator=parser.prog, objid=str(graceid), url='https://gracedb.ligo.org/events/{0}'.format(graceid), runtime=elapsed_time, instruments=instruments, distmean=distmean, diststd=diststd, origin='LIGO/Virgo', nest=True) if not opts.dry_run: gracedb.writeLog(graceid, "INFO:BAYESTAR:uploaded sky map", filename=fitspath, tagname=("sky_loc", "lvem")) else: command.rename(fitspath, os.path.join('.', opts.output)) finally: shutil.rmtree(fitsdir) except: # Produce log message for any otherwise uncaught exception log.exception("sky localization failed") # Then re-raise the exception raise
chain_dump = '%s.chain.npy' % int(coinc.coinc_event_id) else: chain_dump = None try: sky_map, epoch, elapsed_time = ligolw_sky_map( sngl_inspirals, opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, psds=psds, method=method, nside=opts.nside, chain_dump=chain_dump, phase_convention=opts.phase_convention, snr_series=snrs, enable_snr_series=opts.enable_snr_series) prob, distmu, distsigma, _ = sky_map distmean, diststd = distance.parameters_to_marginal_moments( prob, distmu, distsigma) except (ArithmeticError, ValueError): log.exception("%s:method '%s':sky localization failed", coinc.coinc_event_id, method) count_sky_maps_failed += 1 if not opts.keep_going: raise else: log.info("%s:method '%s':saving sky map", coinc.coinc_event_id, method) fits.write_sky_map('%s.%s.fits.gz' % (int(coinc.coinc_event_id), method), sky_map, objid=str(coinc.coinc_event_id), gps_time=float(epoch), creator=parser.prog, runtime=elapsed_time, distmean=distmean, diststd=diststd, instruments=instruments, nest=True) if count_sky_maps_failed > 0: raise RuntimeError("{0} sky map{1} did not converge".format( count_sky_maps_failed, 's' if count_sky_maps_failed > 1 else ''))
# Evaluate per-pixel density. p = derasterize(Table([p], names=['PROB'])) order, ipix = moc.uniq2nest(p['UNIQ']) nside = hp.order2nside(order.astype(int)) max_order = order.max().astype(int) max_nside = hp.order2nside(max_order) theta = 0.5*np.pi - ranking_samples['dec'] phi = ranking_samples['ra'] ranking_samples['ipix'] = hp.ang2pix(max_nside, theta, phi, nest=True) ranking_samples.sort('ipix') result = np.transpose( [pixstats(ranking_samples, max_nside, n, i) for n, i in zip(nside, ipix)]) # Add distance info if necessary. if 'dist' in ranking_samples.colnames: p['PROBDENSITY'], distmean, diststd = result p['DISTMU'], p['DISTSIGMA'], p['DISTNORM'] = \ distance.moments_to_parameters(distmean, diststd) # Add marginal distance moments p.meta['distmean'] = np.mean(samples['dist']) p.meta['diststd'] = np.std(samples['dist']) else: p['PROBDENSITY'] = result # Write output to FITS file. fits.write_sky_map( opts.output, p, nest=True, creator=parser.prog, objid=opts.objid, gps_time=samples['time'].mean())
log.info("starting sky localization") sky_map = rasterize(localize( event, opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, opts.cosmology, method=opts.method, nside=opts.nside, chain_dump=chain_dump, enable_snr_series=opts.enable_snr_series, f_high_truncate=opts.f_high_truncate)) sky_map.meta['objid'] = str(graceid) sky_map.meta['url'] = 'https://gracedb.ligo.org/events/{0}'.format( graceid) log.info("sky localization complete") # upload FITS file with command.TemporaryDirectory() as fitsdir: fitspath = os.path.join(fitsdir, opts.output) fits.write_sky_map(fitspath, sky_map, nest=True) log.debug('wrote FITS file: %s', opts.output) if opts.dry_run: command.rename(fitspath, os.path.join('.', opts.output)) else: gracedb.writeLog( graceid, "BAYESTAR rapid sky localization ready", filename=fitspath, tagname=tags) log.debug('uploaded FITS file') except KeyboardInterrupt: # Produce log message and then exit if we receive SIGINT (ctrl-C). log.exception("sky localization failed") raise except: # Produce log message for any otherwise uncaught exception. # Unless we are in dry-run mode, keep going.
enable_snr_series=opts.enable_snr_series) prob, distmu, distsigma, _ = sky_map distmean, diststd = distance.parameters_to_marginal_moments( prob, distmu, distsigma) log.info("sky localization complete") # upload FITS file with command.TemporaryDirectory() as fitsdir: fitspath = os.path.join(fitsdir, opts.output) fits.write_sky_map( fitspath, sky_map, gps_time=float(epoch), creator=parser.prog, objid=str(graceid), url='https://gracedb.ligo.org/events/{0}'.format(graceid), runtime=elapsed_time, instruments=instruments, distmean=distmean, diststd=diststd, origin='LIGO/Virgo', nest=True) log.debug('wrote FITS file: %s', opts.output) if opts.dry_run: command.rename(fitspath, os.path.join('.', opts.output)) else: gracedb.writeLog(graceid, "BAYESTAR rapid sky localization ready", filename=fitspath, tagname=("sky_loc", "lvem")) log.debug('uploaded FITS file')
if opts.chain_dump: chain_dump = '%s.chain.npy' % int_coinc_event_id else: chain_dump = None try: sky_map = localize( event, opts.waveform, opts.f_low, opts.min_distance, opts.max_distance, opts.prior_distance_power, opts.cosmology, method=method, nside=opts.nside, chain_dump=chain_dump, enable_snr_series=opts.enable_snr_series, f_high_truncate=opts.f_high_truncate) sky_map.meta['objid'] = coinc_event_id except (ArithmeticError, ValueError): log.exception( "%s:method '%s':sky localization failed", coinc_event_id, method) count_sky_maps_failed += 1 if not opts.keep_going: raise else: log.info( "%s:method '%s':saving sky map", coinc_event_id, method) filename = '%d.%s.fits' % (int_coinc_event_id, method) fits.write_sky_map( os.path.join(opts.output, filename), sky_map, nest=True) if count_sky_maps_failed > 0: raise RuntimeError("{0} sky map{1} did not converge".format( count_sky_maps_failed, 's' if count_sky_maps_failed > 1 else ''))
prob = np.mean([ hp.ud_grade(prob, nside, order_in='NESTED', order_out='NESTED', power=-2) for prob in probs ], axis=0) # Describe the processing of this file history = ['Arithmetic mean of the following {} sky maps:'.format(len(probs))] history += [' ' + file.name for file in opts.input] # Create metadata dictionary for FITS header meta = dict(creator=parser.prog, nest=True, history=history) # Copy some header values from the first sky map copy_keys = ('objid', 'url', 'instruments', 'gps_time') meta.update({key: metas[0][key] for key in copy_keys if key in metas[0]}) # Determine output filename if opts.output is not None: output = opts.output else: output = '_plus_'.join( os.path.split(file.name)[1].partition('.fits')[0] for file in opts.input) + '.fits.gz' # Write output filename to stdout print(output) # Write output file fits.write_sky_map(output, prob, **meta)