code: def test_signals_extraction_with_labels_with_mask(
      signals,
      labels_img,
      labels_data,
      mask_img,
      shape_3d_default,
      tmp_path,
  ):
      """Test conversion between signals and images \
      using regions defined by labels with a mask."""
      data_img = signals_to_img_labels(
          signals=signals, labels_img=labels_img, mask_img=mask_img
      )
  
      assert data_img.shape == (shape_3d_default + (N_TIMEPOINTS,))
      # There must be non-zero data (safety net)
      data = get_data(data_img)
      assert abs(data).max() > 1e-9
  
      # Zero outside of the mask
      assert np.all(
          data[np.logical_not(get_data(mask_img))].std(axis=-1) < EPS
      )
  
      filenames = write_imgs_to_path(
          labels_img, mask_img, file_path=tmp_path
      )
      data_img = signals_to_img_labels(
          signals=signals,
          labels_img=filenames[0],
          mask_img=filenames[1],
      )
  
      assert data_img.shape == (shape_3d_default + (N_TIMEPOINTS,))
      data = get_data(data_img)
      assert abs(data).max() > 1e-9
      # Zero outside of the mask
      assert np.all(
          data[np.logical_not(get_data(mask_img))].std(axis=-1) < EPS
      )
  
      # mask labels before checking
      masked_labels_data = labels_data.copy()
      masked_labels_data[np.logical_not(get_data(mask_img))] = 0
      _all_voxel_of_each_region_have_same_values(
          data, masked_labels_data, N_REGIONS, signals
      )
  
      # and back
      signals_r, labels_r = img_to_signals_labels(
          imgs=data_img, labels_img=labels_img, mask_img=mask_img
      )
  
      assert_almost_equal(signals_r, signals)
      assert labels_r == list(range(1, 9))
  
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 25 for calling a global function with example usage: test_signals_extraction_with_labels_with_mask(signals, labels_img, labels_data, mask_img, shape_3d_default, tmp_path) without return types