I have a function that calculates the average rainfall over the first 6 months of the year over a 30 year period. The function receives a geometry, and returns the mean of pixels inside the geometry.
In some cases, with small polygons (about the size of a pixel) the result is NULL. it is not always the case, in tests I have made considerably smaller polygons that have given a result. Here is a code snippet that creates the null value.
var geometry = /* color: #0b4a8b */ee.Geometry.Polygon(
[[[24.36479088838034, -33.36746983993103],
[24.36024158347382, -33.42516561247864],
[24.438305535991674, -33.4257574802331],
[24.43181381987206, -33.37553285357873]]]);
var rain_temp = ee.ImageCollection("ECMWF/ERA5_LAND/MONTHLY_AGGR");
Map.addLayer(geometry);
Map.centerObject(geometry);
var avgRainfall6Coldest = function(polygon, startMonth){
var startYear = 1990;
var endYear = 2020;
var rain_tempYears = rain_temp.filterDate(ee.Date.fromYMD(startYear,1,1),ee.Date.fromYMD(endYear,1,1));
rain_tempYears = rain_tempYears.filterBounds(polygon);
var monthlyAverages = function(month){
return rain_tempYears.filter(ee.Filter.calendarRange(month,month,"month")).reduce(ee.Reducer.mean());
};
var yearlyAvg = ee.ImageCollection(ee.List.sequence(1,6).map(monthlyAverages)).reduce(ee.Reducer.sum());
var imageVisParam = {"opacity":1,"bands":["total_precipitation_sum_mean_sum"],"min":0,"max":0.600,"gamma":1};
Map.addLayer(yearlyAvg,imageVisParam);
print(rain_tempYears.aggregate_count_distinct("year"));
return yearlyAvg.select("total_precipitation_sum_mean_sum").reduceRegion(ee.Reducer.mean(),polygon);
};
print(avgRainfall6Coldest(geometry));
Link to the script in Earth Engine. https://code.earthengine.google.com/ec3cfbafb787c71658497e7b910d9acf
Any idea why this is occurring, and could there be a workaround?