コード例 #1
0
ファイル: test_profile.py プロジェクト: mireianievas/gammapy
def test_serialisation(tmpdir):
    dataset = get_simple_dataset_on_off()
    geom = dataset.counts.geom
    regions = make_concentric_annulus_sky_regions(
        center=geom.center_skydir,
        radius_max=0.2 * u.deg,
    )

    est = FluxProfileEstimator(regions, energy_edges=[0.1, 10] * u.TeV)
    result = est.run(dataset)

    result.write(tmpdir / "profile.fits", format="profile")

    profile = FluxPoints.read(
        tmpdir / "profile.fits",
        format="profile",
        reference_model=PowerLawSpectralModel(),
    )

    assert_allclose(result.norm, profile.norm, rtol=1e-4)
    assert_allclose(result.norm_err, profile.norm_err, rtol=1e-4)
    assert_allclose(result.npred, profile.npred)
    assert_allclose(result.ts, profile.ts)

    assert np.all(result.is_ul == profile.is_ul)
コード例 #2
0
ファイル: test_profile.py プロジェクト: mireianievas/gammapy
def test_radial_profile():
    dataset = get_simple_dataset_on_off()
    geom = dataset.counts.geom
    regions = make_concentric_annulus_sky_regions(
        center=geom.center_skydir,
        radius_max=0.2 * u.deg,
    )

    prof_maker = FluxProfileEstimator(
        regions,
        energy_edges=[0.1, 1, 10] * u.TeV,
        selection_optional="all",
        n_sigma_ul=3,
    )
    result = prof_maker.run(dataset)

    imp_prof = result.to_table(sed_type="flux", format="profile")

    assert_allclose(imp_prof[7]["x_min"], 0.14, atol=1e-4)
    assert_allclose(imp_prof[7]["x_ref"], 0.15, atol=1e-4)
    assert_allclose(imp_prof[7]["counts"], [[980.0], [980.0]], atol=1e-2)
    assert_allclose(imp_prof[7]["sqrt_ts"], [23.886444, 23.886444], atol=1e-5)
    assert_allclose(imp_prof[0]["flux"], [8e-06, 8.0e-06], atol=1e-3)

    # TODO: npred quantities are not supported by the table serialisation format
    #  so we rely on the FluxPoints object
    npred_excess = result.npred_excess.data[7].squeeze()
    assert_allclose(npred_excess, [784.0, 784.0], rtol=1e-3)

    errn = result.npred_excess_errn.data[7].squeeze()
    assert_allclose(errn, [34.075, 34.075], rtol=2e-3)

    ul = result.npred_excess_ul.data[0].squeeze()
    assert_allclose(ul, [72.074, 72.074], rtol=1e-3)
コード例 #3
0
ファイル: test_profile.py プロジェクト: mireianievas/gammapy
def test_radial_profile_one_interval():
    dataset = get_simple_dataset_on_off()
    geom = dataset.counts.geom
    regions = make_concentric_annulus_sky_regions(
        center=geom.center_skydir,
        radius_max=0.2 * u.deg,
    )

    prof_maker = FluxProfileEstimator(
        regions,
        selection_optional="all",
        energy_edges=[0.1, 10] * u.TeV,
        n_sigma_ul=3,
        sum_over_energy_groups=True,
    )
    result = prof_maker.run(dataset)

    imp_prof = result.to_table(sed_type="flux", format="profile")

    assert_allclose(imp_prof[7]["counts"], [[1960]], atol=1e-5)
    assert_allclose(imp_prof[7]["npred_excess"], [[1568.0]], rtol=1e-3)
    assert_allclose(imp_prof[7]["sqrt_ts"], [33.780533], rtol=1e-3)
    assert_allclose(imp_prof[0]["flux"], [16e-06], atol=1e-3)

    axis = result.counts.geom.axes["dataset"]
    assert axis.center == ["test-on-off"]

    errn = result.npred_excess_errn.data[7].squeeze()
    assert_allclose(errn, [48.278367], rtol=2e-3)

    ul = result.npred_excess_ul.data[0].squeeze()
    assert_allclose(ul, [130.394824], rtol=1e-3)
コード例 #4
0
def test_radial_profile_one_interval():
    dataset = get_simple_dataset_on_off()
    geom = dataset.counts.geom
    regions = make_concentric_annulus_sky_regions(
        center=geom.center_skydir,
        radius_max=0.2 * u.deg,
    )

    prof_maker = ExcessProfileEstimator(regions, selection_optional="all")
    imp_prof = prof_maker.run(dataset)

    assert_allclose(imp_prof[7]["counts"], [1960], atol=1e-5)
    assert_allclose(imp_prof[7]["excess"], [1568.0], atol=1e-5)
    assert_allclose(imp_prof[7]["sqrt_ts"], [33.780533], atol=1e-5)
    assert_allclose(imp_prof[7]["errn"], [-48.278367], atol=1e-5)
    assert_allclose(imp_prof[0]["ul"], [134.285969], atol=1e-5)
    assert_allclose(imp_prof[0]["flux"], [16e-06], atol=1e-3)
    assert_allclose(imp_prof[0]["solid_angle"], [6.853891e-07], atol=1e-5)
コード例 #5
0
def test_radial_profile():
    dataset = get_simple_dataset_on_off()
    geom = dataset.counts.geom
    regions = make_concentric_annulus_sky_regions(
        center=geom.center_skydir,
        radius_max=0.2 * u.deg,
    )

    prof_maker = ExcessProfileEstimator(regions)
    imp_prof = prof_maker.run(dataset)

    assert_allclose(imp_prof[7]["x_min"], 0.14, atol=1e-4)
    assert_allclose(imp_prof[7]["x_ref"], 0.15, atol=1e-4)
    assert_allclose(imp_prof[7]["counts"], [980.0, 980.0], atol=1e-2)
    assert_allclose(imp_prof[7]["excess"], [784.0, 784.0], atol=1e-2)
    assert_allclose(imp_prof[7]["sqrt_ts"], [23.886444, 23.886444], atol=1e-5)
    assert_allclose(imp_prof[7]["errn"], [-34.075141, -34.075141], atol=1e-5)
    assert_allclose(imp_prof[0]["ul"], [75.834983, 75.834983], atol=1e-5)
    assert_allclose(imp_prof[0]["flux"], [7.99999987e-06, 8.00000010e-06], atol=1e-3)
    assert_allclose(imp_prof[0]["solid_angle"], [6.853891e-07, 6.853891e-07], atol=1e-5)