code: def test_signal_extraction_with_maps_and_labels(
      labeled_regions, fmri_img, shape_3d_default
  ):
      labels = list(range(N_REGIONS + 1))
      labels_data = get_data(labeled_regions)
      # Convert to maps
      maps_data = np.zeros(shape_3d_default + (N_REGIONS,))
      for n, l in enumerate(labels):
          if n == 0:
              continue
          maps_data[labels_data == l, n - 1] = 1
  
      maps_img = Nifti1Image(maps_data, labeled_regions.affine)
  
      # Extract signals from maps and labels: results must be identical.
      maps_signals, maps_labels = img_to_signals_maps(
          fmri_img, maps_img
      )
      labels_signals, labels_labels = img_to_signals_labels(
          imgs=fmri_img, labels_img=labeled_regions
      )
      assert_almost_equal(maps_signals, labels_signals)
  
      # Same thing with a mask, containing only 3 regions.
      mask_img = _create_mask_with_3_regions_from_labels_data(
          labels_data, labeled_regions.affine
      )
      labels_signals, labels_labels = img_to_signals_labels(
          imgs=fmri_img, labels_img=labeled_regions, mask_img=mask_img
      )
      maps_signals, maps_labels = img_to_signals_maps(
          fmri_img, maps_img, mask_img=mask_img
      )
  
      assert_almost_equal(maps_signals, labels_signals)
      assert maps_signals.shape[1] == N_REGIONS
      assert maps_labels == list(range(len(maps_labels)))
      assert labels_signals.shape == (N_TIMEPOINTS, N_REGIONS)
      assert labels_labels == labels[1:]
  
      # Inverse operation (mostly smoke test)
      labels_img_r = signals_to_img_labels(
          labels_signals, labeled_regions, mask_img=mask_img
      )
      assert labels_img_r.shape == shape_3d_default + (N_TIMEPOINTS,)
  
      maps_img_r = signals_to_img_maps(
          maps_signals, maps_img, mask_img=mask_img
      )
      assert maps_img_r.shape == shape_3d_default + (N_TIMEPOINTS,)
  
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 28 for calling a global function with example usage: test_signal_extraction_with_maps_and_labels(labeled_regions, fmri_img, shape_3d_default) without return types