Пример #1
0
def test_safe_mask_maker(observations, caplog):
    obs = observations[0]

    axis = MapAxis.from_bounds(0.1,
                               10,
                               nbin=16,
                               unit="TeV",
                               name="energy",
                               interp="log")
    axis_true = MapAxis.from_bounds(0.1,
                                    50,
                                    nbin=30,
                                    unit="TeV",
                                    name="energy_true",
                                    interp="log")
    geom = WcsGeom.create(npix=(11, 11),
                          axes=[axis],
                          skydir=obs.pointing_radec)

    empty_dataset = MapDataset.create(geom=geom, energy_axis_true=axis_true)
    dataset_maker = MapDatasetMaker()
    safe_mask_maker = SafeMaskMaker(offset_max="3 deg",
                                    bias_percent=0.02,
                                    position=obs.pointing_radec)

    fixed_offset = 1.5 * u.deg
    safe_mask_maker_offset = SafeMaskMaker(offset_max="3 deg",
                                           bias_percent=0.02,
                                           fixed_offset=fixed_offset)

    dataset = dataset_maker.run(empty_dataset, obs)

    mask_offset = safe_mask_maker.make_mask_offset_max(dataset=dataset,
                                                       observation=obs)
    assert_allclose(mask_offset.sum(), 109)

    mask_energy_aeff_default = safe_mask_maker.make_mask_energy_aeff_default(
        dataset=dataset, observation=obs)
    assert_allclose(mask_energy_aeff_default.data.sum(), 1936)

    mask_aeff_max = safe_mask_maker.make_mask_energy_aeff_max(dataset)
    mask_aeff_max_offset = safe_mask_maker_offset.make_mask_energy_aeff_max(
        dataset, obs)
    assert_allclose(mask_aeff_max.data.sum(), 1210)
    assert_allclose(mask_aeff_max_offset.data.sum(), 1210)

    mask_edisp_bias = safe_mask_maker.make_mask_energy_edisp_bias(dataset)
    mask_edisp_bias_offset = safe_mask_maker_offset.make_mask_energy_edisp_bias(
        dataset, obs)
    assert_allclose(mask_edisp_bias.data.sum(), 1815)
    assert_allclose(mask_edisp_bias_offset.data.sum(), 121)

    mask_bkg_peak = safe_mask_maker.make_mask_energy_bkg_peak(dataset)
    assert_allclose(mask_bkg_peak.data.sum(), 1815)
    assert caplog.records[-1].levelname == "WARNING"
    assert caplog.records[
        -1].message == "No default thresholds defined for obs 110380"
Пример #2
0
def test_safe_mask_maker_dl3(spectrum_dataset_crab, observations_hess_dl3):

    safe_mask_maker = SafeMaskMaker()
    maker = SpectrumDatasetMaker()

    obs = observations_hess_dl3[0]
    dataset = maker.run(spectrum_dataset_crab, obs)
    dataset = safe_mask_maker.run(dataset, obs)
    assert_allclose(dataset.energy_range[0].value, 1)
    assert dataset.energy_range[0].unit == "TeV"

    mask_safe = safe_mask_maker.make_mask_energy_aeff_max(dataset)
    assert mask_safe.data.sum() == 4

    mask_safe = safe_mask_maker.make_mask_energy_edisp_bias(dataset)
    assert mask_safe.data.sum() == 3

    mask_safe = safe_mask_maker.make_mask_energy_bkg_peak(dataset)
    assert mask_safe.data.sum() == 3
Пример #3
0
def test_safe_mask_maker(observations):
    obs = observations[0]

    axis = MapAxis.from_bounds(0.1,
                               10,
                               nbin=16,
                               unit="TeV",
                               name="energy",
                               interp="log")
    axis_true = MapAxis.from_bounds(0.1,
                                    50,
                                    nbin=30,
                                    unit="TeV",
                                    name="energy_true",
                                    interp="log")
    geom = WcsGeom.create(npix=(11, 11),
                          axes=[axis],
                          skydir=obs.pointing_radec)

    empty_dataset = MapDataset.create(geom=geom, energy_axis_true=axis_true)
    dataset_maker = MapDatasetMaker()
    safe_mask_maker = SafeMaskMaker(offset_max="3 deg",
                                    bias_percent=0.02,
                                    position=obs.pointing_radec)

    dataset = dataset_maker.run(empty_dataset, obs)

    mask_offset = safe_mask_maker.make_mask_offset_max(dataset=dataset,
                                                       observation=obs)
    assert_allclose(mask_offset.sum(), 109)

    mask_energy_aeff_default = safe_mask_maker.make_mask_energy_aeff_default(
        dataset=dataset, observation=obs)
    assert_allclose(mask_energy_aeff_default.data.sum(), 1936)

    mask_aeff_max = safe_mask_maker.make_mask_energy_aeff_max(dataset)
    assert_allclose(mask_aeff_max.data.sum(), 1210)

    mask_edisp_bias = safe_mask_maker.make_mask_energy_edisp_bias(dataset)
    assert_allclose(mask_edisp_bias.data.sum(), 1815)

    mask_bkg_peak = safe_mask_maker.make_mask_energy_bkg_peak(dataset)
    assert_allclose(mask_bkg_peak.data.sum(), 1815)