TransWikia.com

Google Earth Engine: Error for mapping expression function over feature collection

Geographic Information Systems Asked on September 2, 2021

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)
.filterBounds(reefs_buffer)
.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)
 print(sstHS_collection)
 reefs_sstMean.map(sstHS_function)

One Answer

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.

Answered by mikejwilliamson on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP