spectral_custom
Compute custom spectral indices by evaluating band math expressions with a secure parser. Supports arithmetic operators and named band variables.
Instructions
Evaluate a custom band math expression using a safe expression parser. Supports basic arithmetic (+, -, *, /), parentheses, numeric literals, and band variable names. Example: expression "(b4 - b3) / (b4 + b3)" with bands {"b3": 0.2, "b4": 0.8} computes NDVI. No eval() is used — the expression is parsed with a secure recursive-descent parser that only permits numbers, named band variables, arithmetic operators, and parentheses.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bands | Yes | Object mapping band variable names to their reflectance values. Keys must match the variable names used in the expression. Example: {"b3": 0.2, "b4": 0.8, "b5": 0.6}. | |
| expression | Yes | Band math expression to evaluate. Supports: numbers, band variable names (matching keys in the bands object), operators (+, -, *, /), and parentheses. Examples: '(b4 - b3) / (b4 + b3)', 'nir * 2 - red', '(swir1 + red) / (nir + blue)'. No function calls or arbitrary code allowed. |