Google Earth Engine – Returning Data for Points but Not for Polygons

google-earth-enginegoogle-earth-engine-python-apipolygon

When I use this code (Python API) to get data per point, it works fine:

def calcMean(img):
    mean = img.reduceRegion(ee.Reducer.mean(), polygon).get(band)
    return img.set('date', img.date().format()).set('mean', mean)


polygon = ee.Geometry.Point([32.58,35.17])
band = 'temperature_2m'
sensor = "ECMWF/ERA5_LAND/HOURLY"
StartDate = "2022-05-01" 
EndDate = "2022-05-03" 
col = ee.ImageCollection(sensor).filterDate(StartDate,EndDate).filterBounds(polygon).map(calcMean)
values = col.reduceColumns(ee.Reducer.toList(2), ['date', 'mean']).values().get(0)
data = ee.List(values)
df = pd.DataFrame(data.getInfo())

enter image description here

However, when I run the same code, only with polygon, I get no data (also no error).
This is how the polygon looks like:

polygon = ee.Geometry.Polygon(geometry)


>> polygon

ee.Geometry({
  "functionInvocationValue": {
    "functionName": "GeometryConstructors.Polygon",
    "arguments": {
      "coordinates": {
        "constantValue": [
          [
            [
              35.191598,
              32.585162
            ],
            [
              35.191595,
              32.585148
            ],
            [
              35.191587,
              32.585135
            ],
            [
              35.191575,
              32.585126
            ],
            [
              35.19156,
              32.58512
            ],
            [
              35.191544,
              32.585118
            ],
            [
              35.191527,
              32.58512
            ],
            [
              35.191513,
              32.585127
            ],
            [
              35.191501,
              32.585137
            ],
            [
              35.191494,
              32.58515
            ],
            [
              35.191491,
              32.585164
            ],
            [
              35.191494,
              32.585178
            ],
            [
              35.191502,
              32.58519
            ],
            [
              35.191514,
              32.5852
            ],
            [
              35.191529,
              32.585206
            ],
            [
              35.191546,
              32.585208
            ],
            [
              35.191562,
              32.585205
            ],
            [
              35.191577,
              32.585199
            ],
            [
              35.191588,
              32.585188
            ],
            [
              35.191596,
              32.585176
            ],
            [
              35.191598,
              32.585162
            ]
          ]
        ]
      },
      "evenOdd": {
        "constantValue": true
      }
    }
  }
})

Why is that?

Best Answer

You haven't specified a pixel size so your reduceRegion is running with the image's projection of 10km / pixel. The mean reducer is weighted and the weighting is determined by how much of the polygon is covered by the pixel. In this case, the polygon is so small, compared to the pixel size, that it ends up with 0 weight.

Either set the reducer to be unweighted, or specify a scale in the reduceRegion (10 should work fine).

Related Question