density_redshifts = c2t.get_dens_redshifts(density_dir, z_low, z_high, bracket=True) xfrac_redshifts = c2t.get_xfrac_redshifts(xfrac_dir, z_low, z_high, bracket=True) #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)
import numpy as np 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)
#First we need lists of all the available ionization fraction and density files. #Here, we use python's built-in glob command, which makes a list of all such files: xfrac_files = glob.glob(xfrac_dir + '/xfrac3d_*.bin') density_files = glob.glob(density_dir + '/*n_all.dat') #Make the ionization fraction lightcone xfrac_lightcone, z = c2t.make_lightcone(xfrac_files, z_low = 7.059, z_high = 7.3) #Make the density lightcone density_lightcone, z = c2t.make_lightcone(density_files, z_low = 7.059, z_high = 7.3) #The dT lightcone is made by combining density and ionization fraction. #If you already have a bunch of dT files, you can make a lightcone directly #using the make_lightcone method dt_lightcone = c2t.calc_dt_lightcone(xfrac_lightcone, density_lightcone, lowest_z = z.min()) print dt_lightcone.shape #Calculate the mean dT along the line-of-sight of the lightcone dT_mean = c2t.apply_func_along_los(dt_lightcone, func=np.mean, los_axis=2) #Plot the dT volume pl.subplot(121) pl.imshow(dt_lightcone[0,:,:], extent=[z.min(),z.max(), 0, c2t.conv.LB], aspect='auto') pl.colorbar() pl.xlabel('$z$') pl.ylabel('Mpc') pl.subplot(122) pl.plot(z, dT_mean) pl.xlabel('Redshift') pl.ylabel('Mean brightness temperature')