Esempio n. 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()
Esempio n. 2
0
def vol_render_mw(fnames, method='median', bounds=None, processes=1, max_samples=None):
	los_coll = maptools.los_collection(fnames, bounds=bounds,
	                                           processes=processes,
	                                           max_samples=max_samples)
	
	x, y, z = los_coll.get_xyz(oversample=3, max_points=20)
	rho = los_coll.get_density(method=method, oversample=3, max_points=20)
	
	print '# of points: %d' % (rho.size)
	
	x += 0.1 * np.random.random(x.shape)
	y += 0.1 * np.random.random(y.shape)
	z += 0.1 * np.random.random(z.shape)
	
	vol = vol_render_pts(x, y, z, rho, show_pts=True)
	
	set_opacity_transfer(vol, np.max(rho), 0.0001)
	set_bw_colorscheme(vol, 0., 1.)
	
	mlab.view(focalpoint=(0., 0., 0.))
	
	print 'showing...'
	mlab.show()
Esempio n. 3
0
 def __init__(self, fnames, bounds=None,
                            processes=1,
                            n_neighbors=32,
                            corr_length_core=0.25,
                            corr_length_tail=1.,
                            max_corr=1.,
                            tail_weight=0.,
                            dist_floor=0.1):
     
     self.n_neighbors = n_neighbors
     
     self.corr_length_core = corr_length_core
     self.corr_length_tail = corr_length_tail
     self.max_corr = max_corr
     self.tail_weight = tail_weight
     
     self.los_coll = maptools.los_collection(fnames, bounds=bounds,
                                                     processes=processes)
     
     self.nside = self.los_coll.nside
     self.pix_idx = self.los_coll.pix_idx
     
     print 'Finding neighbors ...'
     self.neighbor_idx, self.neighbor_ang_dist = find_neighbors(self.nside,
                                                                self.pix_idx,
                                                                self.n_neighbors)
     
     # Determine difference from priors
     self.delta = np.log(self.los_coll.los_delta_EBV)
     self.n_pix, self.n_samples, self.n_slices = self.delta.shape
     
     print 'Calculating priors ...'
     ln_Delta_EBV_prior = get_prior_ln_Delta_EBV(self.nside,
                                                 self.pix_idx,
                                                 n_regions=self.n_slices-1)
     
     #print ''
     #print 'priors:'
     #print ln_Delta_EBV_prior[0, :]
     
     for n in xrange(self.n_samples):
         self.delta[:, n, :] -= ln_Delta_EBV_prior
     
     self.delta /= 1.5  # Standardize to units of the std. dev. on the priors
     
     #print ''
     #print 'delta:'
     #print self.delta
     
     # Distance in pc to each bin
     slice_dist = np.power(10., self.los_coll.los_mu_anchor/5. + 1.)
     slice_dist = np.hstack([[0.], slice_dist])
     self.bin_dist = 0.5 * (slice_dist[:-1] + slice_dist[1:])
     
     # Determine physical distance of each voxel to its neighbors
     # shape = (pix, neighbor, slice)
     print 'Determining neighbor correlation weights ...'
     self.neighbor_dist = np.einsum('ij,k->ijk', self.neighbor_ang_dist, self.bin_dist)
     self.neighbor_dist = np.sqrt(self.neighbor_dist * self.neighbor_dist + dist_floor * dist_floor)
     self.neighbor_corr = self.corr_of_dist(self.neighbor_dist)
     #self.neighbor_corr = self.hard_sphere_corr(self.neighbor_dist, self.corr_length_core)
     
     #print ''
     #print 'dist:'
     #print self.bin_dist
     #print ''
     #print 'corr:'
     #print self.neighbor_corr
     #print ''
     
     # Set initial state
     print 'Randomizing initial state ...'
     self.beta = 1.
     self.chain = []
     self.randomize()
     self.log_state()
     self.update_order = np.arange(self.n_pix)