code: def create_simulation_data(
      snr=0, n_samples=2 * 100, size=12, random_state=1
  ):
      generator = check_random_state(random_state)
      roi_size = 2  # size / 3
      smooth_X = 1
      # Coefs
      w = np.zeros((size, size, size))
      w[0:roi_size, 0:roi_size, 0:roi_size] = -0.6
      w[-roi_size:, -roi_size:, 0:roi_size] = 0.5
      w[0:roi_size, -roi_size:, -roi_size:] = -0.6
      w[-roi_size:, 0:roi_size:, -roi_size:] = 0.5
      w[
          (size - roi_size) // 2 : (size + roi_size) // 2,
          (size - roi_size) // 2 : (size + roi_size) // 2,
          (size - roi_size) // 2 : (size + roi_size) // 2,
      ] = 0.5
      w = w.ravel()
      # Generate smooth background noise
      XX = generator.randn(n_samples, size, size, size)
      noise = []
      for i in range(n_samples):
          Xi = gaussian_filter(XX[i, :, :, :], smooth_X)
          Xi = Xi.ravel()
          noise.append(Xi)
      noise = np.array(noise)
      # Generate the signal y
      y = generator.randn(n_samples)
      X = np.dot(y[:, np.newaxis], w[np.newaxis])
      norm_noise = linalg.norm(X, 2) / np.exp(snr / 20.0)
      noise_coef = norm_noise / linalg.norm(noise, 2)
      noise *= noise_coef
      snr = 20 * np.log(linalg.norm(X, 2) / linalg.norm(noise, 2))
      print(f"SNR: {snr:.1f} dB")
      # Mixing of signal + noise and splitting into train/test
      X += noise
      X -= X.mean(axis=-1)[:, np.newaxis]
      X /= X.std(axis=-1)[:, np.newaxis]
      X_test = X[n_samples // 2 :, :]
      X_train = X[: n_samples // 2, :]
      y_test = y[n_samples // 2 :]
      y = y[: n_samples // 2]
  
      return X_train, X_test, y, y_test, snr, w, size
  
file_path: nilearn/examples/02_decoding/plot_simulated_data.py
imports: from time import time
  import matplotlib.pyplot
  import nibabel
  import numpy
  from scipy import linalg
  from scipy.ndimage import gaussian_filter
  from sklearn import linear_model, svm
  from sklearn.feature_selection import f_regression
  from sklearn.model_selection import KFold
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils import check_random_state
  import nilearn.masking
  from nilearn import decoding
  from nilearn.plotting import show
label_desc: Use image node_id 1 for calling a global function with example usage: create_simulation_data(snr, n_samples, size, random_state) and returns: X_train,  X_test,  y,  y_test,  snr,  w,  size