class_docstr: A WMTS imagery retriever which can be added to a map.
  
  Uses tile caching for fast repeated map retrievals.
  
  Note
  ----
      Requires owslib and Pillow to work.
class_docstr_tok: ["A","WMTS","imagery","retriever","which","can","be","added","to","a","map",".","Uses","tile","caching","for","fast","repeated","map","retrievals",".","Note","--","--","Requires","owslib","and","Pillow","to","work","."]
code: def _choose_matrix(
      self, tile_matrices, meters_per_unit, max_pixel_span
  ):
      # Get the tile matrices in order of increasing resolution.
      tile_matrices = sorted(
          tile_matrices,
          key=lambda tm: tm.scaledenominator,
          reverse=True,
      )
  
      # Find which tile matrix has the appropriate resolution.
      max_scale = max_pixel_span * meters_per_unit / METERS_PER_PIXEL
      for tm in tile_matrices:
          if tm.scaledenominator <= max_scale:
              return tm
      return tile_matrices[-1]
  
imports: import collections
  import io
  import math
  from urllib.parse import urlparse
  import warnings
  import weakref
  from xml.etree import ElementTree
  import numpy
  from PIL import Image
  import shapely.geometry
  import cartopy.crs
  from cartopy.img_transform import warp_array
  from cartopy.io import LocatedImage, RasterSource
label_desc: Use image node_id 5 for calling the WMTSRasterSource obj's underlying member method code with example usage: obj._choose_matrix(tile_matrices, meters_per_unit, max_pixel_span) and returns: tile_matrices, tm