docs: def calculate_sizes_by_zoom(coord, metatile_zoom, cfg_tile_sizes, max_zoom):
      """
      Returns a map of nominal zoom to the list of tile sizes to generate at that
      zoom.
  
      This is because we want to generate different metatile contents at
      different zoom levels. At the most detailed zoom level, we want to generate
      the smallest tiles possible, as this allows "overzooming" by simply
      extracting the smaller tiles. At the minimum zoom, we want to get as close
      as we can to zero nominal zoom by using any "unused" space in the metatile
      for larger tile sizes that we're not generating.
  
      For example, with 1x1 metatiles, the tile size is always 256px, and the
      function will return {coord.zoom: [256]}
  
      Note that max_zoom should be the maximum *coordinate* zoom, not nominal
      zoom.
      """
  
      from tilequeue.tile import metatile_zoom_from_size
  
      tile_size_by_zoom = {}
      nominal_zoom = coord.zoom + metatile_zoom
  
      # check that the tile sizes are correct and within range.
      for tile_size in cfg_tile_sizes:
          assert tile_size >= 256
          assert tile_size <= 256 * (1 << metatile_zoom)
          assert _is_power_of_2(tile_size)
  
      if coord.zoom >= max_zoom:
          # all the tile_sizes down to 256 at the nominal zoom.
          tile_sizes = []
          tile_sizes.extend(cfg_tile_sizes)
  
          lowest_tile_size = min(tile_sizes)
          while lowest_tile_size > 256:
              lowest_tile_size //= 2
              tile_sizes.append(lowest_tile_size)
  
          tile_size_by_zoom[nominal_zoom] = tile_sizes
  
      elif coord.zoom <= 0:
          # the tile_sizes, plus max(tile_sizes) size at nominal zooms decreasing
          # down to 0 (or as close as we can get)
          tile_size_by_zoom[nominal_zoom] = cfg_tile_sizes
  
          max_tile_size = max(cfg_tile_sizes)
          max_tile_zoom = metatile_zoom_from_size(max_tile_size // 256)
          assert max_tile_zoom <= metatile_zoom
          for delta in range(0, metatile_zoom - max_tile_zoom):
              z = nominal_zoom - (delta + 1)
              tile_size_by_zoom[z] = [max_tile_size]
  
      else:
          # the tile_sizes at nominal zoom only.
          tile_size_by_zoom[nominal_zoom] = cfg_tile_sizes
  
      return tile_size_by_zoom