code: def test_apply_signal():
      dimensions = np.array(
          [10, 10, 10]
      )  # What is the size of the brain
      feature_size = [2]
      feature_type = ["cube"]
      feature_coordinates = np.array([[5, 5, 5]])
      signal_magnitude = [30]
  
      # Generate a volume representing the location and quality of the signal
      volume = sim.generate_signal(
          dimensions=dimensions,
          feature_coordinates=feature_coordinates,
          feature_type=feature_type,
          feature_size=feature_size,
          signal_magnitude=signal_magnitude,
      )
  
      # Inputs for generate_stimfunction
      onsets = [10, 30, 50, 70, 90]
      event_durations = [6]
      tr_duration = 2
      duration = 100
  
      # Create the time course for the signal to be generated
      stimfunction = sim.generate_stimfunction(
          onsets=onsets,
          event_durations=event_durations,
          total_time=duration,
      )
  
      signal_function = sim.convolve_hrf(
          stimfunction=stimfunction,
          tr_duration=tr_duration,
      )
  
      # Check that you can compute signal change appropriately
      # Preset a bunch of things
      stimfunction_tr = stimfunction[:: int(tr_duration * 100)]
      mask, template = sim.mask_brain(dimensions, mask_self=False)
      noise_dict = sim._noise_dict_update({})
      noise = sim.generate_noise(
          dimensions=dimensions,
          stimfunction_tr=stimfunction_tr,
          tr_duration=tr_duration,
          template=template,
          mask=mask,
          noise_dict=noise_dict,
          iterations=[0, 0],
      )
      coords = feature_coordinates[0]
      noise_function_a = noise[coords[0], coords[1], coords[2], :]
      noise_function_a = noise_function_a.reshape(
          duration // tr_duration, 1
      )
  
      noise_function_b = noise[coords[0] + 1, coords[1], coords[2], :]
      noise_function_b = noise_function_b.reshape(
          duration // tr_duration, 1
      )
  
      # Check that the noise_function and signal_function must be the same size
      method = "PSC"
      with pytest.raises(ValueError):
          sim.compute_signal_change(
              signal_function,
              noise_function_a.T,
              noise_dict,
              [0.5],
              method,
          )
  
      # Create the calibrated signal with PSC
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [1.0],
          method,
      )
  
      assert sig_b.max() / sig_a.max() == 2, "PSC modulation failed"
  
      # Create the calibrated signal with SFNR
      method = "SFNR"
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
      scaled_a = sig_a / (noise_function_a.mean() / noise_dict["sfnr"])
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_b,
          noise_dict,
          [1.0],
          method,
      )
      scaled_b = sig_b / (noise_function_b.mean() / noise_dict["sfnr"])
  
      assert (
          scaled_b.max() / scaled_a.max() == 2
      ), "SFNR modulation failed"
  
      # Create the calibrated signal with CNR_Amp/Noise-SD
      method = "CNR_Amp/Noise-SD"
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
      scaled_a = sig_a / noise_function_a.std()
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_b,
          noise_dict,
          [1.0],
          method,
      )
      scaled_b = sig_b / noise_function_b.std()
  
      assert (
          scaled_b.max() / scaled_a.max() == 2
      ), "CNR_Amp modulation failed"
  
      # Create the calibrated signal with CNR_Amp/Noise-Var_dB
      method = "CNR_Amp2/Noise-Var_dB"
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
      scaled_a = np.log(sig_a.max() / noise_function_a.std())
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_b,
          noise_dict,
          [1.0],
          method,
      )
      scaled_b = np.log(sig_b.max() / noise_function_b.std())
  
      assert (
          np.round(scaled_b / scaled_a) == 2
      ), "CNR_Amp dB modulation failed"
  
      # Create the calibrated signal with CNR_Signal-SD/Noise-SD
      method = "CNR_Signal-SD/Noise-SD"
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
      scaled_a = sig_a.std() / noise_function_a.std()
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [1.0],
          method,
      )
      scaled_b = sig_b.std() / noise_function_a.std()
  
      assert (scaled_b / scaled_a) == 2, "CNR signal modulation failed"
  
      # Create the calibrated signal with CNR_Amp/Noise-Var_dB
      method = "CNR_Signal-Var/Noise-Var_dB"
      sig_a = sim.compute_signal_change(
          signal_function,
          noise_function_a,
          noise_dict,
          [0.5],
          method,
      )
  
      scaled_a = np.log(sig_a.std() / noise_function_a.std())
      sig_b = sim.compute_signal_change(
          signal_function,
          noise_function_b,
          noise_dict,
          [1.0],
          method,
      )
      scaled_b = np.log(sig_b.std() / noise_function_b.std())
  
      assert np.round(scaled_b / scaled_a) == 2, (
          "CNR signal dB modulation " "failed"
      )
  
      # Convolve the HRF with the stimulus sequence
      signal = sim.apply_signal(
          signal_function=signal_function,
          volume_signal=volume,
      )
  
      assert signal.shape == (
          dimensions[0],
          dimensions[1],
          dimensions[2],
          duration / tr_duration,
      ), (
          "The output is the " "wrong size"
      )
  
      signal = sim.apply_signal(
          signal_function=stimfunction,
          volume_signal=volume,
      )
  
      assert np.any(
          signal == signal_magnitude
      ), "The stimfunction is not binary"
  
      # Check that there is an error if the number of signal voxels doesn't
      # match the number of non zero brain voxels
      with pytest.raises(IndexError):
          sig_vox = (volume > 0).sum()
          vox_pattern = np.tile(stimfunction, (1, sig_vox - 1))
          sim.apply_signal(
              signal_function=vox_pattern,
              volume_signal=volume,
          )
  
file_path: brainiak/tests/utils/test_fmrisim.py
imports: import numpy
  import math
  from brainiak.utils import fmrisim
  import pytest
  from itertools import product
label_desc: Use image node_id 3 for calling a global function with example usage: test_apply_signal() without return types