code: def raster_geometry_mask(
      dataset,
      shapes,
      all_touched=False,
      invert=False,
      crop=False,
      pad=False,
      pad_width=0.5,
  ):
      """Create a mask from shapes, transform, and optional window within original
      raster.
  
      By default, mask is intended for use as a numpy mask, where pixels that
      overlap shapes are False.
  
      If shapes do not overlap the raster and crop=True, a ValueError is
      raised.  Otherwise, a warning is raised, and a completely True mask
      is returned (if invert is False).
  
      Parameters
      ----------
      dataset : a dataset object opened in 'r' mode
          Raster for which the mask will be created.
      shapes : iterable object
          The values must be a GeoJSON-like dict or an object that implements
          the Python geo interface protocol (such as a Shapely Polygon).
      all_touched : bool (opt)
          Include a pixel in the mask if it touches any of the shapes.
          If False (default), include a pixel only if its center is within one of
          the shapes, or if it is selected by Bresenham's line algorithm.
      invert : bool (opt)
          Determines whether to mask pixels outside or inside the shapes.
          The default (False) is to mask pixels outside shapes.
          When invert is used with crop, the area outside the cropping window is
          considered selected and should be processed accordingly by the user.
      crop : bool (opt)
          Crop the dataset to the extent of the shapes. Useful for
          processing rasters where shapes cover only a relatively small area.
          Defaults to False.
      pad : bool (opt)
          If True, the features will be padded in each direction by
          one half of a pixel prior to cropping dataset. Defaults to False.
      pad_width : float (opt)
          If pad is set (to maintain back-compatibility), then this will be the
          pixel-size width of the padding around the mask.
  
      Returns
      -------
      tuple
  
          Three elements:
  
              mask : np.ndarray of type 'bool'
                  Mask suitable for use in a MaskedArray where valid pixels are
                  marked `False` and invalid pixels are marked `True`.
  
              out_transform : affine.Affine()
                  Information for mapping pixel coordinates in `masked` to another
                  coordinate system.
  
              window: rasterio.windows.Window instance
                  Window within original raster covered by shapes.  None if crop
                  is False.
      """
      if crop and pad:
          pad_x = pad_width
          pad_y = pad_width
      else:
          pad_x = 0
          pad_y = 0
  
      try:
          window = geometry_window(
              dataset, shapes, pad_x=pad_x, pad_y=pad_y
          )
  
      except WindowError:
          # If shapes do not overlap raster, raise Exception or UserWarning
          # depending on value of crop
          if crop:
              raise ValueError("Input shapes do not overlap raster.")
          else:
              warnings.warn(
                  "shapes are outside bounds of raster. "
                  "Are they in different coordinate reference systems?"
              )
  
          # Return an entirely True mask (if invert is False)
          mask = np.ones(shape=dataset.shape[-2:], dtype="bool")
          if invert:
              mask = ~mask
          return mask, dataset.transform, None
  
      if crop:
          transform = dataset.window_transform(window)
          out_shape = (int(window.height), int(window.width))
  
      else:
          window = None
          transform = dataset.transform
          out_shape = (int(dataset.height), int(dataset.width))
  
      mask = geometry_mask(
          shapes,
          transform=transform,
          invert=invert,
          out_shape=out_shape,
          all_touched=all_touched,
      )
  
      return mask, transform, window
  
imports: import logging
  import warnings
  import numpy
  from rasterio.errors import WindowError
  from rasterio.features import geometry_mask, geometry_window
label_desc: Use image node_id 1 for calling a global function with example usage: raster_geometry_mask(dataset, shapes, all_touched, invert, crop, pad, pad_width) and returns: mask,  transform,  window, mask,  dataset,  None