code: def test_block_amplitudes():
      # Test event design helper function
      # An event design with one event type
      onsets = np.array([0, 20, 40, 60])
      durations = np.array([2, 3, 4, 5])
      offsets = onsets + durations
      amplitudes = [3, 2, 1, 4]
      t = np.arange(0, 100, 2.5)
  
      def mk_blk_tc(amplitudes=None, hrf=glover):
          func_amp = blocks(zip(onsets, offsets), amplitudes)
          # Make real time course for block onset / offsets / amplitudes
          term = convolve_functions(
              func_amp,
              hrf(T),
              (-5, 70),  # step func support
              (0, 30.0),  # conv kernel support
              0.02,
          )  # dt
          return lambdify_t(term)(t)
  
      no_amps = make_recarray(zip(onsets, offsets), ("start", "end"))
      amps = make_recarray(
          zip(onsets, offsets, amplitudes),
          ("start", "end", "amplitude"),
      )
      X, contrasts = block_amplitudes("ev0", no_amps, t)
      assert_almost_equal(X, mk_blk_tc())
      assert_dict_almost_equal(contrasts, {"ev0_0": 1})
      # Same thing as 2D array
      X, contrasts = block_amplitudes("ev0", np.c_[onsets, offsets], t)
      assert_almost_equal(X, mk_blk_tc())
      assert_dict_almost_equal(contrasts, {"ev0_0": 1})
      # Now as list
      X, contrasts = block_amplitudes(
          "ev0", list(zip(onsets, offsets)), t
      )
      assert_almost_equal(X, mk_blk_tc())
      assert_dict_almost_equal(contrasts, {"ev0_0": 1})
      # Add amplitudes
      X_a, contrasts_a = block_amplitudes("ev1", amps, t)
      assert_almost_equal(X_a, mk_blk_tc(amplitudes=amplitudes))
      assert_dict_almost_equal(contrasts_a, {"ev1_0": 1})
      # Same thing as 2D array
      X_a, contrasts_a = block_amplitudes(
          "ev1", np.c_[onsets, offsets, amplitudes], t
      )
      assert_almost_equal(X_a, mk_blk_tc(amplitudes=amplitudes))
      assert_dict_almost_equal(contrasts_a, {"ev1_0": 1})
      # Add another HRF
      X_2, contrasts_2 = block_amplitudes(
          "ev0", no_amps, t, (glover, dglover)
      )
      assert_almost_equal(
          X_2, np.c_[mk_blk_tc(), mk_blk_tc(hrf=dglover)]
      )
      assert_dict_almost_equal(
          contrasts_2, {"ev0_0": [1, 0], "ev0_1": [0, 1]}
      )
      # Errors on bad input
      no_start = make_recarray(zip(onsets, offsets), ("begin", "end"))
      pytest.raises(ValueError, block_amplitudes, "ev0", no_start, t)
      no_end = make_recarray(zip(onsets, offsets), ("start", "finish"))
      pytest.raises(ValueError, block_amplitudes, "ev0", no_end, t)
      funny_amp = make_recarray(
          zip(onsets, offsets, amplitudes),
          ("start", "end", "intensity"),
      )
      pytest.raises(ValueError, block_amplitudes, "ev0", funny_amp, t)
      funny_extra = make_recarray(
          zip(onsets, offsets, amplitudes, onsets),
          ("start", "end", "amplitude", "extra_field"),
      )
      pytest.raises(ValueError, block_amplitudes, "ev0", funny_extra, t)
  
file_path: nipy/nipy/modalities/fmri/tests/test_design.py
imports: from os.path import dirname
  from os.path import join
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_equal
  from nipy.algorithms.statistics.formula import make_recarray
  from ..design import block_amplitudes, block_design, event_design, openfmri2nipy, stack2designs, stack_designs
  from ..hrf import dglover, glover
  from ..utils import T, blocks, convolve_functions, events, lambdify_t
label_desc: Use image node_id 6 for calling a global function with example usage: test_block_amplitudes() and returns: lambdify_t