1

I have a function that takes an ImageCollection and sets a mean value as a property for another ImageCollection.

var DHW = HS_SSTA_7d.map(function(im) {
                    var res = im.reduceRegion(ee.Reducer.mean(), reefs_500, 500); 
                    // calc mean to be called and set as property
                    return im.set("sst_mean", res.get("sst"))});

I then use this to filter out values great than 1 from my ImageCollection.

 var DHW_non_null = DHW.filter(ee.Filter.notNull(["sst_mean"]))
                    .filterMetadata("sst_mean", "greater_than", 1);

Is there a way of setting the band value as a property without reducing it, so it can be filtered? Basically I want to remove any images/pixels which are great than one. I tried to set the band as a property using the two methods below but it didn't seem to work.

 var DHW = HS_SSTA_7d.map(function(im) {
                    return im.set("sst_mean", im.get("sst"))});


 var DHW1 = ee.ImageCollection(HS_SSTA_7d_AsAList.map(function(im){
     var sst = ee.Image(im).get('sst');
     return ee.Image(im).set("sst_mean", sst);
     }));

Is the right way of doing things, or is there a way of filtering your data without setting the band values as a property? A link to my full code ishere

1 Answer 1

3

Yes, you can store an image (with one band or more) as a property,

var image = ee.Image.constant(1);
print(image.set('foo', image));

but this will not allow you to filter a collection on pixel values; every filter either includes or excludes the entire image based on simple value (string/number) or geometry characteristics, not pixels.

If you want to remove individual pixels whose values are greater than one, then you can do that with masking.

var noPixelsGreaterThanOne = collection.map(function (image) {
  return image.updateMask(image.select('sst').lte(1));
});

This will remove the pixel (in all bands) wherever the 'sst' band of that image is greater than one. If you then, for example, mosaic the collection processed this way, then the mosaic will use only the values that weren't masked away; the same applies to a mean or any other reduction.

2
  • Thanks Kevin, so you could use .gte in the same way and that would remove any pixels less than 1 right? Sep 30, 2020 at 8:34
  • @mikejwilliamson Yes. And in general you can use anything that computes an image with values between 0 and 1.
    – Kevin Reid
    Sep 30, 2020 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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