0

I don't understand this error. I tried to Mask an image with another Image(containing only 0 and 1). It doesn't recognize the Mask as input image2.

Link to GEE Code

This Line Created following Error:

var MaskedBAI = First.updateMask(threshold);

Error: Required argument (image2) missing to function: Image.first(image1, image2)

Selects the value of the first value for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.

Args:

image1 (Image): The image from which the left operand bands are taken. image2 (Image): The image from which the right operand bands are taken.

mile Gracie

Val
  • 6,585
  • 5
  • 22
  • 52
Alexander Vocaet
  • 188
  • 1
  • 10

1 Answers1

0

The masking in your code works just fine, your issue is with the use of .first().

If used on an ImageCollection as you do in the beginning of your script, the first image of the collection is returned.

If used on an Image it

Selects the value of the first value for each matched pair of bands in image1 and image2

as the description says. Which I guess not what you want. So the solution is easy, just get rid of the .first():

Map.addLayer(MaskedBAI,BAIparam ,'BAI')

Just to mention, no pixel is below your threshold of 0.3, which means the entire mask is 0, which in turn will show you nothing for MaskedBAI ... just in case you're wondering.

Val
  • 6,585
  • 5
  • 22
  • 52
  • @AlexanderVocaet I mean in your `Map.addLayer` call, you add the `.first` method call on your image `MaskedBAI`, which is not necessary and also the reason of your error. Remove it (like I did in my post above) and everything should work as intended. – Val Oct 18 '18 at 14:21
  • I do not understand what u mean by getting rid of the .first . I printed both Images: threshold and First, both are Image type; also my mask isn't entirely 0, it has some Areas with 1 – Alexander Vocaet Oct 18 '18 at 14:21
  • Thanks so much ! it now works, but how does the Map.addlayer influence the .mask command? would you please be so kind an tell me? i really want to understadn whats going on – Alexander Vocaet Oct 18 '18 at 14:24
  • I understand the confusion ... this is due to how GEE works. Processing steps are constructed locally and then only evaluated by the server once another function requires it, meaning your masked raster won't be actually calculated by GEE until you want to map or print it. Consider reading the user manual's section on [how GEE works](https://developers.google.com/earth-engine/concepts_overview) which goes a bit more into detail. Glad everything worked out! – Val Oct 18 '18 at 14:27