Beispiel #1
0
def test_asmooth_dataset(input_dataset):
    kernel = Tophat2DKernel
    scales = ASmoothMapEstimator.get_scales(3, factor=2,
                                            kernel=kernel) * 0.1 * u.deg

    asmooth = ASmoothMapEstimator(scales=scales,
                                  kernel=kernel,
                                  method="lima",
                                  threshold=2.5)

    # First check that is fails if don't use to_image()
    with pytest.raises(ValueError):
        asmooth.run(input_dataset)

    smoothed = asmooth.run(input_dataset.to_image())

    assert smoothed["flux"].data.shape == (40, 50)
    assert smoothed["flux"].unit == u.Unit("cm-2s-1")
    assert smoothed["counts"].unit == u.Unit("")
    assert smoothed["background"].unit == u.Unit("")
    assert smoothed["scale"].unit == u.Unit("deg")

    desired = {
        "counts": 369.479167,
        "background": 0.13461,
        "scale": 0.056419,
        "significance": 74.677406,
        "flux": 1.237284e-09,
    }

    for name in smoothed:
        actual = smoothed[name].data[20, 25]
        assert_allclose(actual, desired[name], rtol=1e-5)
Beispiel #2
0
def test_asmooth_map_dataset_on_off():
    kernel = Tophat2DKernel
    scales = ASmoothMapEstimator.get_scales(3, factor=2,
                                            kernel=kernel) * 0.1 * u.deg

    asmooth = ASmoothMapEstimator(kernel=kernel,
                                  scales=scales,
                                  method="lima",
                                  threshold=2.5)

    counts = WcsNDMap.create(npix=(50, 50), binsz=0.02, unit="")
    counts += 2
    counts_off = WcsNDMap.create(npix=(50, 50), binsz=0.02, unit="")
    counts_off += 3

    acceptance = WcsNDMap.create(npix=(50, 50), binsz=0.02, unit="")
    acceptance += 1

    acceptance_off = WcsNDMap.create(npix=(50, 50), binsz=0.02, unit="")
    acceptance_off += 3

    dataset = MapDatasetOnOff(
        counts=counts,
        counts_off=counts_off,
        acceptance=acceptance,
        acceptance_off=acceptance_off,
    )

    smoothed = asmooth.run(dataset)
    assert_allclose(smoothed["counts"].data[25, 25], 2)
    assert_allclose(smoothed["background"].data[25, 25], 1)
    assert_allclose(smoothed["significance"].data[25, 25], 4.391334)
Beispiel #3
0
def test_asmooth_dataset(input_dataset):
    kernel = Tophat2DKernel
    scales = ASmoothMapEstimator.get_scales(3, factor=2,
                                            kernel=kernel) * 0.1 * u.deg

    asmooth = ASmoothMapEstimator(scales=scales,
                                  kernel=kernel,
                                  method="lima",
                                  threshold=2.5)

    smoothed = asmooth.run(input_dataset)

    assert smoothed["flux"].data.shape == (1, 40, 50)
    assert smoothed["flux"].unit == u.Unit("cm-2s-1")
    assert smoothed["counts"].unit == u.Unit("")
    assert smoothed["background"].unit == u.Unit("")
    assert smoothed["scale"].unit == u.Unit("deg")

    desired = {
        "counts": 369.479167,
        "background": 0.184005,
        "scale": 0.056419,
        "sqrt_ts": 72.971513,
        "flux": 1.237119e-09,
    }

    for name in smoothed:
        actual = smoothed[name].data[0, 20, 25]
        assert_allclose(actual, desired[name], rtol=1e-2)
def run_asmooth(dataset):
    scales = u.Quantity(np.arange(0.05, 1, 0.05), unit="deg")
    smooth = ASmoothMapEstimator(threshold=3,
                                 scales=scales,
                                 energy_edges=[10, 300] * u.GeV)
    images = smooth.run(dataset)
    return images
Beispiel #5
0
def test_asmooth_map_dataset_on_off():
    kernel = Tophat2DKernel
    scales = ASmoothMapEstimator.get_scales(3, factor=2,
                                            kernel=kernel) * 0.1 * u.deg

    asmooth = ASmoothMapEstimator(kernel=kernel,
                                  scales=scales,
                                  method="lima",
                                  threshold=2.5)

    axis = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=1)

    counts = WcsNDMap.create(npix=(50, 50), binsz=0.02, unit="", axes=[axis])
    counts += 2
    counts_off = WcsNDMap.create(npix=(50, 50),
                                 binsz=0.02,
                                 unit="",
                                 axes=[axis])
    counts_off += 3

    acceptance = WcsNDMap.create(npix=(50, 50),
                                 binsz=0.02,
                                 unit="",
                                 axes=[axis])
    acceptance += 1

    acceptance_off = WcsNDMap.create(npix=(50, 50),
                                     binsz=0.02,
                                     unit="",
                                     axes=[axis])
    acceptance_off += 3

    dataset = MapDatasetOnOff(
        counts=counts,
        counts_off=counts_off,
        acceptance=acceptance,
        acceptance_off=acceptance_off,
    )

    smoothed = asmooth.run(dataset)
    assert_allclose(smoothed["counts"].data[25, 25], 2)
    assert_allclose(smoothed["background"].data[25, 25], 1.25)
    assert_allclose(smoothed["significance"].data[25, 25],
                    3.079799117645,
                    rtol=1e-2)