# !pip install geemap rio-cogeo
import geemap
url = 'https://github.com/giswqs/leafmap/raw/master/examples/data/cog.tif'
in_cog = 'cog.tif'
out_cog = "ndvi.tif"
Download a sample dataset.
geemap.download_from_url(url, in_cog)
Convert image to numpy array.
arr = geemap.image_to_numpy(in_cog)
arr.shape
Computer NDVI.
ndvi = (arr[3] - arr[0]) / (arr[3] + arr[0])
ndvi.shape
Convert numpy array to COG.
geemap.numpy_to_cog(ndvi, out_cog, profile=in_cog)
m = geemap.Map()
m.add_raster(in_cog, band=[4, 1, 2], layer_name="Color infrared")
m.add_raster(out_cog, palette="Greens", layer_name="NDVI")
m