0

I want to create a time-series from an image-collection resulting in a list with the time-series values. It could be however, that some of the images in the collection are completely masked (i.e. have no valid pixels) in my Area-of-Interest. I create the time-series in GEE using this script (the first line is just to make a dummy image-collection, which has one fully masked image) (https://code.earthengine.google.com/9aa3e051390d72fac3fa783b009b08b4):

var img_col = ee.ImageCollection.fromImages([ee.Image(5), 
                                             ee.Image(7).updateMask(ee.Image(0)), 
                                             ee.Image(10)]);

var create_ts = function(img){

  var value = img.reduceRegion({reducer: ee.Reducer.mean(), geometry: aoi, scale: 10000});

  var ft = ee.Feature(null, value);

  return ft;
};

var ts = img_col.map(create_ts);

print(ts);
print(ts.aggregate_array('constant'));

The image-collection contains three images, the printed ts shows only two values however:

[5, 10]

but I would preferably like to have something like this:

[5, null, 10]

as output. If it's not possible to have "null" values in a list/array, then some kind of No-Data-Value would be acceptable as well, like for example:

[5, -9999, 10]
0

From this question Property with null-value disappearing from feature when creating a feature-collection in GEE it follows that the "[5, null, 10]"-option is not feasible.

Adjusting the code like this solves the problem (with an option to pass multiple reducers to the reduceRegion-method, because its unnecessary to explicitly write the key-names) (https://code.earthengine.google.com/f7512d21e29ee477f3a8664a98675793):

var img_col = ee.ImageCollection.fromImages([ee.Image(5), 
                                             ee.Image(7).updateMask(ee.Image(0)), 
                                             ee.Image(10)]);

var create_ts = function(img){

  var value = img.reduceRegion({reducer: ee.Reducer.mean(), geometry: aoi, scale: 10000});

  value = value.map(function(key, val){return ee.List([val, -9999]).reduce(ee.Reducer.firstNonNull())});

  var ft = ee.Feature(null, value);

  return ft;
};

var ts = img_col.map(create_ts);

print(ts);
print(ts.aggregate_array('constant'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.