code: def _write_bids_derivative_func(
      func_path,
      fields,
      n_voxels,
      rand_gen,
      confounds_tag,
  ):
      """Create BIDS functional derivative and confounds files.
  
      Nifti files created come with two spaces and descriptions.
      Spaces are: 'MNI' and 'T1w'.
      Descriptions are: 'preproc' and :term:`fMRIPrep`.
      Only space 'T1w' include both descriptions.
  
      Gifti files are in "fsaverage5" space for both hemispheres.
  
      Parameters
      ----------
      func_path : :obj:`Path`
          Path to a subject functional directory.
  
      file_id : :obj:`str`
          Root of the BIDS filename:
          typically basename without the BIDS suffix and extension.
  
      n_voxels : :obj:`int`
          Number of voxels along a given axis in the functional image.
  
      rand_gen : :obj:`numpy.random.RandomState` instance
          Random number generator.
  
      confounds_tag : :obj:`str`, optional.
          Filename "suffix":
          For example: `desc-confounds_timeseries`
          or "desc-confounds_regressors".
  
      """
      n_time_points = 30
  
      if confounds_tag is not None:
          fields["suffix"] = confounds_tag
          fields["extension"] = "tsv"
          confounds_path = func_path / create_bids_filename(
              fields=fields, entities_to_include=bids_entities()["raw"]
          )
          confounds, metadata = get_legal_confound()
          confounds.to_csv(
              confounds_path, sep="\t", index=None, encoding="utf-8"
          )
          with open(confounds_path.with_suffix(".json"), "w") as f:
              json.dump(metadata, f)
  
      fields["suffix"] = "bold"
      fields["extension"] = "nii.gz"
  
      shape = [n_voxels, n_voxels, n_voxels, n_time_points]
  
      entities_to_include = [
          *bids_entities()["raw"],
          *bids_entities()["derivatives"],
      ]
  
      for space in ("MNI", "T1w"):
          for desc in ("preproc", "fmriprep"):
              # Only space 'T1w' include both descriptions.
              if space == "MNI" and desc == "fmriprep":
                  continue
  
              fields["entities"]["space"] = space
              fields["entities"]["desc"] = desc
  
              bold_path = func_path / create_bids_filename(
                  fields=fields, entities_to_include=entities_to_include
              )
              write_fake_bold_img(
                  bold_path, shape=shape, random_state=rand_gen
              )
  
      fields["entities"]["space"] = "fsaverage5"
      fields["extension"] = "func.gii"
      fields["entities"].pop("desc")
      for hemi in ["L", "R"]:
          fields["entities"]["hemi"] = hemi
          gifti_path = func_path / create_bids_filename(
              fields=fields, entities_to_include=entities_to_include
          )
          _write_fake_bold_gifti(gifti_path)
  
imports: from __future__ import annotations
  import itertools
  import json
  import string
  from pathlib import Path
  import numpy
  import pandas
  import scipy.linalg
  import scipy.signal
  from nibabel import Nifti1Image
  from scipy.ndimage import binary_dilation
  from nilearn import datasets, image, maskers, masking
  from nilearn._utils import as_ndarray, logger
  from nilearn.interfaces.bids.utils import bids_entities, check_bids_label, create_bids_filename
  from nilearn.interfaces.fmriprep.tests._testing import get_legal_confound
label_desc: Use image node_id 25 for calling a global function with example usage: _write_bids_derivative_func(func_path, fields, n_voxels, rand_gen, confounds_tag) without return types