[GIS] Adding band value as a property in Google Earth Engine

filtergoogle-earth-enginejavascripttime series

I have an image collection of different anomaly values for a specific time period. I'm simply looking to count how many of these values are over 1 in my time period.

This is my code

// create collection
 var collection = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
  .select('sst')
  .map(function(image){return image.clip(EEZ)});

// get mean value over ten years
var reference = collection.filterDate('2002-01-01', '2012-12-31')
.sort('system:time_start', false);

//calculate anomaly for 2018
 var series = collection.filterDate('2018-01-01', '2018-12-31').map(function(image) {
return image.subtract(mean)
.set('system:time_start', image.get('system:time_start'));

I thought there may have been a way of adding the band value to a property for each image and then filtering the metadata of this collection for values 1 or over, but I can't seem to find a way of doing it.

Are there other ways of filtering/removing data values below specific targets?

Best Answer

It is not completely clear what you want hear? It helps if you provide an working example, for example in your script what is the variable mean doing? And what is your reference collection suggesting? Would you like a per pixel mean value and subtract or you want a mean for the entire reference period and all pixels?

I would say the logic you are describing should work, but some details would help? Perhaps this gives an idea of how to implement your logic (be aware, due to reduceRegions on large collections this is probably not the most efficient way of approaching your problem):

// create collection
 var collection = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
  .select('sst')
  .filterBounds(EEZ)
  .map(function(image){return image.clip(EEZ)});

print(collection.limit(10), 'collection')
// get mean value over ten years
var reference = collection.filterDate('2002-01-01', '2012-12-31')
    .sort('system:time_start', false);

var mean = ee.Image(reference.select('sst').reduce(ee.Reducer.mean()).select('sst_mean'));
print(mean, 'mean')
Map.addLayer(mean)



//calculate anomaly for 2018
 var series = collection.filterDate('2018-01-01', '2018-12-31').map(function(image) {

      // difference
      var dif = image.subtract(mean)
      // amount of pixels > 0
      var number = ee.Number(dif.gt(0).reduceRegion({
          reducer: ee.Reducer.count(),
          geometry: EEZ,    
        }).values().get(0));


      return image.subtract(mean) // what is mean?
        .set('system:time_start', image.get('system:time_start'))
        .set('dif', number)
 });

print(series, 'series')