code: def extract(Z, shape, position, fill):
      """Extract voxel neighbourhood
  
      Parameters
      ----------
      Z : array-like
          the original data
      shape : tuple
          tuple containing neighbourhood dimensions
      position : tuple
          tuple containing central point indexes
      fill : float
         value for the padding of Z
  
      Returns
      -------
      R : ndarray
          the neighbourhood of the specified point in Z
  
      """
      R = (
          np.ones(shape, dtype=Z.dtype) * fill
      )  # initialize output block to the fill value
      P = np.array(list(position)).astype(
          int
      )  # position coordinates(numpy array)
      Rs = np.array(list(R.shape)).astype(
          int
      )  # output block dimensions (numpy array)
      Zs = np.array(list(Z.shape)).astype(
          int
      )  # original volume dimensions (numpy array)
  
      R_start = np.zeros(len(shape)).astype(int)
      R_stop = np.array(list(shape)).astype(int)
      Z_start = P - Rs // 2
      Z_start_cor = (np.maximum(Z_start, 0)).tolist()  # handle borders
      R_start = R_start + (Z_start_cor - Z_start)
      Z_stop = (P + Rs // 2) + Rs % 2
      Z_stop_cor = (np.minimum(Z_stop, Zs)).tolist()  # handle borders
      R_stop = R_stop - (Z_stop - Z_stop_cor)
  
      R[
          R_start[0] : R_stop[0],
          R_start[1] : R_stop[1],
          R_start[2] : R_stop[2],
      ] = Z[
          Z_start_cor[0] : Z_stop_cor[0],
          Z_start_cor[1] : Z_stop_cor[1],
          Z_start_cor[2] : Z_stop_cor[2],
      ]
  
      return R
  
imports: import os
  import os.path
  import shutil
  import numpy
  import nibabel
  import networkx
  from ...None import logging
  from ..base import BaseInterface, LibraryBaseInterface, BaseInterfaceInputSpec, traits, File, TraitedSpec, Directory, isdefined
  from .base import have_cmp
label_desc: Use image node_id 5 for calling a global function with example usage: extract(Z, shape, position, fill) and returns: R