code: def medial_wall_to_nan(in_file, subjects_dir, target_subject, newpath=None):
      
      import nibabel as nb
      import numpy as np
      import os
  
      fn = os.path.basename(in_file)
      if not target_subject.startswith('fs'):
          return in_file
  
      cortex = nb.freesurfer.read_label(os.path.join(
          subjects_dir, target_subject, 'label', '{}.cortex.label'.format(fn[:2])))
      func = nb.load(in_file)
      medial = np.delete(np.arange(len(func.darrays[0].data)), cortex)
      for darray in func.darrays:
          darray.data[medial] = np.nan
  
      out_file = os.path.join(newpath or os.getcwd(), fn)
      func.to_filename(out_file)
      return out_file
docs: Convert values on medial wall to NaNs