示例#1
0
def test_load_irf_dict_from_file():
    """Test that the IRF components in a dictionary loaded from a DL3 file can
    be loaded in a dictionary and correctly used"""
    irf = load_irf_dict_from_file(
        "$GAMMAPY_DATA/hess-dl3-dr1/data/hess_dl3_dr1_obs_id_020136.fits.gz")

    energy = Quantity(1, "TeV")
    offset = Quantity(0.5, "deg")

    val = irf["aeff"].evaluate(energy_true=energy, offset=offset)
    assert_allclose(val.value, 273372.44851054, rtol=1e-5)
    assert val.unit == "m2"

    val = irf["edisp"].evaluate(offset=offset, energy_true=energy, migra=1)
    assert_allclose(val.value, 1.84269482, rtol=1e-5)
    assert val.unit == ""

    val = irf["psf"].evaluate(rad=Quantity(0.1, "deg"),
                              energy_true=energy,
                              offset=offset)
    assert_allclose(val, 6.75981573 * u.Unit("deg-2"), rtol=1e-5)

    val = irf["bkg"].evaluate(energy=energy, fov_lon=offset, fov_lat="0.1 deg")
    assert_allclose(val.value, 0.00031552, rtol=1e-5)
    assert val.unit == "1 / (MeV s sr)"
示例#2
0
def test_irf_dict_from_file_duplicate_irfs(caplog, tmp_path):
    """catch the warning message about two type of IRF with the same hdu class
    encountered in the same file"""
    original_file = make_path(
        "$GAMMAPY_DATA/hess-dl3-dr1/data/hess_dl3_dr1_obs_id_020136.fits.gz")
    dummy_file = tmp_path / "020136_duplicated_psf.fits"

    # create a dummy file with the PSF HDU repeated twice
    f = fits.open(original_file)
    f.append(f[5].copy())
    f[7].name = "PSF2"
    f.writeto(dummy_file)

    load_irf_dict_from_file(dummy_file)

    assert "more than one HDU" in caplog.text
    assert "loaded the PSF HDU in the dictionary" in caplog.text
示例#3
0
def test_irf_dict_from_file_fixed_rad_max():
    """test that for point-like IRF without RAD_MAX_2D HDU a RadMax2D with a
    single value is generated from the RAD_MAX header keyword"""
    irf = load_irf_dict_from_file(
        "$GAMMAPY_DATA/joint-crab/dl3/magic/run_05029748_DL3.fits")

    assert "RAD_MAX" in irf["aeff"].meta
    assert "rad_max" in irf
    assert isinstance(irf["rad_max"], RadMax2D)

    # check that has a single-bin in energy and offset
    assert irf["rad_max"].axes["energy"].nbin == 1
    assert irf["rad_max"].axes["offset"].nbin == 1
    assert irf["rad_max"].quantity.to_value(
        "deg") == irf["aeff"].meta["RAD_MAX"]