def get_best_zoom_level(input_file, tile_pyramid_type):
tile_pyramid = BufferedTilePyramid(tile_pyramid_type)<EOL>with rasterio.open(input_file, "<STR_LIT:r>") as src:<EOL><INDENT>xmin, ymin, xmax, ymax = reproject_geometry(<EOL>segmentize_geometry(<EOL>box(<EOL>src.bounds.left, src.bounds.bottom, src.bounds.right,<EOL>src.bounds.top<EOL>),<EOL>get_segmentize_value(input_file, tile_pyramid)<EOL>),<EOL>src_crs=src.crs, dst_crs=tile_pyramid.crs<EOL>).bounds<EOL>x_dif = xmax - xmin<EOL>y_dif = ymax - ymin<EOL>size = float(src.width + src.height)<EOL>avg_resolution = (<EOL>(x_dif / float(src.width)) * (float(src.width) / size) +<EOL>(y_dif / float(src.height)) * (float(src.height) / size)<EOL>)<EOL><DEDENT>for zoom in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>if tile_pyramid.pixel_x_size(zoom) <= avg_resolution:<EOL><INDENT>return zoom-<NUM_LIT:1><EOL><DEDENT><DEDENT>
Determine the best base zoom level for a raster.

"Best" means the maximum zoom level where no oversampling has to be done.

Parameters
----------
input_file : path to raster file
tile_pyramid_type : ``TilePyramid`` projection (``geodetic`` or``mercator``)

Returns
-------
zoom : integer