I'm having an issue when trying to create a function to map over a feature collection.

I'm trying to create SST thresholds for several regions where over a certain SST value is 1, under another SST, value is 0 and in between is a linear function between those cut offs.

I tried this with a single image first and it looked like it had worked. Link here

However, I'd like to apply this to a featurecollection I've created , so I wanted to create a function of this and then map it over the collection. However I'm getting an error

Invalid argument specified for ee.List(): mean.

I think it is because I'm not defining mean correctly in the expression. I've tried lots of different options and can't figure it out. The code I'm using is here

var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst')
.filterDate(startDate, endDate)
.map(function(image){return image.clip(EEZ)}); //reefs_buffer

var sstMean = sst.reduce(ee.Reducer.mean())

print('sstMean', sstMean)

var reefs_sstMean = sstMean.reduceRegions({
  reducer: ee.Reducer.mean(),
  collection: reefs_buffer,
  scale: 30});

 print('reefs_sstMean', reefs_sstMean)

function sstHS_function(feature) {
   var sstReefs = feature.select('mean');
   var sstHS = sstReefs.expression(
"(b('mean') > 29.5) ? 1" +
 ": (b('mean')  < 24) ? 0" +
 ": 2/11*mean - 48/11 ",
 {'mean' : mean});
   return ee.Feature(sstHS);

 var sstHS_collection = reefs_sstMean.map(sstHS_function)
  • Can't really check without access to your feature collections of the reefs, which have not been shared, but, my suspicion is that the error lies in your expression(). Commented Oct 11, 2019 at 1:19

1 Answer 1


So after a bit of fiddling I managed to work out the issue. It turns out that rather I needed to apply the expression to the image collection, then calculate the means for the regions, rather than the other way around as I was doing initially.

So apply the expression to an image collection, then use the reduce functions to calculate the average expressions by time or region.

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.