Exemple #1
0
def test_coeval_callback_exceptions(ic, redshift, max_redshift, perturb_field):
    # should output warning in logs and not raise an error
    lc, coeval_output = wrapper.run_lightcone(
        init_box=ic,
        perturb=perturb_field,
        max_redshift=max_redshift,
        coeval_callback=lambda x: 1
        / Heaviside(x.redshift - (redshift + max_redshift) / 2),
        coeval_callback_redshifts=[max_redshift, redshift],
    )
    # should raise an error
    with pytest.raises(RuntimeError) as excinfo:
        lc, coeval_output = wrapper.run_lightcone(
            init_box=ic,
            perturb=perturb_field,
            max_redshift=max_redshift,
            coeval_callback=lambda x: 1 / 0,
            coeval_callback_redshifts=[max_redshift, redshift],
        )
    assert "coeval_callback computation failed on first trial" in str(excinfo.value)
Exemple #2
0
def test_lightcone_quantities(ic, max_redshift, perturb_field):
    lc = wrapper.run_lightcone(
        init_box=ic,
        perturb=perturb_field,
        max_redshift=max_redshift,
        lightcone_quantities=("dNrec_box", "density", "brightness_temp"),
        global_quantities=("density", "Gamma12_box"),
    )

    assert hasattr(lc, "dNrec_box")
    assert hasattr(lc, "density")
    assert hasattr(lc, "global_density")
    assert hasattr(lc, "global_Gamma12")

    # dNrec is not filled because we're not doing INHOMO_RECO
    assert lc.dNrec_box.max() == lc.dNrec_box.min() == 0

    # density should be filled with not zeros.
    assert lc.density.min() != lc.density.max() != 0

    # Simply ensure that different quantities are not getting crossed/referred to each other.
    assert lc.density.min() != lc.brightness_temp.min(
    ) != lc.brightness_temp.max()

    # Raise an error since we're not doing spin temp.
    with pytest.raises(ValueError):
        wrapper.run_lightcone(
            init_box=ic,
            perturb=perturb_field,
            max_redshift=20.0,
            lightcone_quantities=("Ts_box", "density"),
        )

    # And also raise an error for global quantities.
    with pytest.raises(ValueError):
        wrapper.run_lightcone(
            init_box=ic,
            perturb=perturb_field,
            max_redshift=20.0,
            global_quantities=("Ts_box", ),
        )
Exemple #3
0
def test_coeval_callback(ic, max_redshift, perturb_field):
    lc, coeval_output = wrapper.run_lightcone(
        init_box=ic,
        perturb=perturb_field,
        max_redshift=max_redshift,
        lightcone_quantities=("brightness_temp", ),
        global_quantities=("brightness_temp", ),
        coeval_callback=_global_Tb,
    )
    assert isinstance(lc, wrapper.LightCone)
    assert isinstance(coeval_output, list)
    assert len(lc.node_redshifts) == len(coeval_output)
    assert np.allclose(lc.global_brightness_temp,
                       np.array(coeval_output, dtype=np.float32))
Exemple #4
0
def test_coeval_callback_redshifts(ic, redshift, max_redshift, perturb_field):
    coeval_callback_redshifts = np.array(
        [max_redshift, max_redshift, (redshift + max_redshift) / 2, redshift],
        dtype=np.float32,
    )
    lc, coeval_output = wrapper.run_lightcone(
        init_box=ic,
        perturb=perturb_field,
        max_redshift=max_redshift,
        coeval_callback=lambda x: x.redshift,
        coeval_callback_redshifts=coeval_callback_redshifts,
    )
    assert len(coeval_callback_redshifts) - 1 == len(coeval_output)
    computed_redshifts = [
        lc.node_redshifts[np.argmin(np.abs(i - lc.node_redshifts))]
        for i in coeval_callback_redshifts[1:]
    ]
    assert np.allclose(coeval_output, computed_redshifts)