This guide explains how to create mathematical expressions to calculate custom spectral indices in the RAVI plugin. It also provides practical examples and important tips to avoid common mistakes.
Sentinel-2 provides the following bands that you can use in your expressions:
Band (use it in the expression) | Name | Description | Wavelength | Spatial Resolution |
---|---|---|---|---|
B1 | Coastal aerosol | Coastal aerosol | 443 nm | 60 m |
B2 | Blue | Blue | 490 nm | 10 m |
B3 | Green | Green | 560 nm | 10 m |
B4 | Red | Red | 665 nm | 10 m |
B5 | Red Edge 1 | Red Edge 1 | 705 nm | 20 m |
B6 | Red Edge 2 | Red Edge 2 | 740 nm | 20 m |
B7 | Red Edge 3 | Red Edge 3 | 783 nm | 20 m |
B8 | NIR | Near Infrared | 842 nm | 10 m |
B8A | Narrow NIR | Narrow Near Infrared | 865 nm | 20 m |
B9 | Water vapor | Water vapor | 940 nm | 60 m |
B11 | SWIR 1 | Shortwave Infrared 1 | 1610 nm | 20 m |
B12 | SWIR 2 | Shortwave Infrared 2 | 2190 nm | 20 m |
+
(addition)-
(subtraction)*
(multiplication)/
(division)**
(exponentiation)>
(greater than)<
(less than)>=
(greater than or equal to)<=
(less than or equal to)==
(equal to)!=
(not equal to)&&
(logical AND)||
(logical OR)!
(logical NOT)sqrt(x)
- Square root of xabs(x)
- Absolute value of xmin(x, y)
- Minimum value between x and ymax(x, y)
- Maximum value between x and ylog(x)
- Natural logarithm of xexp(x)
- Exponential function \( e^x \)sin(x)
, cos(x)
, tan(x)
- Trigonometric functionsround(x)
- Round x to the nearest integerfloor(x)
- Round x down to the nearest integerceil(x)
- Round x up to the nearest integerpow(x, y)
- Raise x to the power of y(B8 - B4) / (B8 + B4)
2.5 * ((B8 - B4) / (B8 + 6 * B4 - 7.5 * B2 + 1))
(1 + 0.5) * ((B8 - B4) / (B8 + B4 + 0.5))
(B8 - B5) / (B8 + B5)
(B8 - B11) / (B8 + B11)
This expression calculates NDVI only when the red band (B4) is greater than 0.2. Otherwise, it returns 0:
(B4 > 0.2) ? ((B8 - B4) / (B8 + B4)) : 0
This expression calculates NDMI only when the SWIR1 band (B11) is greater than 0.1. Otherwise, it returns -1:
(B11 > 0.1) ? ((B8 - B11) / (B8 + B11)) : -1
This expression calculates NDVI only when both the red band (B4) is greater than 0.2 and the NIR band (B8) is greater than 0.3. Otherwise, it returns 0:
(B4 > 0.2 && B8 > 0.3) ? ((B8 - B4) / (B8 + B4)) : 0
**
for exponentiation.When creating complex expressions, test them incrementally to ensure they work as expected. Extreme values or division by zero can cause unexpected results.