raster_tools.mosaic#

raster_tools.mosaic(rasters, mosaic_method='last', dst_crs=None, dst_grid=None, resampling_method='nearest', dtype=None, null_value=None)[source]#

Mosaic multiple rasters into a new, single raster.

The inputs can have multiple and differing numbers of bands. The number of bands in the output will be the same as the input with the largest number of bands.

Parameters
  • rasters (list of raster_tools.Raster) – A list-like object containing the rasters to be mosaicked. These can have differing grids, resolutions, and projections.

  • mosaic_method (str, optional) –

    The method to use when resolving overlap. Valid options are:

    ’first’

    The final pixel will take its value from the first raster with a valid pixel at the pixel’s location.

    ’last’

    The final pixel will take its value from the last raster with a valid pixel at the pixel’s location. Default.

    ’min’

    The final pixel will take its value from the minimum valid value across all input rasters, at the given location.

    ’max’

    The final pixel will take its value from the maximum valid value across all input rasters, at the given location.

    ’sum’

    The final pixel will be the sum of all valid pixels at the given location. Note, this can lead to overflow issues for sufficiently large values and small enough dtypes.

  • dst_crs (CRS-like, str, int, optional) – The destination CRS to use when building the destination grid. This can be anything that can be parsed by rasterio.CRS.from_user_input(). This is only checked if dst_grid is not provided. The default is to take the CRS from the first raster in rasters.

  • dst_grid (odc.geo.GeoBox, raster_tools.Raster, str, optional) – The definition for the destination grid to mosaic the rasters onto. This can be a odc.geo.GeoBox, raster_tools.Raster object, or a path str. If the input is a raster object or path, this function does NOT write to the given raster, it instead uses the raster as a reference for the grid. The default is to check dst_crs and construct a grid that encompasses all inputs, using the resolution from the first raster in rasters.

  • resampling_method (str, optional) –

    Resampling method to use when reprojecting input rasters to the destination grid. The default is nearest. Valid options are:

    ’nearest’

    Nearest neighbor resampling. This is the default.

    ’bilinear’

    Bilinear resampling.

    ’cubic’

    Cubic resampling.

    ’cubic_spline’

    Cubic spline resampling.

    ’lanczos’

    Lanczos windowed sinc resampling.

    ’average’

    Average resampling, computes the weighted average of all contributing pixels.

    ’mode’

    Mode resampling, selects the value which appears most often.

    ’max’

    Maximum resampling. (GDAL 2.0+)

    ’min’

    Minimum resampling. (GDAL 2.0+)

    ’med’

    Median resampling. (GDAL 2.0+)

    ’q1’

    Q1, first quartile resampling. (GDAL 2.0+)

    ’q3’

    Q3, third quartile resampling. (GDAL 2.0+)

    ’sum’

    Sum, compute the weighted sum. (GDAL 3.1+)

    ’rms’

    RMS, root mean square/quadratic mean. (GDAL 3.3+)

  • dtype (numpy.dtype, str, optional) – The dtype for the output raster. The default is to use numpy.result_type() on the dtypes from the input rasters.

  • null_value (scalar, optional) – The nodata/null value to use for the output raster. The default is to get a default value based on the output raster’s dtype.

Returns

The resulting mosaicked raster.

Return type

Raster