Package org.esa.snap.core.dataop.barithm
Class BandArithmetic
java.lang.Object
org.esa.snap.core.dataop.barithm.BandArithmetic
Provides band arithmetic utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareRastersEqualInSize(Product[] products, int defaultProductIndex, String... expressions) Determines whether all rasters which are referenced in the given expressions are compatible.static booleanareRastersEqualInSize(Product product, String... expressions) Determines whether all rasters which are referenced in the given expressions are compatible.static booleanareRastersEqualInSize(Term term) Determines whether all rasters which are referenced in a term are compatible.static WritableNamespacecreateDefaultNamespace(Product[] products, int contextProductIndex) Creates a default namespace for the product(s) given in an array.static WritableNamespacecreateDefaultNamespace(Product[] products, int contextProductIndex, ProductNamespacePrefixProvider... prefixProviders) Creates a default namespace for the product(s) given in an array.static StringcreateExternalName(String name) Create an external name from the given name.static voidDe-registers an existing global function.static voidDe-registers an existing global symbol.static StringgetProductNodeNamePrefix(Product product) Gets a symbol name prefix for the names of bands, tie point grids, flags, etc.static RasterDataSymbol[]getRefRasterDataSymbols(Term... terms) Utility method which returns all raster data symbols referenced in a given compiled band math expressions.static RasterDataNode[]getRefRasters(String expression, Product... products) Utility method which returns all raster data nodes referenced in the given band math expressions.static RasterDataNode[]getRefRasters(String expression, Product[] products, int contextProductIndex) Utility method which returns all raster data nodes referenced in the given band math expressions.static RasterDataNode[]getRefRasters(Term... terms) Utility method which returns all raster data nodes referenced in the given compiled band math expressions.static StringgetValidMaskExpression(String expression, Product[] products, int contextProductIndex, String validMaskExpression) static StringgetValidMaskExpression(String expression, Product product, String validMaskExpression) static TermparseExpression(String expression, Product contextProduct) Parses the given expression.static TermparseExpression(String expression, Product[] products, int contextProductIndex) Parses the given expression.static voidRegisters a new global function.static voidRegisters a new global symbol.
-
Method Details
-
registerSymbol
Registers a new global symbol.- Parameters:
s- the symbol
-
deregisterSymbol
De-registers an existing global symbol.- Parameters:
s- the symbol
-
registerFunction
Registers a new global function.- Parameters:
f- the function
-
deregisterFunction
De-registers an existing global function.- Parameters:
f- the function
-
parseExpression
Parses the given expression.- Parameters:
expression- the expressioncontextProduct- the context product- Returns:
- the compiled expression
- Throws:
ParseException- if a parse error occurs
-
parseExpression
public static Term parseExpression(String expression, Product[] products, int contextProductIndex) throws ParseException Parses the given expression.- Parameters:
expression- the expressionproducts- the array of source products which form the valid namespace for the expressioncontextProductIndex- the index of the context product for which also symbols without the product prefix$ref-noare registered in the namespace- Returns:
- the compiled expression
- Throws:
ParseException- if a parse error occurs
-
createDefaultNamespace
Creates a default namespace for the product(s) given in an array. The resulting namespace contains symbols for all tie-point grids, bands and single flag values. if the array contains more then one product, the symbol's name will have a prefix according to each product's reference number.- Parameters:
products- the array of source products which form the valid namespace for the expressioncontextProductIndex- the index of the context product for which also symbols without the product prefix$ref-noare registered in the namespace- Returns:
- a default namespace, never
null
-
createDefaultNamespace
public static WritableNamespace createDefaultNamespace(Product[] products, int contextProductIndex, ProductNamespacePrefixProvider... prefixProviders) Creates a default namespace for the product(s) given in an array. The resulting namespace contains symbols for all tie-point grids, bands and single flag values. if the array contains more then one product, the symbol's name will have a prefix according to each product's reference number.- Parameters:
products- the array of source products which form the valid namespace for the expressioncontextProductIndex- the index of the context product for which also symbols without the product prefix$ref-noare registered in the namespaceprefixProviders- a list of product prefix providers- Returns:
- a default namespace, never
null
-
getRefRasters
public static RasterDataNode[] getRefRasters(String expression, Product... products) throws ParseException Utility method which returns all raster data nodes referenced in the given band math expressions.- Parameters:
expression- the expressionproducts- the array of source products which form the valid namespace for the expression- Returns:
- the array of raster data nodes, which may be empty
- Throws:
ParseException
-
getRefRasters
public static RasterDataNode[] getRefRasters(String expression, Product[] products, int contextProductIndex) throws ParseException Utility method which returns all raster data nodes referenced in the given band math expressions.- Parameters:
expression- the expressionproducts- the array of source products which form the valid namespace for the expressioncontextProductIndex- the index of the context product for which also symbols without the product prefix$ref-noare registered in the namespace- Returns:
- the array of raster data nodes, which may be empty
- Throws:
ParseException
-
getRefRasters
Utility method which returns all raster data nodes referenced in the given compiled band math expressions.- Parameters:
terms- the array of terms to be analysed- Returns:
- the array of raster data nodes, which may be empty
-
getRefRasterDataSymbols
Utility method which returns all raster data symbols referenced in a given compiled band math expressions. The order of the returned rasters is the order they appear in the given terms.- Parameters:
terms- the compiled band math expressions- Returns:
- the array of raster data symbols, never
nullbut may be empty
-
getValidMaskExpression
public static String getValidMaskExpression(String expression, Product product, String validMaskExpression) throws ParseException - Throws:
ParseException
-
getValidMaskExpression
public static String getValidMaskExpression(String expression, Product[] products, int contextProductIndex, String validMaskExpression) throws ParseException - Throws:
ParseException
-
createExternalName
Create an external name from the given name. If the given name contains character which are not valid in an external name the name is escaped with single quotes.The method simply delgates to
Tokenizer.createExternalName(String).- Parameters:
name- the name- Returns:
- a valid external name
-
getProductNodeNamePrefix
Gets a symbol name prefix for the names of bands, tie point grids, flags, etc. of the given product. The prefix is of the general form"$refNo."where refNo is the product's reference number returned byProduct.getRefNo().- Parameters:
product- the product, must not benull- Returns:
- a node name prefix, never null.
-
areRastersEqualInSize
Determines whether all rasters which are referenced in a term are compatible.- Parameters:
term- The term in question- Returns:
- true if the rasters are compatible
-
areRastersEqualInSize
public static boolean areRastersEqualInSize(Product product, String... expressions) throws ParseException Determines whether all rasters which are referenced in the given expressions are compatible.- Parameters:
product- The product to which the expressions can referexpressions- the expressions in question- Returns:
- true if all referenced rasters are compatible
- Throws:
ParseException- if a parse error occurs
-
areRastersEqualInSize
public static boolean areRastersEqualInSize(Product[] products, int defaultProductIndex, String... expressions) throws ParseException Determines whether all rasters which are referenced in the given expressions are compatible.- Parameters:
products- The product to which the expressions can referdefaultProductIndex- The index of the default productexpressions- the expressions in question- Returns:
- true if all referenced rasters are compatible
- Throws:
ParseException- if a parse error occurs
-