def test_source_prob(tmpdir_with_config, config, z, fluxes, ew_obs, flim_file, addl_fluxes, addl_names, e_prob_lae):
    """
    Test source probability
    """

    # Folder with config files
    os.chdir(tmpdir_with_config)

    if type(addl_names) != type(None):

        # Get errors on additional emission lines from flux limit file
        flims = read_flim_file(flim_file)
        errors = []
        for x in addl_names:
            zoii = (1.0 + z)*config.getfloat("wavelengths","LAE")/config.getfloat("wavelengths", "OII") - 1.0
            lambda_ = config.getfloat("wavelengths", x)*(1.0 + zoii)
            errors.append(0.2*flims(lambda_/config.getfloat("wavelengths","LAE") - 1.0))
        errors = array(errors)

        prob_lae_given_data = source_prob(config, [100.0], [0.0], [z], array([fluxes]), array([0.0]), [ew_obs], [0.0], None, None, 
                                          array(addl_fluxes), errors, array(addl_names), flim_file, ignore_noise = True)
    else:
        prob_lae_given_data = source_prob(config, [100.0], [0.0], [z], array([fluxes]), array([0.0]), [ew_obs], [0.0], None, None, None, None, None,
                                          flim_file, ignore_noise = True)


    if e_prob_lae > 0.0:
        assert abs(e_prob_lae - prob_lae_given_data) < 0.05*e_prob_lae
    else:
        assert prob_lae_given_data < 1e-40
def test_n_additional_line(config, flim_file, name, line_fluxes, addl_fluxes, zoiis, epx_oii, epx_lae):

    flims = read_flim_file(flim_file)
    wavelength = config.getfloat("wavelengths", name)*(1.0 + zoiis) 
    errors = array(0.2*flims(wavelength/config.getfloat("wavelengths", "LAE") - 1.0)) 

    n_lines_lae, n_lines_oii = n_additional_line(line_fluxes, array([0.0]), addl_fluxes, errors, 
                                                 config.getfloat("RelativeLineStrengths", name))

    assert n_lines_oii == pytest.approx(epx_oii, rel=0.001)
    assert n_lines_lae == pytest.approx(epx_lae, rel=0.001)
Example #3
0
def test_prob_additional_line(config, name, line_fluxes, addl_fluxes, zoiis,
                              flim_file, epx_oii, epx_lae):

    flims = read_flim_file(flim_file)
    wavelength = config.getfloat("wavelengths", name) * (1.0 + zoiis)
    errors = array(
        0.2 * flims(wavelength / config.getfloat("wavelengths", "LAE") - 1.0))

    plae, poii = prob_additional_line(
        name, line_fluxes, array([0.0]), addl_fluxes, errors,
        config.getfloat("RelativeLineStrengths", name))

    assert plae[0] == pytest.approx(epx_lae, rel=1e-2, abs=0.0)
    assert poii[0] == pytest.approx(epx_oii, rel=1e-2, abs=0.0)
Example #4
0
def test_source_prob(config, z, fluxes, ew_obs, flim_file, addl_fluxes,
                     addl_names, e_ratio, e_prob_lae):
    """
    Test source probability
    """

    if type(addl_names) != type(None):

        # Get errors on additional emission lines from flux limit file
        flims = read_flim_file(flim_file)
        errors = []
        for x in addl_names:
            zoii = (1.0 + z) * config.getfloat("wavelengths",
                                               "LAE") / config.getfloat(
                                                   "wavelengths", "OII") - 1.0
            lambda_ = config.getfloat("wavelengths", x) * (1.0 + zoii)
            errors.append(
                0.2 *
                flims(lambda_ / config.getfloat("wavelengths", "LAE") - 1.0))
        errors = array(errors)

        posterior_odds, prob_lae_given_data = source_prob(
            config, [100.0], [0.0], [z], array([fluxes]), array([0.0]),
            [ew_obs], [0.0], None, None, array(addl_fluxes), errors,
            array(addl_names), flim_file)
    else:
        posterior_odds, prob_lae_given_data = source_prob(
            config, [100.0], [0.0], [z], array([fluxes]), array([0.0]),
            [ew_obs], [0.0], None, None, None, None, None, flim_file)

    if e_prob_lae > 0.0:
        assert abs(e_prob_lae - prob_lae_given_data) < 0.05 * e_prob_lae
    else:
        assert prob_lae_given_data < 1e-40

    if e_ratio > 1e-40:
        assert abs(e_ratio - posterior_odds) < 0.1 * e_ratio
    else:
        assert posterior_odds < 1e-40
Example #5
0
    def __init__(self, lf, flim_file, flux_errors=None):

        self.lf = lf
        self.flims = read_flim_file(flim_file)
        self.flux_errors = flux_errors