Add test for iter_by_axis
@@ -546,3 +546,21 @@ def test_iter_by_image():
for m in m_4d.iter_by_image(keepdims=False):
assert m.data.ndim == 2
assert m.geom.axes.names == []
+
+
+def test_iter_by_axis():
+ 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_axis(axis_name="energy", keepdims=False):
+ assert m.data.ndim == 3
+ assert m.geom.axes.names == ["time"]
