示例#1
0
def test_ring_bkg_maker(geom, observations, exclusion_mask):
    ring_bkg_maker = RingBackgroundMaker(r_in="0.2 deg",
                                         width="0.3 deg",
                                         exclusion_mask=exclusion_mask)
    safe_mask_maker = SafeMaskMaker(methods=["offset-max"], offset_max="2 deg")
    map_dataset_maker = MapDatasetMaker(offset_max="2 deg")

    reference = MapDataset.create(geom)
    datasets = []

    for obs in observations:
        dataset = map_dataset_maker.run(reference, obs)
        dataset = safe_mask_maker.run(dataset, obs)
        dataset = dataset.to_image()

        dataset_on_off = ring_bkg_maker.run(dataset)
        datasets.append(dataset_on_off)

    mask = dataset.mask_safe
    assert_allclose(datasets[0].counts_off.data[mask].sum(), 2511333)
    assert_allclose(datasets[1].counts_off.data[mask].sum(), 2143577.0)
    assert_allclose(datasets[0].acceptance_off.data[mask].sum(), 2961300)
    assert_allclose(datasets[1].acceptance_off.data[mask].sum(), 2364657.2)
    assert_allclose(datasets[0].alpha.data[0][100][100], 0.00063745599)
    assert_allclose(datasets[0].exposure.data[0][100][100], 806254444.8480084)
示例#2
0
def test_map_maker_ring(observations):
    geomd = geom(ebounds=[0.1, 10])
    map_dataset_maker = MapDatasetMaker(offset_max="2 deg")
    safe_mask_maker = SafeMaskMaker(methods=["offset-max"], offset_max="2 deg")

    stacked = MapDatasetOnOff.create(geomd)

    regions = CircleSkyRegion(SkyCoord(0, 0, unit="deg", frame="galactic"),
                              radius=0.5 * u.deg)
    exclusion = Map.from_geom(geomd)
    exclusion.data = exclusion.geom.region_mask([regions], inside=False)

    ring_bkg = RingBackgroundMaker(r_in="0.5 deg",
                                   width="0.4 deg",
                                   exclusion_mask=exclusion)

    for obs in observations:
        dataset = map_dataset_maker.run(stacked, obs)
        dataset = safe_mask_maker.run(dataset, obs)

        dataset = dataset.to_image()

        dataset_on_off = ring_bkg.run(dataset)
        stacked.stack(dataset_on_off)

    assert_allclose(np.nansum(stacked.counts.data), 34366, rtol=1e-2)
    assert_allclose(np.nansum(stacked.acceptance_off.data), 434.36, rtol=1e-2)
示例#3
0
def test_ring_bkg_maker(map_dataset_maker, observations, exclusion_mask):
    ring_bkg_maker = RingBackgroundMaker(r_in="0.2 deg",
                                         width="0.3 deg",
                                         exclusion_mask=exclusion_mask)
    datasets = []

    for obs in observations:
        dataset = map_dataset_maker.run(obs)
        dataset = dataset.to_image()

        dataset_on_off = ring_bkg_maker.run(dataset)
        datasets.append(dataset_on_off)

    mask = dataset.mask_safe
    assert_allclose(datasets[0].counts_off.data[mask].sum(), 2511333)
    assert_allclose(datasets[1].counts_off.data[mask].sum(), 2143577.0)
    assert_allclose(datasets[0].acceptance_off.data[mask].sum(), 2961300)
    assert_allclose(datasets[1].acceptance_off.data[mask].sum(), 2364657.2)
    assert_allclose(datasets[0].alpha.data[0][100][100], 0.00063745599)
    assert_allclose(datasets[0].exposure.data[0][100][100], 806254444.8480084)
示例#4
0
# No we repeat the same analysis but using a classical ring background estimation. We define an exclusion mask and then use the `~gammapy.cube.RingBackgroundMaker`.

# In[ ]:

geom_image = geom.to_image().to_cube([energy_axis.squash()])

regions = CircleSkyRegion(center=spatial_model.position, radius=0.3 * u.deg)

exclusion_mask = Map.from_geom(geom_image)
exclusion_mask.data = geom_image.region_mask([regions], inside=False)
exclusion_mask.sum_over_axes().plot()

# In[ ]:

ring_maker = RingBackgroundMaker(r_in="0.3 deg",
                                 width="0.3 deg",
                                 exclusion_mask=exclusion_mask)

# In[ ]:

get_ipython().run_cell_magic(
    'time', '',
    'stacked_on_off = MapDatasetOnOff.create(geom=geom_image)\n\nfor dataset in datasets:\n    dataset_image = dataset.to_image()\n    dataset_on_off = ring_maker.run(dataset_image)\n    stacked_on_off.stack(dataset_on_off)'
)

# Based on the estimate of the ring background we compute a Li&Ma significance image:

# In[ ]:

scale = geom.pixel_scales[0].to("deg")
# Using a convolution radius of 0.05 degrees