band_arithmetic#

geodesic.boson.band_arithmetic(expression, asset_name, band_name='calculated')[source]#

Creates a new asset by applying a band arithmetic expression to an existing asset.

Asset bands are represented using the following syntax:

  • {“band_name”: band_index}: asset band from band index

  • {“asset_name”: “band_name”}: asset band from band name

Addition, subtraction, multiplication, division, and functions are supported. See below for the full list of functions.

Parameters:
  • expression (str) – band arithmetic expression to apply

  • asset_name (str) – name of the asset to create

  • band_name (str) – name of the band to create. Defaults to “calculated”

Returns:

middleware to apply band arithmetic to an asset

Return type:

Middleware

Examples

>>> # Create a new asset by adding the "red" and "nir" bands together
>>> transform = band_arithmetic(
...     expression='{"red": 0} + {"nir": 0}',
...     asset_name="red_nir_sum"
... )
>>> # Create a new asset by adding 10 to the "red" band
>>> transform = band_arithmetic(
...     expression='{"image": "red"} + 10',
...     asset_name="red_plus_10"
... )
>>> # Create a new asset with a log scale of the "VV" band "10 * log10({"image": "VV"})"
>>> transform = band_arithmetic(
...     expression='10 * log10({"image": "VV"})',
        asset_name="log_scale"
... )
>>> # Create a new asset by masking the "nir" band where the "red" band is greater than 1000
>>> transform = band_arithmetic(
...     expression='if(gt({"red": 0}, 1000), {"nir": 0}, 0)',
...     asset_name="masked_nir"
... )

Functions:

  • exp(x) - e^x

  • sqrt(x) - square root of x

  • log(x, b) - log of x with base b, if no base is provided the default is e

  • log10(x) - log base 10 of x

  • abs(x) - absolute value of x

  • sin(x) - sine of x

  • cos(x) - cosine of x

  • tan(x) - tangent of x

  • floor(x) - rounds x down to nearest integer

  • ceil(x) - rounds x up to nearest integer

  • round(x) - rounds x up or down to nearest integer

  • pow(x, y) - x to the power of y

  • min(x, y, z) - smallest value of x, y, z - takes 2 or more arguments

  • max(x, y, z) - largest value of x, y, z - takes 2 or more arguments

  • clamp(x, min, max) - returns x unless x is greater than max or less than min

Comparison Functions:

  • gt(x, y) - returns 1 if x > y, else 0

  • lt(x, y) - returns 1 if x < y, else 0

  • gte(x, y) - returns 1 if x >= y, else 0

  • lte(x, y) - returns 1 if x <= y, else 0

  • eq(x, y) - returns 1 if x == y, else 0

  • neq(x, y) - returns 1 if x != y, else 0

Conditional Functions:

  • if(condition, true_value, false_value) - returns true_value if condition != 0, else

    false_value

Logical Operators:

  • and(x, y, …) - returns 1 if all arguments are non-zero, else 0

  • or(x, y, …) - returns 1 if any argument is non-zero, else 0

  • not(x) - returns 1 if x is 0, else 0