import c2raytools as c2t import argparse import sys import os import glob def parse_options(): parser = argparse.ArgumentParser(prog='make_dt_lightcone', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--xfrac', '-x', type=str, default = None, help='The lightcone file containing the ionized fractions.') parser.add_argument('--density', '-d', type=str, default = None, help='The lightcone file containing the density.') parser.add_argument('--output', '-o', type=str, help='The name of the output file.',\ default='dt_lightcone.cbin') parser.add_argument('--min_z', type=float, default = None, help='The lowest_redshift.') parser.add_argument('--boxsize', '-b', type=float, default=425, help='The side of the box in Mpc/h.') args = parser.parse_args() return args if __name__ == '__main__': if len(sys.argv) <= 1: print 'No arguments given. Use -h to print help.' sys.exit(2) args = parse_options() c2t.set_verbose(True) c2t.set_sim_constants(args.boxsize) xfrac, xfile_type = c2t.get_data_and_type(args.xfrac, cbin_bits = 32, cbin_order = 'c') density, dfile_type = c2t.get_data_and_type(args.density, cbin_bits = 32, cbin_order = 'c') dt_lightcone = c2t.calc_dt_lightcone(xfrac, density, args.min_z) c2t.save_cbin(args.output, dt_lightcone)
#List all the data files dens_files = [density_dir + '%.3fn_all.dat' % z for z in density_redshifts] vel_files = [velocity_dir + '%.3fv_all.dat' % z for z in density_redshifts] xfrac_files = [xfrac_dir + 'xfrac3d_%.3f.bin' % z for z in xfrac_redshifts] #Make the ionization fraction lightcone xfrac_lightcone, z = c2t.make_lightcone(xfrac_files, z_low, z_high) #Make the density lightcone dens_lightcone, z = c2t.make_lightcone(dens_files, z_low, z_high) #Combine ionization fraction and density to make a dT lightcone dT_lightcone = c2t.calc_dt_lightcone(xfrac_lightcone, dens_lightcone, \ lowest_z=z.min()) #Make a velocity lightcone vel_lightcone, z = c2t.make_velocity_lightcone(vel_files, dens_files, \ z_low, z_high) #Apply redshift space distortions. This is done in the same way as for #coeval data volumes. Just be sure to set periodic to False and #to specify the the velocity_axis argument (see the documentation #of get_distorted_dt for more information) rsd_dT = c2t.get_distorted_dt(dT_lightcone, vel_lightcone, z, \ num_particles=30, los_axis=2, velocity_axis=0, \ periodic=False) #Save the results c2t.save_cbin(output_dir + 'lightcone_rsd.cbin', rsd_dT)
vel_file = ''.join(glob.glob(density_path+'%.3fv_all.dat'%(z_arr[i-1]))) print 'Velocity file = %s' % vel_file vfile = c2t.VelocityFile(vel_file) kms = vfile.get_kms_from_density(dfile) mesh = (xfile.mesh_x, xfile.mesh_y, xfile.mesh_z) print 'mesh = ', mesh dT_box = c2t.calc_dt(xfile, dfile, xfile.z) dT_file = './dT_boxes/dT_%.3f.cbin' % (z_arr[i]) print 'dT_box file = %s' % dT_file #rho = dfile.cgs_density #print 'rho_crit*OmegaB',c2t.const.rho_crit_0*c2t.const.OmegaB#*(1+z_arr[i])**3 #print 'rho.mean()',rho.mean() c2t.save_cbin(dT_file, dT_box, bits=64, order='F') dT_pv_box = c2t.get_distorted_dt(dT_box, kms, xfile.z, num_particles=40) dT_pv_file = './dT_pv_boxes/dT_pv_%.3f.cbin' % (z_arr[i]) print 'dT_pv_box file = %s' % dT_pv_file c2t.save_cbin(dT_pv_file, dT_pv_box, bits=64, order='F') dT_mean = dT_box.mean() dT_rms_box = np.sqrt((dT_box - dT_mean)**2) dT_rms = dT_rms_box.mean() dT_rms_other = c2t.rootmeansquare(dT_box) dT_pv_mean = dT_pv_box.mean() dT_pv_rms_box = np.sqrt((dT_pv_box - dT_pv_mean)**2) dT_pv_rms = dT_pv_rms_box.mean() print 'z, nu, dT_mean, dT_rms %.3f %.3f %.4f %.4f %.4f' % (z_arr[i], nu[i], dT_mean, dT_rms, dT_rms_other)
c2t.set_verbose(True) c2t.set_sim_constants(boxsize_cMpc = 244.) z_low = 6.0 z_high = 22. # Read in dT boxes, get filenames, and make lightcones dT_files = glob.glob(dT_path+'dT_*.cbin') dens_files = glob.glob(density_path+'*n_all.dat') vel_files = glob.glob(density_path+'*v_all.dat') vel_lightcone, z = c2t.make_velocity_lightcone(vel_files, dens_files, z_low, z_high, los_axis=0) dT_lightcone,out_z = c2t.make_lightcone(dT_files, z_low , z_high, cbin_bits=64, cbin_order='F', los_axis=0) rsd_dT = c2t.get_distorted_dt(dT_lightcone, vel_lightcone, z, num_particles=40, los_axis=2, velocity_axis=0, periodic=False) c2t.save_cbin(out_box, dT_lightcone) c2t.save_cbin(out_pv_box, rsd_dT) np.savetxt(file_z,out_z,fmt="%f") vel_lightcone, z = c2t.make_velocity_lightcone(vel_files, dens_files, z_low, z_high, los_axis=1) dT_lightcone,out_z = c2t.make_lightcone(dT_files, z_low , z_high, cbin_bits=64, cbin_order='F', los_axis=1) rsd_dT = c2t.get_distorted_dt(dT_lightcone, vel_lightcone, z, num_particles=40, los_axis=2, velocity_axis=1, periodic=False) c2t.save_cbin(out1_box, dT_lightcone) c2t.save_cbin(out1_pv_box, rsd_dT) np.savetxt(file1_z,out_z,fmt="%f") vel_lightcone, z = c2t.make_velocity_lightcone(vel_files, dens_files, z_low, z_high, los_axis=2) dT_lightcone,out_z = c2t.make_lightcone(dT_files, z_low , z_high, cbin_bits=64, cbin_order='F', los_axis=2) rsd_dT = c2t.get_distorted_dt(dT_lightcone, vel_lightcone, z, num_particles=40, los_axis=2, velocity_axis=2, periodic=False)