code: def permutation_test(design, contrast, mask=GROUP_MASK, nsample=1000):
      """
      Perform a permutation (sign) test for a given design type and
      contrast. It is a Monte Carlo test because we only sample nsample
      possible sign arrays.
  
      Parameters
      ----------
      design: str
          one of ['block', 'event']
      contrast : str
          name of contrast to estimate
      mask : ``Image`` instance or array-like, optional
          image containing mask, or array-like
      nsample: int, optional
          number of permutations
  
      Returns
      -------
      min_vals: np.ndarray
      max_vals: np.ndarray
      """
      subj_con_dirs = futil.subj_des_con_dirs(design, contrast)
      nsubj = len(subj_con_dirs)
      if nsubj == 0:
          raise ValueError(f"No subjects have {design}, {contrast}")
      signs = (
          2 * np.greater(np.random.sample(size=(nsample, nsubj)), 0.5)
          - 1
      )
      min_vals, max_vals = group_analysis_signs(
          design, contrast, mask, signs
      )
      return min_vals, max_vals
  
imports: import warnings
  from copy import copy
  from imp import reload
  from os.path import join
  from tempfile import NamedTemporaryFile
  import ds105_util
  import numpy
  from nipy.algorithms.statistics import onesample
  from nipy.algorithms.statistics.api import ARModel, OLSModel, isestimable, make_recarray
  from nipy.core import api
  from nipy.core.api import Image
  from nipy.core.image.image import rollimg
  from nipy.io.api import load_image, save_image
  from nipy.modalities.fmri import design
  from nipy.modalities.fmri.fmristat import hrf
label_desc: Use image node_id 5 for calling a global function with example usage: permutation_test(design, contrast, mask, nsample) and returns: min_vals,  max_vals