Beispiel #1
0
def test_rad_max_roundtrip(tmp_path):
    n_energy = 10
    energy_axis = MapAxis.from_energy_bounds(50 * u.GeV,
                                             100 * u.TeV,
                                             n_energy,
                                             name="energy")

    n_offset = 5
    offset_axis = MapAxis.from_bounds(0,
                                      2,
                                      n_offset,
                                      unit=u.deg,
                                      name="offset")

    shape = (n_energy, n_offset)
    rad_max = np.linspace(0.1, 0.5, n_energy * n_offset).reshape(shape)

    rad_max_2d = RadMax2D(
        axes=[
            energy_axis,
            offset_axis,
        ],
        data=rad_max,
        unit=u.deg,
    )

    rad_max_2d.write(tmp_path / "rad_max.fits")
    rad_max_read = RadMax2D.read(tmp_path / "rad_max.fits")

    assert np.all(rad_max_read.data == rad_max)
    assert np.all(rad_max_read.data == rad_max_read.data)
Beispiel #2
0
def test_rad_max_single_bin():
    energy_axis = MapAxis.from_energy_bounds(0.01, 100, 1, unit="TeV")
    offset_axis = MapAxis.from_bounds(
        0.,
        5,
        1,
        unit="deg",
        name="offset",
    )

    rad_max = RadMax2D(data=[[0.1]] * u.deg,
                       axes=[energy_axis, offset_axis],
                       interp_kwargs={
                           "method": "nearest",
                           "fill_value": None
                       })

    value = rad_max.evaluate(energy=1 * u.TeV, offset=1 * u.deg)
    assert_allclose(value, 0.1 * u.deg)

    value = rad_max.evaluate(energy=[1, 2, 3] * u.TeV, offset=[[1]] * u.deg)
    assert value.shape == (1, 3)
    assert_allclose(value, 0.1 * u.deg)