I am trying to compute NDVI of an image collection with 10 images in it. I created an ndvi function and mapped that over the image collection. After that I want reduce the collection to a single image with median reducer. However earth engine returns an image with no values.
When I select the first image from the mapped collection, that loads just fine in QGIS however with any reducer / mosaic it returns nothing
Please suggest how to fix it.
This is my code
https://colab.research.google.com/drive/1nD-AIZgzEQOs2Vf8G749o87A0RXiIrMj?usp=sharing
# imports
!pip install -U earthengine-api --no-deps --quiet
import ee
from google.colab import auth
auth.authenticate_user()
ee.Authenticate()
ee.Initialize()
# Study Area
xMin = 70;
yMin = 33;
xMax = 70.3;
yMax = 33.3;
area = ee.Geometry.Rectangle([[xMin, yMin],[xMax, yMax]])
# Filtering an image Collection
s2 = ee.ImageCollection("COPERNICUS/S2_SR").filterBounds(area).filterDate('2022-05-01','2022-05-25')
print(s2.getInfo())
print(s2.first().bandNames().getInfo())
# mapping over image collection
def getNDVI(image):
# Normalized difference vegetation index (NDVI)
ndvi = image.normalizedDifference(['B8','B4']).rename("ndvi")
return(ndvi.copyProperties(image,['system:time_start','system:time_end']))
mapped = s2.map(getNDVI)
print(mapped.size().getInfo())
# Reducing to median image
median = mapped.median().clip(area)
print(median.getInfo())
#downloading the tiff
dl = median.getDownloadURL()
print(dl)
This is how the first NDVI image appears from the mapped collection
Best Answer
You can specify the
getDownloadURL()
params and specify the scale you want to export your imagery to. For more details, look here.