My goal is to Filter
an ImageCollection
to contain only Images with uniform coverage within a given AOI (Images that have to 'holes' / masked pixels within an AOI). I'm trying to do it by mapping the collection over ee.Reducer.allNonZero()
setting isNotEmpty
flag and then filtering images by corresponding flags.
This is a script I created (EE code version):
var NO2_coll = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_NO2")
.select('tropospheric_NO2_column_number_density');
var aoi = ee.Geometry.Polygon(ee.List([
[9.18804289906566, 45.468566496899996], [10.203754688320892, 45.468566496899996],
[10.203754688320892,45.695567257444594], [9.18804289906566, 45.695567257444594],
[9.18804289906566, 45.468566496899996]]));
var date_from = '2020-01-04';
var date_to = '2020-01-05';
function setEmptyFlag (image) {
var isNotEmpty = image.reduceRegion({
reducer: ee.Reducer.allNonZero(),
geometry: aoi,
scale: 7000,
}).values().get(0);
return image.set('isNotEmpty', isNotEmpty);
}
var coll_filt = NO2_coll.filterBounds(aoi).filter(ee.Filter.date(date_from, date_to));
var coll_with_zero_flag = coll_filt.map(setEmptyFlag);
var coll_filt_clean = coll_with_zero_flag.filterMetadata('isNotEmpty', 'equals', 1);
var single_scene = coll_filt_clean.first();
Map.addLayer(aoi);
Map.addLayer(single_scene);
Map.centerObject(aoi);
But ee.Reducer.allNonZero()
always returnes '1' no matter the presence of masked pixels within AOI.
How do I fix it?