1

I have a function which assigns a score depend on the value of a band, which I then map to an image collection.

However, in some cases, I have null values, where no value is given. In these cases I'd like to convert the null values to 0. I tried to set null values as zero in the code, but I'm getting an image error. My new code, with the extra line is below.

function currentHS_function(image){
  var currentHS = image.expression(
 "(b('current') < 0.13) ? 1.0" +
 ": (b('current') > 0.15) ? 0.0" +
 ": (b('current') = null) ? 0.0" + // new line - set null values as 0
 ": -50.0*current + 15.0/2.0 ",
 {"current" : image});
   return currentHS;
 }

// apply heath score function to image collection
var currentHS_collection = currentSpeed.map(currentHS_function);
1

One thing you can do is to unmask the image using a proxy value before the expression and then catch that proxy value:

function currentHS_function(image){
  var proxy = -999
  image = image.unmask(proxy)
  var currentHS = image.expression(
 "(b('current') == proxy) ? 0.0" +
 ": (b('current') < 0.13) ? 1.0" +
 ": (b('current') > 0.15) ? 0.0" +
 ": -50.0*current + 15.0/2.0 ",
 {"current" : image, "proxy": proxy});
   return currentHS;
 }

In this case -999 is the proxy value, but you can use one of your own

2
  • So you're setting values of masked images to -999 then adding that to the equation? Is that correct? – mikejwilliamson Jun 22 '20 at 14:02
  • yes, that is correct – Rodrigo E. Principe Jun 23 '20 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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