Google Earth Engine – Calling ‘Mean’ on ImageCollection Produces Scalar Value

google-earth-enginegoogle-earth-engine-python-api

I define the following ImageCollection, which is 24 hourly images from a single day:

collection = ee.ImageCollection("ECMWF/ERA5_LAND/HOURLY").select("total_precipitation")
collection = collection.filterDate("2020-01-01", "2020-01-02")

Then I download the first image in the collection:

region = ee.Geometry.Polygon([
    (-119.69680109161911, 37.9180436245507),
    (-119.23634853488707, 37.9180436245507),
    (-119.23634853488707, 37.57830484843708),
    (-119.69680109161911, 37.57830484843708),
    (-119.69680109161911, 37.9180436245507)
])
img = collection.first()
task = ee.batch.Export.image.toDrive(
    img.toFloat(),
    description="sample_hourly_image",
    fileNamePrefix="sample_hourly_image",
    region=region,
    fileFormat="GeoTIFF")
task.start()

After downloading I can open this image and convert to a numpy array, which looks as follows – with 4 rows and 6 columns:

numpy hourly array

Then I want to take the mean of all 24 hourly images in the collection to produce a single image of mean temperature for that day. This is what I tried:

daily_img = collection.mean()
task = ee.batch.Export.image.toDrive(
    daily_img.toFloat(),
    description="sample_daily_image",
    fileNamePrefix="sample_daily_image",
    region=region,
    fileFormat="GeoTIFF",
)
task.start()

However this time when I download the image and convert to a numpy array it only has a single scalar value:

enter image description here

What am I doing wrong here?

Best Answer

You should set the scale and crs (or crsTransform and crs) parameters in the export call. When you reduce an image collection the result has a default projection that has 1-degree pixel size in WGS84 EPSG:4326 coordinate reference system. It does this because it is possible that images in the collection have different projections. Currently, because your region is pretty small and you are accepting defaults in the export, your exported image has a single 1-degree pixel; set the crs and scale to that of the original data. Read more about the default projection at The default projection.

Related Question