code: def stack2designs(old_X, new_X, old_contrasts={}, new_contrasts={}):
      """
      Add some columns to a design matrix that has contrasts matrices
      already specified, adding some possibly new contrasts as well.
  
      This basically performs an np.hstack of old_X, new_X
      and makes sure the contrast matrices are dealt with accordingly.
  
      If two contrasts have the same name, an exception is raised.
  
      Parameters
      ----------
      old_X : np.ndarray
         A design matrix
      new_X : np.ndarray
         A second design matrix to be stacked with old_X
      old_contrast : dict
         Dictionary of contrasts in the old_X column space
      new_contrasts : dict
         Dictionary of contrasts in the new_X column space
  
      Returns
      -------
      X : np.ndarray
         A new design matrix:  np.hstack([old_X, new_X])
      contrasts : dict
         The new contrast matrices reflecting changes to the columns.
      """
      contrasts = {}
      old_X = np.asarray(old_X)
      new_X = np.asarray(new_X)
      if old_X.size == 0:
          return new_X, new_contrasts
      if new_X.size == 0:
          return old_X, old_contrasts
  
      if old_X.ndim == 1:
          old_X = old_X[:, None]
      if new_X.ndim == 1:
          new_X = new_X[:, None]
  
      X = np.hstack([old_X, new_X])
  
      if (
          set(old_contrasts.keys()).intersection(new_contrasts.keys())
          != set()
      ):
          raise ValueError(
              "old and new contrasts must have different names"
          )
  
      for n, c in old_contrasts.items():
          if c.ndim > 1:
              cm = np.zeros((c.shape[0], X.shape[1]))
              cm[:, : old_X.shape[1]] = c
          else:
              cm = np.zeros(X.shape[1])
              cm[: old_X.shape[1]] = c
          contrasts[n] = cm
  
      for n, c in new_contrasts.items():
          if c.ndim > 1:
              cm = np.zeros((c.shape[0], X.shape[1]))
              cm[:, old_X.shape[1] :] = c
          else:
              cm = np.zeros(X.shape[1])
              cm[old_X.shape[1] :] = c
          contrasts[n] = cm
  
      return X, contrasts
  
imports: import itertools
  from functools import reduce
  from operator import mul
  import numpy
  from nipy.algorithms.statistics.formula import formulae
  from nipy.algorithms.statistics.formula.formulae import Factor, Formula, Term, make_recarray
  from nipy.algorithms.statistics.utils import combinations
  from .hrf import glover
  from .utils import T, blocks, convolve_functions, events
  from .utils import fourier_basis
label_desc: Use image node_id 6 for calling a global function with example usage: stack2designs(old_X, new_X, old_contrasts, new_contrasts) and returns: X,  contrasts, new_X,  new_contrasts, old_X,  old_contrasts