def create_mosaic(tiles, nodata=<NUM_LIT:0>):
if isinstance(tiles, GeneratorType):<EOL><INDENT>tiles = list(tiles)<EOL><DEDENT>elif not isinstance(tiles, list):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not all([isinstance(pair, tuple) for pair in tiles]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not all([<EOL>all([isinstance(tile, BufferedTile), isinstance(data, np.ndarray)])<EOL>for tile, data in tiles<EOL>]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(tiles) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>", len(tiles))<EOL>if len(tiles) == <NUM_LIT:1>:<EOL><INDENT>tile, data = tiles[<NUM_LIT:0>]<EOL>return ReferencedRaster(<EOL>data=data,<EOL>affine=tile.affine,<EOL>bounds=tile.bounds,<EOL>crs=tile.crs<EOL>)<EOL><DEDENT>pyramid, resolution, dtype = _get_tiles_properties(tiles)<EOL>shift = _shift_required(tiles)<EOL>m_left, m_bottom, m_right, m_top = None, None, None, None<EOL>for tile, data in tiles:<EOL><INDENT>num_bands = data.shape[<NUM_LIT:0>] if data.ndim > <NUM_LIT:2> else <NUM_LIT:1><EOL>left, bottom, right, top = tile.bounds<EOL>if shift:<EOL><INDENT>left += pyramid.x_size / <NUM_LIT:2><EOL>right += pyramid.x_size / <NUM_LIT:2><EOL>if right > pyramid.right:<EOL><INDENT>right -= pyramid.x_size<EOL>left -= pyramid.x_size<EOL><DEDENT><DEDENT>m_left = min([left, m_left]) if m_left is not None else left<EOL>m_bottom = min([bottom, m_bottom]) if m_bottom is not None else bottom<EOL>m_right = max([right, m_right]) if m_right is not None else right<EOL>m_top = max([top, m_top]) if m_top is not None else top<EOL><DEDENT>height = int(round((m_top - m_bottom) / resolution))<EOL>width = int(round((m_right - m_left) / resolution))<EOL>mosaic = ma.MaskedArray(<EOL>data=np.full((num_bands, height, width), dtype=dtype, fill_value=nodata),<EOL>mask=np.ones((num_bands, height, width))<EOL>)<EOL>affine = Affine(resolution, <NUM_LIT:0>, m_left, <NUM_LIT:0>, -resolution, m_top)<EOL>for tile, data in tiles:<EOL><INDENT>data = prepare_array(data, nodata=nodata, dtype=dtype)<EOL>t_left, t_bottom, t_right, t_top = tile.bounds<EOL>if shift:<EOL><INDENT>t_left += pyramid.x_size / <NUM_LIT:2><EOL>t_right += pyramid.x_size / <NUM_LIT:2><EOL>if t_right > pyramid.right:<EOL><INDENT>t_right -= pyramid.x_size<EOL>t_left -= pyramid.x_size<EOL><DEDENT><DEDENT>minrow, maxrow, mincol, maxcol = bounds_to_ranges(<EOL>out_bounds=(t_left, t_bottom, t_right, t_top),<EOL>in_affine=affine,<EOL>in_shape=(height, width)<EOL>)<EOL>mosaic[:, minrow:maxrow, mincol:maxcol] = data<EOL>mosaic.mask[:, minrow:maxrow, mincol:maxcol] = data.mask<EOL><DEDENT>if shift:<EOL><INDENT>affine = Affine(resolution, <NUM_LIT:0>, m_left - pyramid.x_size / <NUM_LIT:2>, <NUM_LIT:0>, -resolution, m_top)<EOL><DEDENT>return ReferencedRaster(<EOL>data=mosaic,<EOL>affine=affine,<EOL>bounds=Bounds(m_left, m_bottom, m_right, m_top),<EOL>crs=tile.crs<EOL>)<EOL>
Create a mosaic from tiles. Tiles must be connected (also possible over Antimeridian),
otherwise strange things can happen!

Parameters
----------
tiles : iterable
    an iterable containing tuples of a BufferedTile and an array
nodata : integer or float
    raster nodata value to initialize the mosaic with (default: 0)

Returns
-------
mosaic : ReferencedRaster