code: def zoom_for_pixelsize(pixel_size, max_z=24, tilesize=256):
      
      for z in range(max_z):
          if pixel_size > _meters_per_pixel(z, 0, tilesize=tilesize):
              return max(0, z - 1)  # We don't want to scale up
  
      return max_z - 1
docs: Get mercator zoom level corresponding to a pixel resolution.
  
      Freely adapted from
      https://github.com/OSGeo/gdal/blob/b0dfc591929ebdbccd8a0557510c5efdb893b852/gdal/swig/python/scripts/gdal2tiles.py#L294
  
      Parameters
      ----------
      pixel_size: float
          Pixel size
      max_z: int, optional (default: 24)
          Max mercator zoom level allowed
      tilesize: int, optional
          Mercator tile size (default: 256).
  
      Returns
      -------
      Mercator zoom level corresponding to the pixel resolution