@@ -455,3 +455,61 @@ def harmonize_tool(target_sensor: str) -> dict:
455455 raise ClientError (e )
456456
457457 return _tool ('harmonize' , {'target_sensor' : target_sensor })
458+
459+
460+ def band_math_tool (b1 : str ,
461+ b2 : Optional [str ] = None ,
462+ b3 : Optional [str ] = None ,
463+ b4 : Optional [str ] = None ,
464+ b5 : Optional [str ] = None ,
465+ b6 : Optional [str ] = None ,
466+ b7 : Optional [str ] = None ,
467+ b8 : Optional [str ] = None ,
468+ b9 : Optional [str ] = None ,
469+ b10 : Optional [str ] = None ,
470+ b11 : Optional [str ] = None ,
471+ b12 : Optional [str ] = None ,
472+ b13 : Optional [str ] = None ,
473+ b14 : Optional [str ] = None ,
474+ b15 : Optional [str ] = None ,
475+ pixel_type : str = specs .BAND_MATH_PIXEL_TYPE_DEFAULT ):
476+ '''Specify an Orders API band math tool.
477+
478+ The parameters of the bandmath tool define how each output band in the
479+ derivative product should be produced, referencing the product inputs’
480+ original bands. Band math expressions may not reference neighboring pixels,
481+ as non-local operations are not supported. The tool can calculate up to 15
482+ bands for an item. Input band parameters may not be skipped. For example,
483+ if the b4 parameter is provided, then b1, b2, and b3 parameters are also
484+ required.
485+
486+ For each band expression, the bandmath tool supports normal arithmetic
487+ operations and simple math operators offered in the Python numpy package.
488+ (For a list of supported mathematical functions, see
489+ [Bandmath supported numpy math routines](https://developers.planet.com/apis/orders/bandmath-numpy-routines/)).
490+
491+ One bandmath imagery output file is produced for each product bundle, with
492+ output bands derived from the band math expressions. nodata pixels are
493+ processed with the band math equation. These files have “_bandmath”
494+ appended to their file names.
495+
496+ The tool passes through UDM, RPC, and XML files, and does not update values
497+ in these files.
498+
499+ Parameters:
500+ b1-b15: An expression defining how the output band should be computed.
501+ pixel_type: A value indicating what the output pixel type should be.
502+
503+ Raises:
504+ planet.exceptions.ClientError: If pixel_type is not valid.
505+ ''' # noqa
506+ try :
507+ pixel_type = specs .get_match (pixel_type ,
508+ specs .BAND_MATH_PIXEL_TYPE ,
509+ 'pixel_type' )
510+ except specs .SpecificationException as e :
511+ raise ClientError (e )
512+
513+ # e.g. {"b1": "b1", "b2":"arctan(b1)"} if b1 and b2 are specified
514+ parameters = dict ((k , v ) for k , v in locals ().items () if v )
515+ return _tool ('bandmath' , parameters )
0 commit comments