示例#1
0
def produce_perturb_field_data(redshift, **kwargs):
    options = get_all_options(redshift, **kwargs)
    options_ics = get_all_options_ics(**kwargs)

    out = {
        key: kwargs[key]
        for key in kwargs
        if key.upper() in (k.upper() for k in global_params.keys())
    }

    velocity_normalisation = 1e16

    with config.use(regenerate=True, write=False):
        init_box = initial_conditions(**options_ics)
        pt_box = perturb_field(redshift=redshift, init_boxes=init_box, **out)

    p_dens, k_dens = get_power(
        pt_box.density,
        boxlength=options["user_params"]["BOX_LEN"],
    )
    p_vel, k_vel = get_power(
        pt_box.velocity * velocity_normalisation,
        boxlength=options["user_params"]["BOX_LEN"],
    )

    def hist(kind, xmin, xmax, nbins):
        data = getattr(pt_box, kind)
        if kind == "velocity":
            data = velocity_normalisation * data

        bins, edges = np.histogram(
            data,
            bins=np.linspace(xmin, xmax, nbins),
            range=[xmin, xmax],
            density=True,
        )

        left, right = edges[:-1], edges[1:]

        X = np.array([left, right]).T.flatten()
        Y = np.array([bins, bins]).T.flatten()
        return X, Y

    X_dens, Y_dens = hist("density", -0.8, 2.0, 50)
    X_vel, Y_vel = hist("velocity", -2, 2, 50)

    return k_dens, p_dens, k_vel, p_vel, X_dens, Y_dens, X_vel, Y_vel, init_box
示例#2
0
def test_first_box(default_user_params):
    """Tests whether the first_box idea works for spin_temp.
    This test was breaking before we set the z_heat_max box to actually get
    the correct dimensions (before it was treated as a dummy).
    """
    initial_conditions = p21c.initial_conditions(
        user_params=default_user_params.clone(
            HII_DIM=default_user_params.HII_DIM + 1),
        random_seed=1,
    )

    perturbed_field = p21c.perturb_field(redshift=29.0,
                                         init_boxes=initial_conditions)

    spin_temp = p21c.spin_temperature(perturbed_field=perturbed_field,
                                      z_heat_max=30.0)

    assert spin_temp.redshift == 29.0
示例#3
0
zeta = 39.204  #65.204
Rmfp = 12.861  #11.861
Tvir = 4.539  #4.539

params = {'HII_DIM': 128, 'DIM': 384, 'BOX_LEN': 256}
my_ext = [0, params['BOX_LEN'], 0, params['BOX_LEN']]
c_params = {'OMm': 0.27, 'OMb': 0.046, 'SIGMA_8': 0.82, 'POWER_INDEX': 0.96}
a_params = {'HII_EFF_FACTOR': zeta, 'R_BUBBLE_MAX': Rmfp, 'ION_Tvir_MIN': Tvir}

# late, middle and early stage of reionization
bins = np.array([[0.18, 0.22], [0.48, 0.52], [0.78, 0.82]])
compare_tobs_mean = np.zeros((bins.shape[0], tobs.size))
compare_tobs_std = np.zeros((bins.shape[0], tobs.size))

ic = p21c.initial_conditions(user_params=params,
                             cosmo_params=c_params,
                             random_seed=2021)
compare_tobs = np.zeros((redshift.size, tobs.size))

for i in tqdm(range(len(redshift))):
    z = redshift[i]

    cube = p21c.run_coeval(redshift=z,
                           init_box=ic,
                           astro_params=a_params,
                           zprime_step_factor=1.05)

    dT = cube.brightness_temp
    xH = cube.xH_box

    uv = uvs['%.3f' % z]
示例#4
0
    eff_fact = random.gauss(52.5, 20.)  # eff_fact = [5, 100]
    Rmfp = random.gauss(12.5, 5.)       # Rmfp = [5, 20]
    Tvir = random.gauss(4.65, 0.5)      # Tvir = [log10(1e4), log10(2e5)]
    
    # Define astronomical parameters
    a_params = {'HII_EFF_FACTOR':eff_fact, 'R_BUBBLE_MAX':Rmfp, 'ION_Tvir_MIN':Tvir}

    # Create 21cmFast cube
    if(i%1 == 0):
        try:
            os.system('rm %s*h5' %path_chache)
        except:
            pass
        comm.Barrier()
        
        ic = p21.initial_conditions(user_params=params, cosmo_params=c_params, random_seed=GenerateSeed())

    cube = p21.run_coeval(redshift=z, init_box=ic, astro_params=a_params, zprime_step_factor=1.05)

    # Mean neutral fraction
    xn = np.mean(cube.xH_box)

    if(xn > 0.1 and xn <= 0.8):
        print('processor: %d/%d   idx=%d\n z=%.3f, xn=%.3f, eff_fact=%.3f, Rmfp=%.3f, Tvir=%.3f' %(rank, nprocs, i, z, xn, eff_fact, Rmfp, Tvir))

        """
        dT = cube.brightness_temp
        dT1 = t2c.subtract_mean_signal(signal=dT, los_axis=2)
        
        # calculate uv-coverage 
        file_uv, file_Nant = 'uv_coverage_%d/uvmap_z%.3f.npy' %(params['HII_DIM'], z), 'uv_coverage_%d/Nantmap_z%.3f.npy' %(params['HII_DIM'], z)
示例#5
0
            "===================== Begin Trace (TOTAL MEM={:1.4e} MB... [{:+1.4e} MB]):"
            .format(thismem, diff))
        top_stats = snapshot2.compare_to(snapshot, "lineno", cumulative=True)
        for stat in top_stats[:4]:
            print(stat)
        print("End Trace ===========================================")
        oldmem = thismem

    snapshot = snapshot2


NITER = 50

init = initial_conditions(user_params={
    "HII_DIM": 50,
    "BOX_LEN": 125.0
},
                          regenerate=True)
perturb = (
    perturb_field(redshift=7, init_boxes=init),
    perturb_field(redshift=8, init_boxes=init),
    perturb_field(redshift=9, init_boxes=init),
)

astro_params = {"HII_EFF_FACTOR": np.random.normal(30, 0.1)}

for i in range(NITER):
    trace_print()

    coeval = run_coeval(
        redshift=[7, 8, 9],
示例#6
0
        ALPHA_ESC=-0.5,
        ALPHA_STAR=0.5,
        F_ESC10=-1.30102999566,
        F_STAR10=-1.0,
        L_X=40.5,
        M_TURN=8.7,
        NU_X_THRESH=500.0,
        X_RAY_SPEC_INDEX=1.0,
        t_STAR=0.5,
        R_BUBBLE_MAX=15.0,
    )

    init_box = initial_conditions(
        user_params=user_params,
        cosmo_params=cosmo_params,
        random_seed=random_seed,
        regenerate=True,
        write=False,
    )

    redshift = 9.0

    pt_box = perturb_field(
        redshift=redshift,
        init_boxes=init_box,
        user_params=user_params,
        cosmo_params=cosmo_params,
    )

    halos = determine_halo_list(
        redshift=redshift,