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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"expression": "<expression>",
"bands": "<bands>"
},
"name": "spectral_custom"
}
}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. |