Example payload for using the bandmath tool

The bandmath tool applies band math expressions to the bands of input files to produce derived outputs and indices for analysis. Common indices include the Normalized Difference Vegetation Index (NDVI), the Enhanced Vegetation Index (EVI), and the Normalized Difference Water Index (NDWI).

Input bands are referenced as b1, b2, b3, and so on, where b1 equals band 1. For each band expression, the bandmath tool supports standard arithmetic operations and simple math operators provided by the Python NumPy package. For a list of supported mathematical functions, see bandmath supported NumPy math routines.

The parameters of the bandmath tool define how each output band in the derivative product is produced, referencing the product inputs' original bands. Band math expressions cannot reference neighboring pixels, because non-local operations are not supported. The tool can calculate up to 15 bands for an item. Input band parameters cannot be skipped. For example, if the b4 parameter is provided, then b1, b2, and b3 parameters are also required.

  • b1 (string, required): an expression defining how output band 1 is computed.
  • b2 (string, optional): an expression defining how output band 2 is computed.
  • ...
  • b15 (string, optional): an expression defining how output band 15 is computed.
  • pixel_type (string, optional): the output pixel type. By default this value is Auto, the same as the input file. 8U (8-bit unsigned), 16U (16-bit unsigned), 16S (16-bit signed), and 32R (32-bit floating point) may also be used depending on the type of equation or index being calculated.

The output of the following example is a bundle that includes all four bands of the original file, a fourth band that is the arc tangent of the original first band, and a fifth band with NDVI values.

{
  "name": "ndvi_bandmath_example",
  "products": [
    {
      "item_ids": [
        "20220124_062250_31_220b"
      ],
      "item_type": "PSScene",
      "product_bundle": "analytic_udm2"
    }
  ],
  "tools": [
    {
      "bandmath": {
        "b1": "b1",
        "b2": "b2",
        "b3": "b3",
        "b4": "arctan(b1)",
        "b5": "(b4-b3)/(b4+b3)",
        "pixel_type": "32R"
      }
    }
  ]
}
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.