code: def test_reduce():
      shape = (3, 5, 7, 9)
      x = np.random.standard_normal(shape)
      im = Image(x, AT(CS("ijkq"), MNI4, np.diag([3, 4, 5, 6, 1])))
      newim = image_reduce(im, lambda x: x.sum(0), "q")
      assert_array_equal(xyz_affine(im), xyz_affine(newim))
      assert newim.axes.coord_names == tuple("ijk")
      assert newim.shape == (3, 5, 7)
      assert_almost_equal(newim.get_fdata(), x.sum(3))
      im_nd = Image(
          x,
          AT(
              CS("ijkq"),
              MNI4,
              np.array(
                  [
                      [0, 1, 2, 0, 10],
                      [3, 4, 5, 0, 11],
                      [6, 7, 8, 0, 12],
                      [0, 0, 0, 9, 13],
                      [0, 0, 0, 0, 1],
                  ]
              ),
          ),
      )
      for i, o, n in zip("ijk", MNI3.coord_names, range(3)):
          for axis_id in (i, o, n):
              # Non-diagonal reduce raise an error
              pytest.raises(
                  AxisError,
                  image_reduce,
                  im_nd,
                  lambda x: x.sum(0),
                  axis_id,
              )
              # Diagonal reduces are OK
              newim = image_reduce(im, lambda x: x.sum(0), axis_id)
  
file_path: nipy/nipy/core/image/tests/test_rollimg.py
imports: import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_equal
  from ...image.image_spaces import xyz_affine
  from ...reference.coordinate_map import AffineTransform
  from ...reference.coordinate_map import AxisError, drop_io_dim
  from ...reference.coordinate_system import CoordinateSystem
  from ...reference.spaces import mni_csm
  from ..image import Image, rollimg, synchronized_order
label_desc: Use image node_id 5 for calling a global function with example usage: test_reduce() without return types