code: def image_modify(img, modify, axis="y+PA"):
      """
      Take an Image, perform some operation on it, over a specified axis, and
      return a new Image.
  
      For this operation, we are allowed to iterate over spatial axes.
  
      For the sake of testing things out, we will assume that the operation modify
      can only operate by iterating over the first axis of an array.
  
      Parameters
      ----------
      img : Image
      modify : callable
          An operation that modifies an array.  Something like::
  
              def f(x):
                  x[:] = x.mean()
  
      axis : str or int
          Specification of axis of Image
  
      Returns
      -------
      newim : Image
          with a modified copy of img._data.
      """
      rolled_img = rollimg(img, axis)
      data = rolled_img.get_fdata().copy()
      for d in data:
          modify(d)
      import copy
  
      new_image = Image(data, copy.copy(rolled_img.coordmap))
      # Now, we have to put the data back to same order as img
      return synchronized_order(new_image, img)
  
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 4 for calling a global function with example usage: image_modify(img, modify, axis) and returns: synchronized_order