コード例 #1
0
def test_find_neighbors_adaptive_res():
    n_neighbors = 36
    n_disp = 5
    processes = 4
    bounds = [60., 80., -5., 5.]
    
    import glob
    
    fnames = glob.glob('/n/fink1/ggreen/bayestar/output/l70/l70.*.h5')
    
    los_coll = maptools.los_collection(fnames, bounds=bounds,
                                               processes=processes)
    
    nside, pix_idx = los_coll.nside, los_coll.pix_idx
    
    print 'Finding neighbors ...'
    neighbor_idx, neighbor_dist = find_neighbors(nside, pix_idx,
                                                       n_neighbors)
    print 'Done.'
    
    # Highlight a couple of nearest-neighbor sections
    pix_val = np.zeros(pix_idx.size)
    
    l = 0.025 * np.pi / 180.
    print l
	
    for k in xrange(n_disp):
	    idx = np.random.randint(pix_idx.size)
	    pix_val[idx] = 2
	    pix_val[neighbor_idx[idx, :]] = 1
	    
	    d = neighbor_dist[idx, :]
	    print 'Center pixel: %d' % idx
	    print d
	    print np.exp(-(d/l)**2.)
	    print ''
    
    nside_max, pix_idx_exp, pix_val_exp = maptools.reduce_to_single_res(pix_idx,
                                                                        nside,
                                                                        pix_val)
    
    size = (2000, 2000)
    
    img, bounds, xy_bounds = hputils.rasterize_map(pix_idx_exp, pix_val_exp,
                                                   nside_max, size)
    
    # Plot nearest neighbors
    
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    
    ax.imshow(img, extent=bounds, origin='lower', aspect='auto',
                                  interpolation='nearest')
    
    plt.show()
コード例 #2
0
def test_plot_resampled_map():
    infname = '/n/home09/ggreen/projects/bayestar/output/resample_test_4.h5'
    plot_fname = '/nfs_pan1/www/ggreen/maps/l70/resampled_4'
    size = (2000, 2000)
    
    # Load in chain
    f = h5py.File(infname, 'r')
    
    loc = f['/location'][:]
    chain = f['/Delta_EBV'][:,:,:] # (sample, pixel, slice)
    
    DM_min = f['/Delta_EBV'].attrs['DM_min']
    DM_max = f['/Delta_EBV'].attrs['DM_max']
    
    f.close()
    
    nside = loc[:]['nside']
    pix_idx = loc[:]['pix_idx']
    
    # Rasterize each sample and plot
    import matplotlib.pyplot as plt
    
    for n,sample in enumerate(chain):
        print 'Plotting sample %d ...' % n
        pix_val = np.sum(sample[:, :12], axis=1)
        
    	nside_max, pix_idx_exp, pix_val_exp = maptools.reduce_to_single_res(pix_idx,
                                                                            nside,
                                                                            pix_val)
        
        
        img, bounds, xy_bounds = hputils.rasterize_map(pix_idx_exp, pix_val_exp,
                                                       nside_max, size)
        
        fig = plt.figure()
        ax = fig.add_subplot(1,1,1)
        
        ax.imshow(img.T, extent=bounds, origin='lower', aspect='auto',
                                      interpolation='nearest')
        
        fname = '%s.%.5d.png' % (plot_fname, n)
        fig.savefig(fname, dpi=300)
        
        plt.close(fig)
        del img
    
    print 'Done.'