code: def test_nifti_masker_io_shapes(rng):
      """Ensure that NiftiMasker handles 1D/2D/3D/4D data appropriately.
  
      transform(4D image) --> 2D output, no warning
      transform(3D image) --> 2D output, DeprecationWarning
      inverse_transform(2D array) --> 4D image, no warning
      inverse_transform(1D array) --> 3D image, no warning
      inverse_transform(2D array with wrong shape) --> ValueError
      """
      n_volumes = 5
      shape_3d = (10, 11, 12)
      shape_4d = (10, 11, 12, n_volumes)
      affine = np.eye(4)
  
      img_4d, mask_img = data_gen.generate_random_img(
          shape_4d,
          affine=affine,
      )
      img_3d, _ = data_gen.generate_random_img(shape_3d, affine=affine)
      n_regions = np.sum(mask_img.get_fdata().astype(bool))
      data_1d = rng.random(n_regions)
      data_2d = rng.random((n_volumes, n_regions))
  
      masker = NiftiMasker(mask_img)
      masker.fit()
  
      # DeprecationWarning *should* be raised for 3D inputs
      with pytest.warns(
          DeprecationWarning, match="Starting in version 0.12"
      ):
          test_data = masker.transform(img_3d)
          assert test_data.shape == (1, n_regions)
  
      # DeprecationWarning should *not* be raised for 4D inputs
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "error",
              message="Starting in version 0.12",
              category=DeprecationWarning,
          )
          test_data = masker.transform(img_4d)
          assert test_data.shape == (n_volumes, n_regions)
  
      # DeprecationWarning should *not* be raised for 1D inputs
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "error",
              message="Starting in version 0.12",
              category=DeprecationWarning,
          )
          test_img = masker.inverse_transform(data_1d)
          assert test_img.shape == shape_3d
  
      # DeprecationWarning should *not* be raised for 2D inputs
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "error",
              message="Starting in version 0.12",
              category=DeprecationWarning,
          )
          test_img = masker.inverse_transform(data_2d)
          assert test_img.shape == shape_4d
  
      with pytest.raises(TypeError):
          masker.inverse_transform(data_2d.T)
  
imports: import os
  import shutil
  import warnings
  from tempfile import mkdtemp
  import nibabel
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from nilearn._utils import data_gen, exceptions, testing
  from nilearn._utils.class_inspect import get_params
  from nilearn.image import get_data, index_img
  from nilearn.maskers import NiftiMasker
  from nilearn.maskers.nifti_masker import _filter_and_mask
label_desc: Use image node_id 25 for calling a global function with example usage: test_nifti_masker_io_shapes(rng) without return types