TransWikia.com

rasterio merge method to calculate mean

Geographic Information Systems Asked on June 18, 2021

I am trying to mosaic some raster-datasets (~15) using rasterio.merge.merge in python.

I defined a method to calculate the mean but have trouble to take the no-data-values into account.

def nanmean(old_data, new_data, old_nodata = -10000, new_nodata = -10000, index=None, roff=None, coff=None):
    old = np.where(old_data == old_nodata, np.nan, old_data)
    new = np.where(new_data == new_nodata, np.nan, new_data)
    old_data[:] = np.nanmean([old, new], axis = 0)



mosaic, out_trans = merge(src_files_to_mosaic, method= nanmean)

That is my function, if I use first/last or min/max as method everything seems to work perfectly fine.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP