code: def test_mask_4d():
      """Test performance with 4D data."""
      # Dummy mask
      mask = np.zeros((10, 10, 10), dtype="int32")
      mask[3:7, 3:7, 3:7] = 1
      mask_bool = mask.astype(bool)
      mask_img = nibabel.Nifti1Image(mask, np.eye(4))
  
      # Dummy data
      data = np.zeros((10, 10, 10, 5), dtype="int32")
      data[..., 0] = 1
      data[..., 1] = 2
      data[..., 2] = 3
      data_img_4d = nibabel.Nifti1Image(data, np.eye(4))
      data_imgs = [
          index_img(data_img_4d, 0),
          index_img(data_img_4d, 1),
          index_img(data_img_4d, 2),
      ]
  
      # check whether transform is indeed selecting niimgs subset
      sample_mask = np.array([0, 2])
      masker = NiftiMasker(mask_img=mask_img)
      masker.fit()
      data_trans = masker.transform(data_imgs, sample_mask=sample_mask)
      data_trans_img = index_img(data_img_4d, sample_mask)
      data_trans_direct = get_data(data_trans_img)[mask_bool, :]
      data_trans_direct = np.swapaxes(data_trans_direct, 0, 1)
      assert_array_equal(data_trans, data_trans_direct)
  
      masker = NiftiMasker(mask_img=mask_img)
      masker.fit()
      data_trans2 = masker.transform(
          data_img_4d, sample_mask=sample_mask
      )
      assert_array_equal(data_trans2, data_trans_direct)
  
      diff_sample_mask = np.array([2, 4])
      data_trans_img_diff = index_img(data_img_4d, diff_sample_mask)
      data_trans_direct_diff = get_data(data_trans_img_diff)[
          mask_bool, :
      ]
      data_trans_direct_diff = np.swapaxes(data_trans_direct_diff, 0, 1)
      masker = NiftiMasker(mask_img=mask_img)
      masker.fit()
      data_trans3 = masker.transform(
          data_img_4d, sample_mask=diff_sample_mask
      )
      assert_array_equal(data_trans3, data_trans_direct_diff)
  
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 11 for calling a global function with example usage: test_mask_4d() without return types