1

I have a function that I would like to map over an image collection:

var moisture = function (img, driest, wettest){
  var img = img.clip(table).select('VV')
  var sensitivity = wettest.subtract(driest); 
  var SMmax=0.32; 
  var SMmin=0.05;
  var calculateSSM = function (image){ return image.addBands(((image.subtract(driest)).divide(sensitivity))
  .multiply(SMmax-SMmin).add(SMmin)); }; 
  var ssm = calculateSSM(img) 
  var ssm = ssm.select('VV_1').rename('moisture');
  return ssm}

var coll2014 = ee.ImageCollection('COPERNICUS/S1_GRD_FLOAT') 
  .filterBounds(table) 
  .filterDate('2014-08-15','2014-12-31')
  .map(function (img) {return ee.Image(img).log10().multiply(10.0)});
  
var dry2014 = coll2014.min()
var wet2014 = coll2014.max()

How can I pass driest and wettest? I tryed

var add = moisture.bind (null, dry2014, wet2014)
var moisture2014 = coll2014.map(add)

but it doesn't seem to work. Or, even better, is there a way to define dry2014 and wet2014 inside the function? Thank you :)

benedetta
  • 33
  • 2

1 Answers1

0

You're binding the 1st and 2nd arguments, but driest and wettest are the 2nd and 3rd arguments. There is no way to skip arguments when using bind().

So use an anonymous function with map()

var moisture2014 = coll2014.map(fuction(img) { 
    return moisture(img, dry2014, wet2014); 
});
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you Barmar, maybe I am missing something or there is a different syntax in GEE. [link](https://code.earthengine.google.com/72986cef06e1badb29c68a6e4064a74e) I get a SyntaxError – benedetta Sep 25 '21 at 15:59
  • 1
    That link doesn't work for me because I don't have an Earth Engine account. – Barmar Sep 25 '21 at 16:02
  • 1
    Use traditional function syntax instead of an arrow function. `function(img) { return moisture(img, dry2014, wet2014); }` – Barmar Sep 25 '21 at 16:03
  • The token '=>' does not exist. This is not applied on gee. – 66lotte Nov 03 '22 at 18:24
  • 1
    @Lotte I've updated the answer to use traditional function syntax. – Barmar Nov 03 '22 at 19:27