1

I'm trying to write the equation for the MCARI vegetation index in raster calculator using WorldView-2 imagery, but can't get it right. Here is the original formula:

MCARI = [(RedEdge – Red) – 0.2 × (RedEdge - Green)] × (RedEdge ÷ Red)

Here is where I'm at:

[float((B6-B5)-0.2) * float(B6-B3)] * float(B6)/(B5)

The error I get is:

float() argument must be a string or a number (error 000539)

I'm thinking my float placement or parens placement is not correct.

2
  • Float() may be case sensitive.
    – Aaron
    Dec 6, 2019 at 16:21
  • sorry, that was a typo while writing the question.
    – Nate
    Dec 6, 2019 at 16:23

1 Answer 1

1

float() is a python builtin. You can only pass strings or numbers to it.

What you need is Float() which is from the arcpy.sa package (which is already imported when using the raster calculator, you only need to import it if writing python scripts).

Something like:

(Float(B6)-B5-0.2) * (Float(B6)-B3) * Float(B6)/B5

Note how I've only put Float around single bands - that's because you can run into integer overflow and truncation issues using Float(B6-B5) as the floating point conversion isn't done until after the subtraction. This is more of a best practice thing, some software will handle the type conversion implicitly and you never need to think about it, but others won't, for example in numpy:

>>> import numpy as np

>>> a=np.ones(1, dtype=np.uint8)

>>> a
array([1], dtype=uint8)

>>> float(a - 2)  # should == -1.0 right...?
255.0             # nope...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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