3

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?

2 Answers 2

3

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')
1
  • Thanks, that's definitely helpful. A colleague helped out and I have posted the answer. Oct 24, 2019 at 10:56
1

A colleague of mine pointed me in the right direction answering this, so thought I'd post the answer.

var series_above1 = series.map(function(im) {
                    var res = im.reduceRegion(ee.Reducer.mean(), PB, 2500)
                    return im.set("sst_mean", res.get("sst"))})

print("number of non-null observation", 
series_above1.filter(ee.Filter.notNull(["sst_mean"])).size())
print("number of observations above 1", 
series_above1.filter(ee.Filter.notNull(["sst_mean"]))
.filterMetadata("sst_mean", "greater_than", 1).size())

print(series1)

Your Answer

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

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