original_docstring:  Internal function used to load anatomy, for optional diming
      
docstring: Internal function used to load anatomy, for optional diming
docstring_tokens: Internal function used to load anatomy for optional diming
code: def _load_anat(anat_img=MNI152TEMPLATE, dim='auto', black_bg='auto'):
      """ Internal function used to load anatomy, for optional diming
      """
      vmin = None
      vmax = None
      if anat_img is False or anat_img is None:
          if black_bg == 'auto':
              # No anatomy given: no need to turn black_bg on
              black_bg = False
          return anat_img, black_bg, vmin, vmax
  
      if anat_img is MNI152TEMPLATE:
          anat_img.load()
          # We special-case the 'canonical anat', as we don't need
          # to do a few transforms to it.
          vmin = 0
          vmax = anat_img.vmax
          if black_bg == 'auto':
              black_bg = False
      else:
          anat_img = _utils.check_niimg_3d(anat_img)
          # Clean anat_img for non-finite values to avoid computing unnecessary
          # border data values.
          data = _safe_get_data(anat_img, ensure_finite=True)
          anat_img = new_img_like(anat_img, data, affine=anat_img.affine)
          if dim or black_bg == 'auto':
              # We need to inspect the values of the image
              vmin = np.nanmin(data)
              vmax = np.nanmax(data)
          if black_bg == 'auto':
              # Guess if the background is rather black or light based on
              # the values of voxels near the border
              background = np.median(get_border_data(data, 2))
              if background > .5 * (vmin + vmax):
                  black_bg = False
              else:
                  black_bg = True
      if dim:
          if dim != 'auto' and not isinstance(dim, numbers.Number):
              raise ValueError(
                  "The input given for 'dim' needs to be a float. "
                  "You provided dim=%s in %s" % (str(dim), type(dim)))
          vmean = .5 * (vmin + vmax)
          ptp = .5 * (vmax - vmin)
          if black_bg:
              if not isinstance(dim, numbers.Number):
                  dim = .8
              vmax = vmean + (1 + dim) * ptp
          else:
              if not isinstance(dim, numbers.Number):
                  dim = .6
              vmin = .5 * (2 - dim) * vmean - (1 + dim) * ptp
      return anat_img, black_bg, vmin, vmax
code_tokens: def _load_anat ( anat_img = MNI152TEMPLATE , dim = 'auto' , black_bg = 'auto' ) : vmin = None vmax = None if anat_img is False or anat_img is None : if black_bg == 'auto' : black_bg = False return anat_img , black_bg , vmin , vmax if anat_img is MNI152TEMPLATE : anat_img . load ( ) vmin = 0 vmax = anat_img . vmax if black_bg == 'auto' : black_bg = False else : anat_img = _utils . check_niimg_3d ( anat_img ) data = _safe_get_data ( anat_img , ensure_finite = True ) anat_img = new_img_like ( anat_img , data , affine = anat_img . affine ) if dim or black_bg == 'auto' : vmin = np . nanmin ( data ) vmax = np . nanmax ( data ) if black_bg == 'auto' : background = np . median ( get_border_data ( data , 2 ) ) if background > .5 * ( vmin + vmax ) : black_bg = False else : black_bg = True if dim : if dim != 'auto' and not isinstance ( dim , numbers . Number ) : raise ValueError ( "The input given for 'dim' needs to be a float. " "You provided dim=%s in %s" % ( str ( dim ) , type ( dim ) ) ) vmean = .5 * ( vmin + vmax ) ptp = .5 * ( vmax - vmin ) if black_bg : if not isinstance ( dim , numbers . Number ) : dim = .8 vmax = vmean + ( 1 + dim ) * ptp else : if not isinstance ( dim , numbers . Number ) : dim = .6 vmin = .5 * ( 2 - dim ) * vmean - ( 1 + dim ) * ptp return anat_img , black_bg , vmin , vmax
short_docstring: Internal function used to load anatomy, for optional diming
short_docstring_tokens: Internal function used to load anatomy for optional diming
comment: """ Internal function used to load anatomy, for optional diming
      """$SEP$# No anatomy given: no need to turn black_bg on$SEP$# We special-case the 'canonical anat', as we don't need$SEP$# to do a few transforms to it.$SEP$# Clean anat_img for non-finite values to avoid computing unnecessary$SEP$# border data values.$SEP$# We need to inspect the values of the image$SEP$# Guess if the background is rather black or light based on$SEP$# the values of voxels near the border