def read_density(self, dens_file, contrast=False): if self.dens_file_reader is not None: dens = self.dens_file_reader(dens_file) else: t2c.set_sim_constants(int(self.Lbox*0.7)) dens = t2c.DensityFile(dens_file).raw_density#cgs_density*u.g/u.cm**3 self.nGrid = dens.shape[0] if contrast: dens = dens/dens.mean() - 1. return dens
# Get data from dawn-1 xf_dir = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/500Mpc/500Mpc_z50_0_300/results/' #'/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/500Mpc/500Mpc_f2_0_300/retrieved_from_khagolaz/results/' dn_dir = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/500Mpc/coarser_densities/nc300/' xf_files = glob(xf_dir+'xfrac3d_*') dn_files = glob(dn_dir+'*n_all.dat') xf_zs = np.array([ff.split('xfrac3d_')[-1].split('.bin')[0] for ff in xf_files]).astype(float) dn_zs = np.array([ff.split('/')[-1].split('n_all')[0] for ff in dn_files]).astype(float) zs = np.intersect1d(xf_zs,dn_zs) filename = './slices_dataset_500Mpc_z50_0_300.pkl' #'./slices_dataset_500Mpc_f2_0_300.pkl' dataset = pickle.load(open(filename, 'rb')) if glob(filename) else {} if len(dataset.keys())==0: for zz in tqdm(zs): xx = t2c.XfracFile(xf_dir+'xfrac3d_{:.3f}.bin'.format(zz)).xi dd = t2c.DensityFile(dn_dir+'{:.3f}n_all.dat'.format(zz)).cgs_density dt = t2c.calc_dt(xx, dd, zz) dataset['{:.3f}'.format(zz)] = {'xf': xx[:,:,100], 'dt': dt[:,:,100]} pickle.dump(dataset,open(filename, 'wb')) dataset_zs = np.array([ii for ii in dataset.keys()]).astype(float) dataset_xs = np.array([dataset['{:.3f}'.format(zz)]['xf'].mean() for zz in dataset_zs]) dataset_zs = dataset_zs[np.argsort(-dataset_zs)][12:-12] dataset_range = np.array([[dataset['{:.3f}'.format(zz)]['dt'].min(),dataset['{:.3f}'.format(zz)]['dt'].max()] for zz in dataset_zs]) class AnimatedGif: def __init__(self, size=(640, 480), figsize=None, fps=1, cmap='jet', text_color='red'): self.fig = plt.figure(figsize=figsize) if figsize is None: self.fig.set_size_inches(size[0] / 100, size[1] / 100) ax = self.fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) ax.set_xticks([])
# interpolate redshift list redshift_xi = t2c.get_xfrac_redshifts(path_xi) redshift_dens = t2c.get_dens_redshifts(path_dens) redshift = SameValuesInArray(redshift_xi, redshift_dens) print('tot redshift:', redshift.size) #### Code below this is important t2c.set_sim_constants(sim) min_arr = [] max_arr = [] for i in tqdm(range(len(redshift))): z = redshift[i] xf = t2c.XfracFile('%sxfrac3d_%.3f.bin' %(path_xi, z)).xi dn = t2c.DensityFile('%s%.3fn_all.dat' %(path_dens, z)).cgs_density dt = t2c.calc_dt(xf, dn, z) ps_dt = t2c.power_spectrum_nd(dt) if(smt): ps_dt = ndimage.gaussian_filter(ps_dt, 5, mode='wrap') for ax in ['x', 'y', 'z']: if(ax=='x'): rs_dt = np.log10(ps_dt[:, int(mesh/2):int(mesh/2)+out_res, int(mesh/2):int(mesh/2)+out_res]) elif(ax=='y'): rs_dt = np.log10(ps_dt[int(mesh/2):int(mesh/2)+out_res, :, int(mesh/2):int(mesh/2)+out_res]) else: rs_dt = np.log10(ps_dt[int(mesh/2):int(mesh/2)+out_res, int(mesh/2):int(mesh/2)+out_res, :]) for j in range(len(rs_dt)): if(ax=='x'): pp = rs_dt[j, :, :]
Setup script ''' import numpy as np import matplotlib.pyplot as plt from sim21cm import extreme_model import tools21cm as t2c t2c.set_sim_constants(500) # Instantaneous simulation ### In this mode, we take one density field and ionize it based on a ### given average ionization fraction dens_file = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/500Mpc/coarser_densities/nc300/8.064n_all.dat' dens = t2c.DensityFile(dens_file).raw_density xi = [0.3, 0.7] simoi = extreme_model.OutsideIn() xhii0 = simoi.run_instant(dens, xi[0], volume_averaged=True, mass_averaged=True, write=False) xhii1 = simoi.run_instant(dens, xi[1], volume_averaged=True, mass_averaged=True, write=False) plt.figure()
kwargs['histtype'] = 'step' if not 'color' in kwargs.keys(): kwargs['color'] = 'k' pl.hist(plot_data.flatten(), log=logscale, **kwargs) #Labels if datatype == 'xfrac': pl.xlabel('$x_i$') elif datatype == 'density': pl.xlabel('$\\rho \; \mathrm{[g \; cm^{-3}]}$') if __name__ == '__main__': import tools21cm as t2c import pylab as pl t2c.set_verbose(True) pl.figure() dfilename = '/disk/sn-12/garrelt/Science/Simulations/Reionization/C2Ray_WMAP5/114Mpc_WMAP5/coarser_densities/nc256_halos_removed/6.905n_all.dat' xfilename = '/disk/sn-12/garrelt/Science/Simulations/Reionization/C2Ray_WMAP5/114Mpc_WMAP5/114Mpc_f2_10S_256/results_ranger/xfrac3d_8.958.bin' dfile = t2c.DensityFile(dfilename) # plot_slice(dfile, los_axis=1, logscale=True, cmap=pl.cm.hot) # ax2 = pl.subplot(1,2,2) # plot_slice(xfilename) plot_slice(t2c.XfracFile(xfilename)) pl.show()