Beispiel #1
0
def minkowski_python(z, i, noise_array, data_filename):

    # create local dictionary object
    local_data_dict = {}

    # the data we want to analyse, a 3D array of floats. Comment/uncomment depending on format
    #input_array = c2t.read_cbin('/media/gorgel/My Passport 3/simon_master/dT_' + str(z) + '.cbin')                   #cbin format

    input_array = c2t.XfracFile(
        '/media/gorgel/My Passport 3/simon_master/xfrac3d_' + str(z) +
        '.bin')  # bin format
    input_array = input_array.xi

    #select options by comment/uncomment
    #save_image(input_array, z, 'raw', data_filename)

    print 'running minkowski program for' + ' z = ' + str(z)

    #input_array = add_gaussian_noise(input_array, noise_array)      #add noise
    #input_array = z_correction(input_array, z)                              #remove z.dependence
    #save_image(input_array, z, 'noise', data_filename)
    #input_array = smoothing_function(input_array, sigma=4)                   #smooth data
    #save_image(input_array, z, 'smth', data_filename)
    #input_array = remove_edge(input_array, 10, 10, 10)
    #save_image(input_array, z, 'edge', data_filename)
    #input_array = subtract_mean(input_array)
    #input_array = complement(input_array)                                   #calculate on complementary field
    #save_image(input_array, z, 'compl', data_filename)

    #minkowski settings
    size_array = len(input_array)
    box_dimensions = np.array(
        [size_array, size_array, size_array]
    )  # the size of the data we want to analyse, a 1D array of three integers (same as the -x -y -z options)
    nr_bins = int(65)  # integer: number of bins to use (same as -b option)
    low = float(0)  # float: lowest value of threshold (same as -l option)
    high = float(1)  # float: highest values of threshold (same as -h option)
    output_array = np.zeros(
        (2, nr_bins + 1, 5), dtype=np.float32
    )  #output array, (koenderink+crofton, number of bins +1, 5 = th,V0,V1,V2,V3)

    #start minkowski program
    print "starting minkowski calculation"
    mink(input_array, box_dimensions, nr_bins, high, low, output_array)

    # collect and order output data in dictionary object
    local_data_dict.update({z : {'thresholds': output_array[0][:,4], 'CV0': output_array[0][:,0], 'CV1': output_array[0][:,1], \
                         'CV2': output_array[0][:,2] , 'CV3': output_array[0][:,3], \
                      'KV0': output_array[1][:,0], 'KV1': output_array[1][:,1], \
                         'KV2': output_array[1][:,2] , 'KV3': output_array[1][:,3], \
                      'ion_frac_vol' : ion_frac_vol[i], 'ion_frac_mass' :ion_frac_mass[i],\
                      'neutral_frac_vol' : neutral_frac_vol[i], 'neutral_frac_mass' : neutral_frac_mass[i]}})

    return local_data_dict
Beispiel #2
0
#Enable the printing of various messages
c2t.set_verbose(True)

#We are using the 114/h Mpc simulation box, so set all the proper conversion factors
c2t.set_sim_constants(boxsize_cMpc=114.)

#Read a density file and print some statistics
dfile = c2t.DensityFile(density_filename)

print 'The redshift is ', dfile.z
print 'The size of the mesh is (', dfile.mesh_x, dfile.mesh_y, dfile.mesh_z, ')'
print 'The mean baryon density is ', dfile.cgs_density.mean(), ' g/cm^3'

#Read an ionized fractions file
xfile = c2t.XfracFile(xfrac_filename)

print 'The volume-averaged mean ionized fraction is: ', xfile.xi.mean()
print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi(
    xfile.xi, dfile.raw_density)

#Read a velocity data file
vfile = c2t.VelocityFile(velocity_filename)

#Since the velocity data is actually momentum, we need the density to convert it to km/s
kms = vfile.get_kms_from_density(dfile)
print 'Gas velocity at cell (100,100,100) is ', kms[:, 100, 100, 100], 'km/s'

#Calculate neutral hydrogen number density
n_hi = dfile.cgs_density * xfile.xi / c2t.m_p
Beispiel #3
0
    :param a: float amplitude
    :param sigma: float s.d.
    :param array_size: size of array to output
    :return: 3d array as detailed above
    """
    ar = np.zeros(array_size, dtype=float)
    for i in range(array_size[0]):
        for j in range(array_size[1]):
            for k in range(array_size[2]):
                dx = float(
                    reduce(lambda foo, y: foo + y**2,
                           [0, i - x[0], j - x[1], k - x[2]]))
                ar[i, j, k] = a * gaussian(dx, sigma)
    return ar


if __name__ == "__main__":
    import sys
    import c2raytools as c2t
    try:
        infile = sys.arg[1]
        outfile = sys.argv[2]
        x_file = c2t.XfracFile(infile)
        ret, sizes = friend_of_friend_search(x_file.xi, 0.5)
        with open(outfile, 'w') as out_file:
            out_file.write(str(sizes))
    except IndexError as e:
        print(
            "Error: expected an input ionised fraction file and an output file"
        )
Beispiel #4
0
        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 c2raytools as c2t
    import pylab as pl
    
    c2t.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 = c2t.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(c2t.XfracFile(xfilename))
    pl.show()
    
    
    
    
Beispiel #5
0
dens_dir    = '/disk/dawn-1/garrelt/Reionization/C2Ray_WMAP7/500Mpc/coarser_densities/nc600/'
ph_count_info = owntools.photoncount_info(xfrac_dir)

Ncuts = 3

xvs_ = 10**np.linspace(np.log10(3.44e-10),np.log10(0.20),10)
#xvs  = ph_count_info[[np.abs(ph_count_info[:,-2]-x).argmin() for x in xvs_],-2]
zs_  = ph_count_info[[np.abs(ph_count_info[:,-2]-x).argmin() for x in xvs_], 0]

dens_zs = owntools.get_zs_list(dens_dir, file_type='/*n_all.dat')
zs   = dens_zs[[np.abs(dens_zs-i).argmin() for i in zs_]]
xvs  = ph_count_info[[np.abs(ph_count_info[:,0]-i).argmin() for i in zs],-2]

z = 9.026 #8.636

gg_xf = c2t.XfracFile(grizzly_dir+str(z)+'xhiifrac.dat').xi
#cc_xf = owntools.coeval_xfrac(xfrac_dir, z)

cube_d  = owntools.coeval_dens(dens_dir, z)
cube_21 = c2t.calc_dt(gg_xf, cube_d, z); cube_21 -= cube_21.mean()
cube_m  = cube_d/cube_d.mean(dtype=np.float64) - 1. #owntools.coeval_overdens(dens_dir, z)

P_dd, ks_m = c2t.power_spectrum_1d(cube_m, kbins=100, box_dims=c2t.conv.LB)
P_21, ks_x = c2t.power_spectrum_1d(cube_21, kbins=100, box_dims=c2t.conv.LB)

f_dd, k_dd  = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_m, cube_m, Ncuts=Ncuts)
f_21d, k_xd = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_21, cube_m, Ncuts=Ncuts)
f_xx, k_xx  = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_x-cube_x.mean(), cube_x-cube_x.mean(), Ncuts=Ncuts)
f_x_ = squeezed_bispectrum._integrated_bispectrum_normalized_cross1(1-cube_x, cube_m, Ncuts=Ncuts)

ks = k_dd.copy()