コード例 #1
0
	to=time.time()
	log_posterior = posterior_obj.log_posterior(posterior_obj.theta, posterior_obj.phi, log_posterior_elements, n_pol_eff, model, normalize=True)
	print "\t\t", time.time()-to

#	lbc_log_posteriors[inj_id,:] = lbc_log_posterior

	print "\tposterior by hand"
	to=time.time()
	posterior = np.exp(log_posterior) ### find posterior
	print "\t\t", time.time()-to
	
	#=================================================
	# PLOT POSTERIOR
	#=================================================
	if not opts.skip_plots:
		estang = stats.estang(posterior, nside=nside)
		print "\tplotting posterior"
		figname = "%s/inj=%d%s.png"%(opts.output_dir, inj_id, opts.tag)
		logfigname = "%s/inj=%d-log%s.png"%(opts.output_dir, inj_id, opts.tag)
		to=time.time()
		posterior_obj.plot(figname, posterior=posterior/pixarea, title="posterior\nNo bins=%d\nlogBayes=%.3f\n$\\rho_{net}$=%.3f"%(np.sum(model),lb,snr_net), unit="prob/deg$^2$", inj=injang, est=estang)
		posterior_obj.plot(logfigname, posterior=log_posterior-np.log(pixarea), title="log(posterior)\nNo bins=%d\nlogBayes=%.3f\n$\\rho_{net}$=%.3f"%(np.sum(model),lb,snr_net), unit="log(prob/deg$^2$)", inj=injang, est=estang)
		print "\t\t", time.time()-to

	#=================================================
	# SAVE POSTERIOR
	#=================================================
	if not opts.skip_fits:
		print "\twriting posterior to file"
		fits = "%s/inj-%d%s.fits"%(opts.output_dir, inj_id, opts.tag)
		to=time.time()
コード例 #2
0
        print "reading map from", fits
    post, header = hp.read_map(fits, h=True, verbose=False)
    npix = len(post)
    if (dict(header)['ORDERING'] == 'NEST'):  ### convert to RING ordering
        post = hp.nest2ring(nside, post)
    nside = hp.npix2nside(npix)
    if opts.verbose:
        print "    nside=%d" % nside

    if opts.rankmap:  ### convert maps to rankmpas, not posteriors
        post = stats.rankmap(post, npix=npix, normed=True)

    d['post'] = post
    d['npix'] = npix
    d['nside'] = nside
    d['estang'] = stats.estang(post, nside=nside)

#=================================================
### iterate through pairs and compute statistics

for ind, label1 in enumerate(labels):
    d1 = maps[label1]
    Post1 = d1['post']
    nside1 = d1['nside']

    for label2 in labels[ind + 1:]:

        d2 = maps[label2]
        Post2 = d2['post']
        nside2 = d2['nside']
コード例 #3
0
	
			### normalize posterior
			posterior /= sum(posterior)

	                if opts.verbose and opts.time: print "\t", time.time()-to, "sec"

			if opts.scatter: ### recored the average prior for the scatter plot
				prior_map += _prior

			#======================
			# save, plot, and summarize posterior
			#======================
			### find the posterior's mode and pull out injected location
			if opts.plot_posteriors or opts.stats or opts.scatter:
				### estimated pixel
				est_theta, est_phi = stats.estang(posterior, nside=nside)

				### injected pixel
                        	inj_theta = toa_event['theta_inj']
	                        inj_phi = toa_event['phi_inj']
        	                if opts.deg:
                	                inj_theta *= utils.deg2rad
                        	        inj_phi   *= utils.deg2rad

				### record positions for scatter
				if opts.scatter:
					estangs[toa_ind] = np.array([est_theta, est_phi])
					injangs[toa_ind] = np.array([inj_theta, inj_phi])

	                ### write posteriors
        	        if opts.write_posteriors: