I'm trying to perform ANIR index calculation on my image collection. I'm having trouble writing the code in the right way. ANIR index formula is :


(a2, b2 and c1, are Euclidean distances between bands B4, B8, B11/B12 respectively).

This is the function I have written so far-

var addANIR = function(image) {
  var ANIR = image.expression(
    'B4': image.select('B4'),
    'B8': image.select('B8'),
    'B11': image.select('B11'),
    'top':A.pow(2).add(B.pow(2)).add((C).pow(2))/ (ee.Number(2).multiply(A).multiply(B)),
    'cosin': top.cos()

  //NDVI index
  return image.addBands(ANIR.add(ee.Image(0.0)));
  //Add 0.0 value to NDVI (currently not in use)

This function gives me an Error. What is wrong with the function/code?


I've never calculated this index, and am not convinced I got it completely right. But based on what you provided, it could look something like this:


var addANIR = function(image) {
  var a = ee.Image().expression(
    'sqrt((832.8 - 644.6)**2 + (i.B8 - i.B4)**2)', {i: image}
  var b = ee.Image().expression(
    'sqrt((1613.7 - 832.8)**2 + (i.B11 - i.B8)**2)', {i: image}
  var c = ee.Image().expression(
    'sqrt((1613.7 - 644.6)**2 + (i.B11 - i.B4)**2)', {i: image}
  var anir = ee.Image().expression(
    '1 / cos((a**2 + b**2 + c**2) / (2 * a * b))', {a: a, b: b, c: c}
  return image.addBands(anir)  
| improve this answer | |
  • Thanks a lot, it works! – user166621 Sep 16 at 12:28

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.