When a band ratio isn’t enough, a Scripted insight lets you write the calculation yourself in the platform’s built-in expression language. It’s the most flexible insight type: multi-step formulas, conditionals, spectral and spatial functions β all computed on the imagery and rendered like any other insight. Choose Scripted as the type in the insight builder.
The code editor #
The Script section is a code editor with two helpers built in:
- Reference β opens the full language reference: every function and operator, grouped by category, with a one-line description and an example.
- Examples β inserts a worked reference program you can adapt.
As you type, the editor validates live and flags problems with a clickable line:column marker so you can jump straight to the error.
The language in a nutshell #
- Bands are referred to by their short names (for example
Rfor red,Nfor near-infrared) β the same band letters the instrument uses. letnames an intermediate result:let ratio = N / (R + eps).outputdeclares what the insight returns β a single band (the value of a named binding), optionally with a mask, or a three-band composite (r, g, b) for an RGB result.- Operators:
+ - * / ^, comparisons (>,<,>=,<=,!=), and per-pixel logic (and,or,not), plusif / else. - Constants:
pi,e, andepsβ a tiny value to add to denominators so you never divide by zero.
Function library #
Grouped as they appear in the Reference:
- Math β
sqrt,abs,log(natural),log10,exp. - Trigonometry β
sin,cos,tan,arctan,arctan2. - Comparison & range β
min,max,clip(x, lo, hi)to bound values. - Conditional β
where(condition, a, b)to pick per pixel. - Normalized difference β
ndiff(a, b)β the(aβb)/(a+b)you’d write for NDVI-style indices, in one call. - Spectral β
band_depth(absorption depth) andabsorption_pos(wavelength of maximum absorption). - Spatial filters β
focal_median(x, radius)to smooth speckle.
A simple example β a cloud-safe, smoothed NDVI clipped to a sensible range:
“ let ndvi = ndiff(N, R) output focal_median(clip(ndvi, -1.0, 1.0), 1) “
Output range, palette & legend #
Like other insights, set a Min and Max for the output and a Color Palette (see Range, palette and rendering in Creating Insights). Scripted insights can also produce a binary output β a true/false mask β in which case you set the label, color and an optional Transparent toggle for each of the two branches, so “false” pixels can drop out of the render entirely.
When to use it #
- A formula with steps or conditions a single expression can’t express β thresholds, masks, ratios of ratios.
- Combining spectral and spatial operations (e.g. compute an index, then median-filter it).
- Prototyping a new index precisely, then saving it for reuse or bundling into a Stack.
As with any insight, a Scripted insight runs on every instrument that carries the bands your script references β see One insight, many instruments in Creating Insights.