Add iter_by_image test
@@ -509,6 +509,8 @@ def test_resample_wcs_wcs():
np.sum(map1*geom1.solid_angle()),
rtol=1e-3
)
+
+
def test_resample_wcs_hpx():
geom1 = HpxGeom.create(nside=32, frame="icrs")
map1 = Map.from_geom(geom1, data=1.)
@@ -523,3 +525,24 @@ def test_resample_wcs_hpx():
rtol=1e-3
)
+
+def test_iter_by_image():
+ time_axis = MapAxis.from_bounds(
+ 0, 3, nbin=3, unit="hour", name="time", interp="lin"
+ )
+
+ energy_axis = MapAxis.from_bounds(
+ 1, 100, nbin=4, unit="TeV", name="energy", interp="log"
+ )
+
+ m_4d = Map.create(
+ binsz=0.2, width=(1, 1), frame="galactic", axes=[energy_axis, time_axis]
+ )
+
+ for m in m_4d.iter_by_image(keepdims=True):
+ assert m.data.ndim == 4
+ assert m.geom.axes.names == ["energy", "time"]
+
+ for m in m_4d.iter_by_image(keepdims=False):
+ assert m.data.ndim == 2
+ assert m.geom.axes.names == []
