code: def test_4d_single_scan(rng):
      """Test that list of 4D images with last dim=1 is treated as 3D."""
      shape_3d = (10, 10, 10)
      shape_4d = shape_3d + (1,)
      mask = np.zeros(shape_3d)
      mask[3:7, 3:7, 3:7] = 1
      mask_img = nibabel.Nifti1Image(mask, np.eye(4))
  
      data_5d = [rng.random(shape_4d) for _ in range(5)]
      data_4d = [d[..., 0] for d in data_5d]
      data_5d = [nibabel.Nifti1Image(d, np.eye(4)) for d in data_5d]
      data_4d = [nibabel.Nifti1Image(d, np.eye(4)) for d in data_4d]
  
      masker = NiftiMasker(mask_img=mask_img)
  
      # Check attributes defined at fit
      assert not hasattr(masker, "mask_img_")
      assert not hasattr(masker, "n_elements_")
  
      masker.fit()
  
      # Check attributes defined at fit
      assert hasattr(masker, "mask_img_")
      assert hasattr(masker, "n_elements_")
      assert masker.n_elements_ == np.sum(mask)
  
      data_trans_5d = masker.transform(data_5d)
      data_trans_4d = masker.transform(data_4d)
  
      assert_array_equal(data_trans_4d, data_trans_5d)
  
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 12 for calling a global function with example usage: test_4d_single_scan(rng) without return types