def test_EffectiveAreaTable(tmp_path, aeff): arf = aeff.to_effective_area_table(offset=0.3 * u.deg) assert_quantity_allclose(arf.data.evaluate(), arf.data.data) with mpl_plot_check(): arf.plot() arf.write(tmp_path / "tmp.fits") arf2 = EffectiveAreaTable.read(tmp_path / "tmp.fits") assert_quantity_allclose(arf.data.evaluate(), arf2.data.evaluate()) test_aeff = 0.6 * arf.max_area node_above = np.where(arf.data.data > test_aeff)[0][0] energy = arf.data.axes["energy_true"] ener_above = energy.center[node_above] ener_below = energy.center[node_above - 1] test_ener = arf.find_energy(test_aeff) assert ener_below < test_ener and test_ener < ener_above elo_threshold = arf.find_energy(0.1 * arf.max_area) assert elo_threshold.unit == "TeV" assert_allclose(elo_threshold.value, 0.554086, rtol=1e-3) ehi_threshold = arf.find_energy(0.9 * arf.max_area, emin=30 * u.TeV, emax=100 * u.TeV) assert ehi_threshold.unit == "TeV" assert_allclose(ehi_threshold.value, 53.347217, rtol=1e-3) # Test evaluation outside safe range data = [np.nan, np.nan, 0, 0, 1, 2, 3, np.nan, np.nan] energy_axis_true = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=9, name="energy_true") aeff = EffectiveAreaTable(data=data, energy_axis_true=energy_axis_true) vals = aeff.evaluate_fill_nan() assert vals[1] == 0 assert vals[-1] == 3
def test_EffectiveAreaTable(tmpdir, aeff): arf = aeff.to_effective_area_table(offset=0.3 * u.deg) assert_quantity_allclose(arf.data.evaluate(), arf.data.data) with mpl_plot_check(): arf.plot() filename = str(tmpdir / "effarea_test.fits") arf.write(filename) arf2 = EffectiveAreaTable.read(filename) assert_quantity_allclose(arf.data.evaluate(), arf2.data.evaluate()) test_aeff = 0.6 * arf.max_area node_above = np.where(arf.data.data > test_aeff)[0][0] energy = arf.data.axis("energy") ener_above = energy.center[node_above] ener_below = energy.center[node_above - 1] test_ener = arf.find_energy(test_aeff) assert ener_below < test_ener and test_ener < ener_above elo_threshold = arf.find_energy(0.1 * arf.max_area) assert elo_threshold.unit == "TeV" assert_allclose(elo_threshold.value, 0.554086, rtol=1e-3) ehi_threshold = arf.find_energy(0.9 * arf.max_area, emin=30 * u.TeV, emax=100 * u.TeV) assert ehi_threshold.unit == "TeV" assert_allclose(ehi_threshold.value, 53.347217, rtol=1e-3) # Test evaluation outside safe range data = [np.nan, np.nan, 0, 0, 1, 2, 3, np.nan, np.nan] energy = np.logspace(0, 10, 10) * u.TeV aeff = EffectiveAreaTable(data=data, energy_lo=energy[:-1], energy_hi=energy[1:]) vals = aeff.evaluate_fill_nan() assert vals[1] == 0 assert vals[-1] == 3