parameters: (fig, dataview, extents=None, height=None, threshold=True, contrast=None,
                    brightness=None, smooth=None, cmap='gray', recache=False, curvature_lims=0.5,
                    legacy_mode=False)
return_statement: return cvimg
docstring: Add curvature layer to figure
  
      Parameters
      ----------
      fig : figure or ax
          figure into which to plot image of curvature
      dataview : cortex.Dataview object
          dataview containing data to be plotted, subject (surface identifier), and transform.
      extents : array-like
          4 values for [Left, Right, Top, Bottom] extents of image plotted. None defaults to 
          extents of images already present in figure.
      height : scalar
          Height of image. None defaults to height of images already present in figure. 
      threshold : boolean
          Whether to apply a threshold to the curvature values to create a binary curvature image
          (one shade for positive curvature, one shade for negative). `None` defaults to value 
          specified in the config file
      contrast : float, [0-1] or None
          Contrast of curvature image. 1 is maximal contrast (given brightness). If brightness is 0.5
          and contrast is 1, and cmap is 'gray', curvature will be black and white. None defaults
          to value in config file.
      brightness : float, [0-1] or None
          How bright to make average value of curvature (0=black, 1=white in gray cmap). None
          defaults to the value in config file.
      curvature_lims : float
          Limits for real curvature values (actual values for cortical curvature are normalized
          within [-`curvature_lims`, +`curvature_lims`] before scaling by `contrast` and shifting
          by `brightness`).
      smooth : scalar or None
          Width of smoothing to apply to surface curvature. None defaults to no smoothing, or
          whatever the default value for curvature is that is stored in
          <filestore>/<subject>/surface-info/curvature.npz (for some subjects initiated in old
          versions of pycortex, this may be smoothed too!)
      cmap : string
          name for colormap of curvature
      recache : boolean
          Whether or not to recache intermediate files. Takes longer to plot this way, potentially
          resolves some errors.
  
      Returns
      -------
      img : matplotlib.image.AxesImage
          matplotlib axes image object for plotted data
docstring_summary: Add curvature layer to figure
docstring_tokens: Add curvature layer to figure
function: def add_curvature(fig, dataview, extents=None, height=None, threshold=True, contrast=None,
                    brightness=None, smooth=None, cmap='gray', recache=False, curvature_lims=0.5,
                    legacy_mode=False):
      """Add curvature layer to figure
  
      Parameters
      ----------
      fig : figure or ax
          figure into which to plot image of curvature
      dataview : cortex.Dataview object
          dataview containing data to be plotted, subject (surface identifier), and transform.
      extents : array-like
          4 values for [Left, Right, Top, Bottom] extents of image plotted. None defaults to 
          extents of images already present in figure.
      height : scalar
          Height of image. None defaults to height of images already present in figure. 
      threshold : boolean
          Whether to apply a threshold to the curvature values to create a binary curvature image
          (one shade for positive curvature, one shade for negative). `None` defaults to value 
          specified in the config file
      contrast : float, [0-1] or None
          Contrast of curvature image. 1 is maximal contrast (given brightness). If brightness is 0.5
          and contrast is 1, and cmap is 'gray', curvature will be black and white. None defaults
          to value in config file.
      brightness : float, [0-1] or None
          How bright to make average value of curvature (0=black, 1=white in gray cmap). None
          defaults to the value in config file.
      curvature_lims : float
          Limits for real curvature values (actual values for cortical curvature are normalized
          within [-`curvature_lims`, +`curvature_lims`] before scaling by `contrast` and shifting
          by `brightness`).
      smooth : scalar or None
          Width of smoothing to apply to surface curvature. None defaults to no smoothing, or
          whatever the default value for curvature is that is stored in
          <filestore>/<subject>/surface-info/curvature.npz (for some subjects initiated in old
          versions of pycortex, this may be smoothed too!)
      cmap : string
          name for colormap of curvature
      recache : boolean
          Whether or not to recache intermediate files. Takes longer to plot this way, potentially
          resolves some errors.
  
      Returns
      -------
      img : matplotlib.image.AxesImage
          matplotlib axes image object for plotted data
  
      """
      from matplotlib.colors import Normalize
      if height is None:
          height = _get_height(fig)
      # Get curvature map as image
      default_smoothing = config.get('curvature', 'smooth')
      if default_smoothing.lower()=='none':
          default_smoothing = None
      else:
          default_smoothing = np.float(default_smoothing)
      if smooth is None:
          # (Might still be None!)
          smooth = default_smoothing
      if smooth is None:
          # If no value for 'smooth' is given in kwargs, db.get_surfinfo returns
          # the default curvature value, whatever that may be. This is the behavior
          # that we want a None in the code to invoke. This is silly and complicated
          # due to backward compatibility issues with some old subjects.
          curv_vertices = db.get_surfinfo(dataview.subject)
      else:
          curv_vertices = db.get_surfinfo(dataview.subject, smooth=smooth)
      curv, _ = make_flatmap_image(curv_vertices, recache=recache, height=height)
      # First, limit to sensible range for flatmap curvature
      norm = Normalize(vmin=-0.5, vmax=0.5)
      curv_im = norm(curv)
      # Option to use thresholded curvature
      default_threshold = config.get('curvature','threshold').lower() in ('true', 't', '1', 'y', 'yes')
      use_threshold_curvature = default_threshold if threshold is None else threshold
      if legacy_mode and use_threshold_curvature:
          curvT = (curv>0).astype(np.float32)
          curvT[np.isnan(curv)] = np.nan
          curv = curvT
      if isinstance(curvature_lims, (list, tuple)):
          vmin, vmax = curvature_lims
      else:
          vmin, vmax = -curvature_lims, curvature_lims
      norm = Normalize(vmin=vmin, vmax=vmax)
      curv_im = norm(curv)
      if not legacy_mode:
          if use_threshold_curvature:
              # Assumes symmetrical curvature_lims
              curv_im = (np.nan_to_num(curv_im) > 0.5).astype(np.float)
              curv_im[np.isnan(curv)] = np.nan
          # Get defaults for brightness, contrast
          if brightness is None:
              brightness = float(config.get('curvature', 'brightness'))
          if contrast is None:
              contrast = float(config.get('curvature', 'contrast'))
          # Scale and shift curvature image
          curv_im = (curv_im - 0.5) * contrast + brightness
      if extents is None:
          extents = _get_extents(fig)
      _, ax = _get_fig_and_ax(fig)
      cvimg = ax.imshow(curv_im,
                        aspect='equal',
                        extent=extents,
                        cmap=cmap,
                        vmin=0,
                        vmax=1,
                        label='curvature',
                        zorder=0)
      return cvimg
function_tokens: def add_curvature ( fig , dataview , extents = None , height = None , threshold = True , contrast = None , brightness = None , smooth = None , cmap = 'gray' , recache = False , curvature_lims = 0.5 , legacy_mode = False ) : from matplotlib . colors import Normalize if height is None : height = _get_height ( fig ) # Get curvature map as image default_smoothing = config . get ( 'curvature' , 'smooth' ) if default_smoothing . lower ( ) == 'none' : default_smoothing = None else : default_smoothing = np . float ( default_smoothing ) if smooth is None : # (Might still be None!) smooth = default_smoothing if smooth is None : # If no value for 'smooth' is given in kwargs, db.get_surfinfo returns # the default curvature value, whatever that may be. This is the behavior # that we want a None in the code to invoke. This is silly and complicated # due to backward compatibility issues with some old subjects. curv_vertices = db . get_surfinfo ( dataview . subject ) else : curv_vertices = db . get_surfinfo ( dataview . subject , smooth = smooth ) curv , _ = make_flatmap_image ( curv_vertices , recache = recache , height = height ) # First, limit to sensible range for flatmap curvature norm = Normalize ( vmin = - 0.5 , vmax = 0.5 ) curv_im = norm ( curv ) # Option to use thresholded curvature default_threshold = config . get ( 'curvature' , 'threshold' ) . lower ( ) in ( 'true' , 't' , '1' , 'y' , 'yes' ) use_threshold_curvature = default_threshold if threshold is None else threshold if legacy_mode and use_threshold_curvature : curvT = ( curv > 0 ) . astype ( np . float32 ) curvT [ np . isnan ( curv ) ] = np . nan curv = curvT if isinstance ( curvature_lims , ( list , tuple ) ) : vmin , vmax = curvature_lims else : vmin , vmax = - curvature_lims , curvature_lims norm = Normalize ( vmin = vmin , vmax = vmax ) curv_im = norm ( curv ) if not legacy_mode : if use_threshold_curvature : # Assumes symmetrical curvature_lims curv_im = ( np . nan_to_num ( curv_im ) > 0.5 ) . astype ( np . float ) curv_im [ np . isnan ( curv ) ] = np . nan # Get defaults for brightness, contrast if brightness is None : brightness = float ( config . get ( 'curvature' , 'brightness' ) ) if contrast is None : contrast = float ( config . get ( 'curvature' , 'contrast' ) ) # Scale and shift curvature image curv_im = ( curv_im - 0.5 ) * contrast + brightness if extents is None : extents = _get_extents ( fig ) _ , ax = _get_fig_and_ax ( fig ) cvimg = ax . imshow ( curv_im , aspect = 'equal' , extent = extents , cmap = cmap , vmin = 0 , vmax = 1 , label = 'curvature' , zorder = 0 ) return cvimg