code: def _generate_ROIs(
      ROI_file, stimfunc, noise, scale_percentage, data_dict
  ):
      """Make signal activity for an ROI of data
          Creates the specified evoked response time course, calibrated to the
          expected signal change, for a given ROI
  
      Parameters
      ----------
  
      ROI_file : str
          Path to the file of the ROI being loaded in
  
      stimfunc : 1 dimensional array
          Time course of evoked response. Output from
          fmrisim.generate_stimfunction
  
      noise : 4 dimensional array
          Volume of noise generated from fmrisim.generate_noise. Although this
          is needed as an input, this is only so that the percent signal change
          can be calibrated. This is not combined with the signal generated.
  
      scale_percentage : float
          What is the percent signal change for the evoked response
  
      data_dict : dict
          A dictionary to specify the parameters used for making data,
          specifying the following keys
          numTRs - int - Specify the number of time points
          multivariate_patterns - bool - Is the difference between conditions
          univariate (0) or multivariate (1)
          different_ROIs - bool - Are there different ROIs for each condition (
          1) or is it in the same ROI (0). If it is the same ROI and you are
          using univariate differences, the second condition will have a
          smaller evoked response than the other.
          event_duration - int - How long, in seconds, is each event
          scale_percentage - float - What is the percent signal change
          trDuration - float - How many seconds per volume
          save_dicom - bool - Save to data as a dicom (1) or numpy (0)
          save_realtime - bool - Do you want to save the data in real time (1)
          or as fast as possible (0)?
          isi - float - What is the time between each event (in seconds)
          burn_in - int - How long before the first event (in seconds)
  
      Returns
      ----------
  
      signal : 4 dimensional array
      Volume of signal in the specified ROI (noise has not yet been added)
  
      """
  
      # Create the signal in the ROI as specified.
  
      # Load in the template data (it may already be loaded if doing a test)
      if isinstance(ROI_file, str):
          logger.info("Loading", ROI_file)
          nii = nibabel.load(ROI_file)
          ROI = nii.get_fdata()
      else:
          ROI = ROI_file
  
      # Find all the indices that contain signal
      idx_list = np.where(ROI == 1)
  
      idxs = np.zeros([len(idx_list[0]), 3])
      for idx_counter in list(range(0, len(idx_list[0]))):
          idxs[idx_counter, 0] = int(idx_list[0][idx_counter])
          idxs[idx_counter, 1] = int(idx_list[1][idx_counter])
          idxs[idx_counter, 2] = int(idx_list[2][idx_counter])
  
      idxs = idxs.astype("int8")
  
      # How many voxels per ROI
      voxels = int(ROI.sum())
  
      # Create a pattern of activity across the two voxels
      if data_dict["multivariate_pattern"] is True:
          pattern = np.random.rand(voxels).reshape((voxels, 1))
      else:  # Just make a univariate increase
          pattern = np.tile(1, voxels).reshape((voxels, 1))
  
      # Multiply each pattern by each voxel time course
      weights = np.tile(stimfunc, voxels) * pattern.T
  
      # Convolve the onsets with the HRF
      temporal_res = 1 / data_dict["trDuration"]
      signal_func = sim.convolve_hrf(
          stimfunction=weights,
          tr_duration=data_dict["trDuration"],
          temporal_resolution=temporal_res,
          scale_function=1,
      )
  
      # Change the type of noise
      noise = noise.astype("double")
  
      # Create a noise function (same voxels for signal function as for noise)
      noise_function = noise[idxs[:, 0], idxs[:, 1], idxs[:, 2], :].T
  
      # Compute the signal magnitude for the data
      sf_scaled = sim.compute_signal_change(
          signal_function=signal_func,
          noise_function=noise_function,
          noise_dict=data_dict["noise_dict"],
          magnitude=[scale_percentage],
          method="PSC",
      )
  
      # Combine the signal time course with the signal volume
      signal = sim.apply_signal(
          sf_scaled,
          ROI,
      )
  
      # Return signal needed
      return signal
  
file_path: brainiak/brainiak/utils/fmrisim_real_time_generator.py
imports: import os
  import time
  import argparse
  import datetime
  import nibabel
  import numpy
  import pydicom
  from brainiak.utils import fmrisim
  import logging
  from pkg_resources import resource_stream
  from nibabel.nifti1 import Nifti1Image
  import gzip
label_desc: Use image node_id 1 for calling a global function with example usage: _generate_ROIs(ROI_file, stimfunc, noise, scale_percentage, data_dict) and returns: signal