code: def test_trim_maps(shape_3d_default):
      # maps
      maps_data = np.zeros(
          shape_3d_default + (N_REGIONS,), dtype=np.float32
      )
      h0, h1, h2 = (s // 2 for s in shape_3d_default)
      maps_data[:h0, :h1, :h2, 0] = 1
      maps_data[:h0, :h1, h2:, 1] = 1.1
      maps_data[:h0, h1:, :h2, 2] = 1
      maps_data[:h0, h1:, h2:, 3] = 0.5
      maps_data[h0:, :h1, :h2, 4] = 1
      maps_data[h0:, :h1, h2:, 5] = 1.4
      maps_data[h0:, h1:, :h2, 6] = 1
      maps_data[h0:, h1:, h2:, 7] = 1
  
      # mask intersecting all regions
      mask_data = np.zeros(shape_3d_default, dtype=np.int8)
      mask_data[1:-1, 1:-1, 1:-1] = 1
  
      maps_i, maps_i_mask, maps_i_indices = _trim_maps(
          maps_data, mask_data
      )
  
      assert maps_i.flags["F_CONTIGUOUS"]
      assert len(maps_i_indices) == maps_i.shape[-1]
      assert maps_i.shape == maps_data.shape
      maps_i_correct = maps_data.copy()
      maps_i_correct[np.logical_not(mask_data), :] = 0
      assert_almost_equal(maps_i_correct, maps_i)
      assert_equal(mask_data, maps_i_mask)
      assert_equal(np.asarray(list(range(8))), maps_i_indices)
  
      # mask intersecting half of the regions
      mask_data = np.zeros(shape_3d_default, dtype=np.int8)
      mask_data[1:2, 1:-1, 1:-1] = 1
      maps_data[1, 1, 1, 0] = 0  # remove one point inside mask
  
      maps_i, maps_i_mask, maps_i_indices = _trim_maps(
          maps_data, mask_data
      )
  
      assert maps_i.flags["F_CONTIGUOUS"]
      assert len(maps_i_indices) == maps_i.shape[-1]
      assert maps_i.shape == (maps_data.shape[:3] + (4,))
      maps_i_correct = maps_data[..., :4].copy()
      maps_i_correct[np.logical_not(mask_data), :] = 0
      assert_almost_equal(maps_i_correct, maps_i)
      mask_data[1, 1, 1] = 0  # for test to succeed
      assert_equal(mask_data, maps_i_mask)
      mask_data[1, 1, 1] = 1  # reset, just in case.
      assert_equal(np.asarray(list(range(4))), maps_i_indices)
  
imports: import warnings
  import numpy
  import pytest
  from nibabel import Nifti1Image
  from numpy.testing import assert_almost_equal, assert_equal
  from nilearn._utils.data_gen import generate_fake_fmri, generate_labeled_regions, generate_maps, generate_timeseries
  from nilearn._utils.exceptions import DimensionError
  from nilearn._utils.testing import write_imgs_to_path
  from nilearn.conftest import _affine_eye, _shape_3d_default
  from nilearn.image import get_data, new_img_like
  from nilearn.maskers import NiftiLabelsMasker
  from nilearn.regions.signal_extraction import _check_shape_and_affine_compatibility, _trim_maps, img_to_signals_labels, img_to_signals_maps, signals_to_img_labels, signals_to_img_maps
label_desc: Use image node_id 32 for calling a global function with example usage: test_trim_maps(shape_3d_default) without return types