code: def test_transformation():
      """Test transforming images."""
      N = 10
      v2w_mapping = Transform(
          "voxels", "world1", mapping, inverse_mapping
      )
      identity = Transform("world1", "world2", id, id)
      data = np.random.random((N, N, N))
      img1 = VolumeGrid(
          data=data,
          transform=v2w_mapping,
      )
      img2 = img1.composed_with_transform(identity)
  
      assert img2.world_space == "world2"
  
      x, y, z = N * np.random.random(size=(3, 10))
      np.testing.assert_almost_equal(
          img1.values_in_world(x, y, z), img2.values_in_world(x, y, z)
      )
  
      pytest.raises(
          CompositionError,
          img1.composed_with_transform,
          identity.get_inverse(),
      )
  
      pytest.raises(CompositionError, img1.resampled_to_img, img2)
  
      # Resample an image on itself: it shouldn't change much:
      img = img1.resampled_to_img(img1)
      np.testing.assert_almost_equal(data, img.get_fdata())
  
      # Check that if I 'resampled_to_img' on an VolumeImg, I get an
      # VolumeImg, and vice versa
      volume_image = VolumeImg(data, np.eye(4), "world")
      identity = Transform("voxels", "world", id, id)
      image = VolumeGrid(data, identity)
      image2 = image.resampled_to_img(volume_image)
      assert isinstance(image2, VolumeImg)
      volume_image2 = volume_image.resampled_to_img(image)
      assert isinstance(image2, VolumeGrid)
      # Check that the data are all the same: we have been playing only
      # with identity mappings
      np.testing.assert_array_equal(
          volume_image2.get_fdata(), image2.get_fdata()
      )
  
file_path: nipy/nipy/labs/datasets/volumes/tests/test_volume_grid.py
imports: import copy
  import numpy
  import pytest
  from ...transforms.transform import CompositionError, Transform
  from ..volume_grid import VolumeGrid
  from ..volume_img import VolumeImg
label_desc: Use image node_id 7 for calling a global function with example usage: test_transformation() without return types