Topics

What is the raster merge criteria algorithm on rasterio.merge?


Eduardo <eduardosteps@...>
 

I'm creating a mosaic from many sentinel images with a bunch of overlapping areas, although I'm trying to understand what is criteria. For example:

This is a small piece totally clear of clouds

1

And this is a larger piece with many clouds

2

This is the result of the merge using rasterio.merge

I used rasterio.merge. It brings me a result where the most recent acquired image prevails, but don't understand the algorithm method yet. How can I tell the code to keep the image with fewer clouds as possible? Which method are this algorithm using to preserve the earlier raster and not the cleanest (no clouds)?

It would be absolutely awesome if I could select the raster with fewer clouds based in pixel values, for insance, to be merged for this mosaic. Is there a way to choose them?


James McBride
 

Hi Eduardo,
I'd suggest taking a look at the method argument that merge accepts. There are a few pre-defined methods, and you can also define your own function for selecting which pixel to select from the datasets to be merged. I copied the documentation below:

    method : str or callable
        pre-defined method:
            first: reverse painting
            last: paint valid new on top of existing
            min: pixel-wise min of existing and new
            max: pixel-wise max of existing and new
        or custom callable with signature:
 
        def function(old_data, new_data, old_nodata, new_nodata, index=None, roff=None, coff=None):
 
            Parameters
            ----------
            old_data : array_like
                array to update with new_data
            new_data : array_like
                data to merge
                same shape as old_data
            old_nodata, new_data : array_like
                boolean masks where old/new data is nodata
                same shape as old_data
            index: int
                index of the current dataset within the merged dataset collection
            roff: int
                row offset in base array
            coff: int
                column offset in base array