code: def crop_image(raster, geoms, all_touched=True):
      """Crop a single file using geometry objects.
  
      Parameters
      ----------
      raster : rasterio.io.DatasetReader object
          The rasterio object to be cropped.
      geoms : geopandas geodataframe or list of polygons
          The spatial polygon boundaries in GeoJSON-like dict format
          to be used to crop the image. All data outside of the polygon
          boundaries will be set to nodata and/or removed from the image.
      all_touched : bool (default=True)
          Include a pixel in the mask if it touches any of the
          shapes. If False, include a pixel only if its center is within one of
          the shapes, or if it is selected by Bresenham's line algorithm.
          (from rasterio)
  
      Returns
      ----------
      tuple
  
          out_image: cropped numpy array
              A numpy array that is cropped to the geoms object
              extent with shape (bands, rows, columns)
          out_meta:  dict
              A dictionary containing updated metadata for the cropped raster,
              including extent (shape elements) and transform properties.
  
      Example
      -------
          >>> import geopandas as gpd
          >>> import rasterio as rio
          >>> import earthpy.spatial as es
          >>> from earthpy.io import path_to_example
          >>> # Clip an RGB image to the extent of Rocky Mountain National Park
          >>> rmnp = gpd.read_file(path_to_example("rmnp.shp"))
          >>> with rio.open(path_to_example("rmnp-rgb.tif")) as src_raster:
          ...     cropped_raster, cropped_meta = es.crop_image(src_raster, rmnp)
          >>> src_raster.shape
          (373, 485)
          >>> cropped_raster.shape[1:3]
          (265, 281)
      """
      if isinstance(geoms, gpd.geodataframe.GeoDataFrame):
          clip_extent = [extent_to_json(geoms)]
      else:
          clip_extent = geoms
      out_image, out_transform = mask(
          raster, clip_extent, crop=True, all_touched=all_touched
      )
      out_meta = raster.meta.copy()
      out_meta.update(
          {
              "driver": "GTiff",
              "height": out_image.shape[1],
              "width": out_image.shape[2],
              "transform": out_transform,
          }
      )
      return out_image, out_meta
  
file_path: earthpy/earthpy/spatial.py
imports: import os
  import sys
  import contextlib
  import warnings
  import numpy
  from shapely.geometry import mapping, box
  import geopandas
  import rasterio
  from rasterio.mask import mask
label_desc: Use image node_id 5 for calling a global function with example usage: crop_image(raster, geoms, all_touched) and returns: out_image,  out_meta