wcps.model¶
This module defines classes and methods for dynamically building WCPS query expressions.
This can be done by:
Composing objects of
WCPSExprsubclasses, e.g. Sum(Datacube(“cube”))Chaining methods on
WCPSExprobjects, e.g. Datacube(“cube”).sum()
Each subclass defines the __str__ method, so that executing
str(Sum(Datacube("cube"))) returns a valid WCPS query string
that can be sent to a WCPS server.
Attributes¶
A type representing axis bounds (in subsetting, extend, scale, etc). |
|
Scalar values can be of one of these types. |
|
Type of operands of WCPS expressions. |
|
Axis tuple types: (name, low), (name, low, high), or (name, low, high, crs) |
Exceptions¶
An exception thrown by this library. |
Classes¶
Custom implementation of StrEnum for Python <= 3.10 |
|
An abstract class encapsulating a WCPS expression. |
|
A reference to a datacube (coverage) object on a WCPS server. |
|
A wrapper for scalar values, e.g. |
|
A base class for unary operators, e.g. logical NOT. |
|
A base class for binary operators, e.g. logical AND. |
|
A base class for unary functions, e.g. |
|
A base class for binary functions, e.g. |
|
Adds |
|
Subtracts |
|
Multiplies |
|
Divides |
|
Computes the modulus (remainder of the division) of |
|
Computes the absolute value of |
|
Rounds |
|
Computes the floor of |
|
Computes the ceiling of |
|
Computes the exponential (e^x) of |
|
Computes the logarithm (base 10) of |
|
Computes the natural logarithm (base e) of |
|
Computes the square root of |
|
Raises |
|
Computes the sine of |
|
Computes the cosine of |
|
Computes the tangent of |
|
Computes the hyperbolic sine of |
|
Computes the hyperbolic cosine of |
|
Computes the hyperbolic tangent of |
|
Computes the inverse sine of |
|
Computes the inverse cosine of |
|
Computes the inverse tangent of |
|
Computes the two-argument inverse tangent of |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Performs a logical AND operation between |
|
Performs a logical OR operation between |
|
Performs a logical XOR operation between |
|
Performs a logical Not operation on |
|
Performs an overlay operation, placing |
|
Take the bit in the cell values of |
|
Select a field (band, channel) from a multiband operand. |
|
Create a multiband value. |
|
Represents an axis interval for defining spatial, temporal, or other dimensional subsets |
|
Select a spatio-temporal area from a coverage operand. |
|
Enlarge a coverage with new areas set to null values. |
|
Resamples the coverage values to fit a new domain. The target domain can be: |
|
Possible interpolation methods for |
|
Reproject a coverage to a different CRS. |
|
Possible cell types to which a value can be casted. |
|
Cast a value to a new type. The type can be specified with the |
|
Computes the sum of the cell values of the operand |
|
Counts the number of true values in the boolean operand |
|
Computes the average (mean) of the cell values of the operand |
|
Returns the minimum value among the elements of the operand |
|
Returns the maximum value among the elements of the operand |
|
Returns true if all elements in the operand |
|
Returns true if some elements in the operand |
|
An axis iterator expression set in a |
|
Reference to an |
|
Possible general |
|
A general coverage condense (aggregation) operation. It aggregates values |
|
A general coverage constructor operation. It allows to create a coverage |
|
Perform a switch operation for conditional evaluation. This produces a WCPS query |
|
Clip |
|
Execute a user-defined function (UDF), or any other WCPS function for which |
|
Encode a coverage to some data format. The data format must be specified |
Functions¶
|
Utility method for conveniently specifying RGB (red, green, blue) multiband values. |
|
Utility method for conveniently specifying RGBA (red, green, blue, alpha) multiband values. |
Module Contents¶
- class StrEnum[source]¶
-
Custom implementation of StrEnum for Python <= 3.10
Initialize self. See help(type(self)) for accurate signature.
- class WCPSExpr(operands=None)[source]¶
An abstract class encapsulating a WCPS expression.
It contains a list of
operands(themselvesWCPSExpr) and aparent.Subclasses for each operator exist, e.g.
Addfor binary addition, which are applied to theoperands. For most operators there are also corresponding methods in this class, allowing to build an expression by chaining them, e.gSum(Datacube("cube1") + Datacube("cube2"))is the same asDatacube("cube1").add(Datacube("cube2").sum()). Notable exceptions areSwitchandCoverage.Various builtin operators are overloaded to allow writing expressions more naturally, e.g.
WCPSExpr * WCPSExpr. Number/strings are automatically wrapped in aScalar, e.g.WCPSExpr * 2becomesWCPSExpr * Scalar(2).__and__,__or__,__xor__,__invert__correspond to BITWISE operators, not to the logical and, or, and not. They are not overloaded to the logical and/or/xor/not in order to avoid confusion.- Parameters:
operands (Optional[OperandType | list[OperandType]]) – the operands of this WCPS expression. This object is set as the parent of each operand, while its own parent is set to None. Scalar operands such as 1, 4.9 or “test” are automatically wrapped in a
Scalarobject.
- parent: WCPSExpr | None = None[source]¶
A
WCPSExprof which this expression is an operand;Noneif this is the root expression. E.g. in if this expression is theDatacubeobject inDatacube("test") * 5, then theparentis theMulobject.
- operands: list[WCPSExpr] = [][source]¶
A list of
WCPSExproperands of this expressions. E.g. inDatacube("test") * 5, this expression is aMul, withDatacubeandScalaroperands.
- add_operand(op)[source]¶
Add an operand to the list of operands. Scalar
opsuch as 1, 4.9 or “test” are automatically wrapped in aScalarobject. :param op: an operand to be added to the list of this expression’s operands; ifopisNoneit will be ignored.- Parameters:
op (Optional[OperandType])
- add(other)[source]¶
Adds the current operand to another operand.
- Parameters:
other (OperandType) – The operand to add to the current operand.
- Returns:
An instance of the
Addclass representing the addition operation.- Return type:
Examples:
Datacube("test1").add(Datacube("test2"))Datacube("test1").add(5)
- sub(other)[source]¶
Subtracts another operand from the current operand.
- Parameters:
other (OperandType) – The operand to subtract from the current operand.
- Returns:
An instance of the
Subclass representing the subtraction operation.- Return type:
Examples:
Datacube("test1").sub(Datacube("test2"))Datacube("test1").sub(5)
- mul(other)[source]¶
Multiplies the current operand by another operand.
- Parameters:
other (OperandType) – The operand to multiply with the current operand.
- Returns:
An instance of the
Mulclass representing the multiplication operation.- Return type:
Examples:
Datacube("test1").mul(Datacube("test2"))Datacube("test1").mul(5)
- div(other)[source]¶
Divides the current operand by another operand.
- Parameters:
other (OperandType) – The operand to divide the current operand by.
- Returns:
An instance of the
Divclass representing the division operation.- Return type:
Examples:
Datacube("test1").div(Datacube("test2"))Datacube("test1").div(5)
- mod(other)[source]¶
Computes the modulus (remainder of the division) of the current operand by another operand.
- Parameters:
other (OperandType) – The operand to use as the divisor.
- Returns:
An instance of the
Modclass representing the modulus operation.- Return type:
Examples:
Datacube("test1").mod(Datacube("test2"))Datacube("test1").mod(5)
- abs()[source]¶
Computes the absolute value of the current operand.
Examples:
Datacube("test1").abs()
- round()[source]¶
Rounds the current operand to the nearest integer.
Examples:
Datacube("test1").round()
- floor()[source]¶
Computes the floor of the current operand (rounds down to the nearest integer).
Examples:
Datacube("test1").floor()
- ceil()[source]¶
Computes the ceiling of the current operand (rounds up to the nearest integer).
Examples:
Datacube("test1").ceil()
- exp()[source]¶
Computes the exponential (e^x) of the current operand.
Examples:
Datacube("test1").exp()
- log()[source]¶
Computes the logarithm (base 10) of the current operand.
Examples:
Datacube("test1").log()
- ln()[source]¶
Computes the natural logarithm (base e) of the current operand.
Examples:
Datacube("test1").ln()
- pow(other)[source]¶
Raises the current operand to the power of another operand.
- Parameters:
other (OperandType) – The exponent to raise the current operand to.
- Returns:
An instance of the
Powclass representing the power operation.- Return type:
Examples:
Datacube("test1").pow(Datacube("test2"))Datacube("test1").pow(5)
- sinh()[source]¶
Computes the hyperbolic sine of the current operand.
- Returns:
An instance of the
Sinhclass representing the hyperbolic sine operation.- Return type:
Examples:
Datacube("test1").sinh()
- cosh()[source]¶
Computes the hyperbolic cosine of the current operand.
- Returns:
An instance of the
Coshclass representing the hyperbolic cosine operation.- Return type:
Examples:
Datacube("test1").cosh()
- tanh()[source]¶
Computes the hyperbolic tangent of the current operand.
- Returns:
An instance of the
Tanhclass representing the hyperbolic tangent operation.- Return type:
Examples:
Datacube("test1").tanh()
- arcsin()[source]¶
Computes the inverse sine (arcsine) of the current operand.
Examples:
Datacube("test1").arcsin()
- arccos()[source]¶
Computes the inverse cosine (arccosine) of the current operand.
Examples:
Datacube("test1").arccos()
- arctan()[source]¶
Computes the inverse tangent (arctangent) of the current operand.
Examples:
Datacube("test1").arctan()
- arctan2()[source]¶
Computes the two-argument inverse tangent (arctangent2) of the current operand.
- Returns:
An instance of the
ArcTan2class representing the arctangent2 operation.- Return type:
Examples:
Datacube("test1").arctan2(Datacube("test2"))
- gt(other)[source]¶
Checks if the current operand is greater than another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Gtclass representing the greater-than comparison.- Return type:
Examples:
Datacube("test1").gt(Datacube("test2"))Datacube("test1").gt(10)
- lt(other)[source]¶
Checks if the current operand is less than another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Ltclass representing the less-than comparison.- Return type:
Examples:
Datacube("test1").lt(Datacube("test2"))Datacube("test1").lt(10)
- ge(other)[source]¶
Checks if the current operand is greater than or equal to another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Geclass representing the greater-than-or-equal-to comparison.- Return type:
Examples:
Datacube("test1").ge(Datacube("test2"))Datacube("test1").ge(10)
- le(other)[source]¶
Checks if the current operand is less than or equal to another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Leclass representing the less-than-or-equal-to comparison.- Return type:
Examples:
Datacube("test1").le(Datacube("test2"))Datacube("test1").le(10)
- eq(other)[source]¶
Checks if the current operand is equal to another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Eqclass representing the equality comparison.- Return type:
Examples:
Datacube("test1").eq(Datacube("test2"))Datacube("test1").eq(10)
- ne(other)[source]¶
Checks if the current operand is not equal to another operand.
- Parameters:
other (OperandType) – The operand to compare against.
- Returns:
An instance of the
Neclass representing the inequality comparison.- Return type:
Examples:
Datacube("test1").ne(Datacube("test2"))Datacube("test1").ne(10)
- logical_and(other)[source]¶
Performs a logical AND operation between the current operand and another operand.
- Parameters:
other (OperandType) – The operand to perform the AND operation with.
- Returns:
An instance of the
Andclass representing the logical AND operation.- Return type:
Examples:
Datacube("test1").logical_and(Datacube("test2"))Datacube("test1").logical_and(True)
- logical_or(other)[source]¶
Performs a logical OR operation between the current operand and another operand.
- Parameters:
other (OperandType) – The operand to perform the OR operation with.
- Returns:
An instance of the
Orclass representing the logical OR operation.- Return type:
Examples:
Datacube("test1").logical_or(Datacube("test2"))Datacube("test1").logical_or(False)
- logical_xor(other)[source]¶
Performs a logical XOR operation between the current operand and another operand.
- Parameters:
other (OperandType) – The operand to perform the XOR operation with.
- Returns:
An instance of the
Xorclass representing the logical XOR operation.- Return type:
Examples:
Datacube("test1").logical_xor(Datacube("test2"))Datacube("test1").logical_xor(True)
- logical_not()[source]¶
Performs a logical NOT operation on the current operand.
Examples:
Datacube("test1").logical_not()
- overlay(other)[source]¶
Performs an overlay operation, placing other operand “on top” of this operand:
wherever the second operand’s cell value is not zero and not null, the result value will be this value.
wherever the second operand’s cell value is zero or null, the first argument’s cell value will be taken.
- Parameters:
other (OperandType) – The operand to perform the overlay operation with.
- Returns:
An instance of the
Overlayclass representing the overlay operation.- Return type:
Examples:
Datacube("test1").overlay(Datacube("test2"))
- bit(pos)[source]¶
Take the bit in this operand’s cell values at nonnegative position number pos, and put it as a Boolean value into a byte. Position counting starts with 0 and runs from least to most significant bit.
- Parameters:
pos (OperandType) – The position at which the bit value should be extracted
- Returns:
An instance of the
Bitclass- Return type:
Examples:
Datacube("test1").bit(5)
- band(band_name)[source]¶
Extract the given band
band_namefrom this multiband object.- Parameters:
band_name – The band name or position (0-based index)
- Returns:
An instance of the
Bandclass- Return type:
Examples:
Datacube("rgb").band("red")Datacube("rgb").band(0)
- subset(axes)[source]¶
Extract a spatio-temporal subset from this object as specified by the list of
axes.- Parameters:
axes – specifies a spatio-temporal subset as:
- Return type:
a single
Axisobject:Axis(axis_name, low, high?, crs?)a tuple of multiple
Axisobjects:(Axis(...), Axis(...))a tuple specifying the axis subset in place:
(axis_name, low, high?, crs?)a tuple of axis subset tuples (see 3.):
((axis_name, low, high?, crs?), (...), ...)a list of
Axisobjects: [Axis(…), Axis(…), …]a list of axis subset tuples (see 3.):
[(axis_name, low, high?, crs?), (...), ...]
Examples (with
cov = Datacube("testcube")):cov.subset(Axis("X", 5.5, 10.5))cov.subset(Axis("X", 5.5, 10.5), Axis("Y", 15))cov.subset("X", 5.5, 10.5)cov.subset(("X", 5.5, 10.5), ("Y", 15))cov.subset([Axis("X", 5.5, 10.5), Axis("Y", 15)])cov.subset([("X", 5.5, 10.5), ("Y", 15)])
- extend(axes)[source]¶
Extend this object to a new domain as specified by the list of
axes; new areas are filled in with null values.- Parameters:
axes – specifies a spatio-temporal subset as:
- Return type:
a single
Axisobject:Axis(axis_name, low, high?, crs?)a tuple of multiple
Axisobjects:(Axis(...), Axis(...))a tuple specifying the axis subset in place:
(axis_name, low, high?, crs?)a tuple of axis subset tuples (see 3.):
((axis_name, low, high?, crs?), (...), ...)a list of
Axisobjects: [Axis(…), Axis(…), …]a list of axis subset tuples (see 3.):
[(axis_name, low, high?, crs?), (...), ...]
Examples (with
cov = Datacube("testcube")):cov.extend(Axis("X", 5.5, 10.5))cov.extend(Axis("X", 5.5, 10.5), Axis("Y", 15))cov.extend("X", 5.5, 10.5)cov.extend(("X", 5.5, 10.5), ("Y", 15))cov.extend([Axis("X", 5.5, 10.5), Axis("Y", 15)])cov.extend([("X", 5.5, 10.5), ("Y", 15)])
- scale(grid_axes=None, another_coverage=None, single_factor=None, axis_factors=None)[source]¶
Up or down-scale the current object. Exactly one of the parameters must be specified.
- Parameters:
grid_axes – rescale to the grid bounds specified for each axis
another_coverage – rescale to the domain of another coverage operand
single_factor – rescale all axes by the same scale factor; factor > 1 for scaling up, 0 < factor < 1 for scaling down
axis_factors – rescale each axis by a specific factor; factor > 1 for scaling up, 0 < factor < 1 for scaling down
- Returns:
An instance of the
Scaleclass- Raise:
A
WCPSClientExceptionin case of error in the provided arguments.- Return type:
Examples (with
cov = Datacube("testcube")):cov.scale(("X", 0, 100), ("Y", 0, 200))cov.scale(Datacube("cov2"))cov.scale(0.5)- downscale by 2xcov.scale([0.5, 2])- downscale the first axis by 2x, and upscale the second axis by 2x
- reproject(target_crs, interpolation_method=None, axis_resolutions=None, axis_subsets=None, domain_of_coverage=None)[source]¶
Reproject the current object to a new CRS.
- Parameters:
target_crs (str) – the new CRS, e.g. “EPSG:4326”
interpolation_method (Optional[ResampleAlg]) – an optional interpolation method, one of the constants defined by
ResampleAlg, e.g.ResampleAlg.BILINEARaxis_resolutions – optional list of target axis resolutions to maintain in the reprojected result
axis_subsets – crop the result by the specified axis subsets (same syntax as for
subset(axes))domain_of_coverage – crop the result to the geo domain of another coverage object
- Return type:
Examples (with
cov = Datacube("testcube")):cov.reproject("EPSG:4326")cov.reproject("EPSG:4326", interpolation_method=ResampleAlg.CUBIC)cov.reproject("EPSG:4326", axis_resolutions=[0.5, 1.5])cov.reproject("EPSG:4326", axis_subsets=[("Lat", 30.5, 60.5), ("Lon", 50.5, 70.5)])cov.reproject("EPSG:4326", axis_resolutions=[0.5, 1.5], domain_of_coverage=Datacube("cov2"))
- cast(target_type)[source]¶
Cast the cell values of the current operand to a new
target_type.- Parameters:
target_type (CastType) – the new cell type of the result, one of the constants in
CastType, e.g.CastType.CHAR.- Return type:
Examples:
cov.cast(Datacube("testcube"), CastType.FLOAT)
- sum()[source]¶
Computes the sum of the cell values of the current operand.
Examples:
Datacube("test1").sum()
- count()[source]¶
Counts the number of true values in the current boolean coverage operand.
Examples:
Datacube("test1").count()
- avg()[source]¶
Computes the average (mean) of the cell values of the current operand.
Examples:
Datacube("test1").avg()
- min()[source]¶
Finds the minimum value among the elements of the current operand.
Examples:
Datacube("test1").min()
- max()[source]¶
Finds the maximum value among the elements of the current operand.
Examples:
Datacube("test1").max()
- all()[source]¶
Checks if all elements in the current operand are true.
Examples:
Datacube("test1").all()
- some()[source]¶
Checks if some elements in the current operand are true.
Examples:
Datacube("test1").some()
- encode(data_format=None, format_params=None)[source]¶
Encode a coverage to some
data_format. The data format must be specified with theto(format)method if it isn’t provided here. Optionally format parameters can be specified to customize the encoding process.- Parameters:
- Return type:
Examples:
` Datacube("testcube").encode("GTiff").params("...") `
- class Datacube(name)[source]¶
Bases:
WCPSExprA reference to a datacube (coverage) object on a WCPS server.
Example:
Datacube("mycoverage").- Parameters:
name (str) – the datacube (coverage) name.
- class Scalar(op)[source]¶
Bases:
WCPSExprA wrapper for scalar values, e.g.
5,3.14,"PNG".- Parameters:
op (ScalarType)
- class UnaryOp(op, operator)[source]¶
Bases:
WCPSExprA base class for unary operators, e.g. logical NOT.
- Parameters:
op (OperandType)
operator (str)
- class BinaryOp(op1, op2, operator)[source]¶
Bases:
WCPSExprA base class for binary operators, e.g. logical AND.
- Parameters:
op1 (OperandType)
op2 (OperandType)
operator (str)
- class UnaryFunc(op, func)[source]¶
Bases:
WCPSExprA base class for unary functions, e.g.
Abs.- Parameters:
op (OperandType)
func (str)
- class BinaryFunc(op1, op2, func)[source]¶
Bases:
WCPSExprA base class for binary functions, e.g.
Pow.- Parameters:
op1 (OperandType)
op2 (OperandType)
func (str)
- class Add(op1, op2)[source]¶
Bases:
BinaryOpAdds
op1toop2.Examples:
Add(Datacube("test1"), Datacube("test2"))Add(Datacube("test1"), 5)Add(5, Datacube("test1"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Sub(op1, op2)[source]¶
Bases:
BinaryOpSubtracts
op2fromop1.Examples:
Sub(Datacube("test1"), Datacube("test2"))Sub(Datacube("test1"), 5)Sub(5, Datacube("test1"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Mul(op1, op2)[source]¶
Bases:
BinaryOpMultiplies
op1byop2.Examples:
Mul(Datacube("test1"), Datacube("test2"))Mul(Datacube("test1"), 5)Mul(5, Datacube("test1"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Div(op1, op2)[source]¶
Bases:
BinaryOpDivides
op1byop2.Examples:
Div(Datacube("test1"), Datacube("test2"))Div(Datacube("test1"), 5)Div(5, Datacube("test1"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Mod(op1, op2)[source]¶
Bases:
BinaryFuncComputes the modulus (remainder of the division) of
op1byop2.Examples:
Mod(Datacube("test1"), Datacube("test2"))Mod(Datacube("test1"), 5)Mod(5, Datacube("test1"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Abs(op)[source]¶
Bases:
UnaryFuncComputes the absolute value of
op.Examples:
Abs(Datacube("test1"))Abs(-5)
- Parameters:
op (OperandType)
- class Round(op)[source]¶
Bases:
UnaryFuncRounds
opto the nearest integer.Examples:
Round(Datacube("test1"))Round(-5.4)
- Parameters:
op (OperandType)
- class Floor(op)[source]¶
Bases:
UnaryFuncComputes the floor of
op(rounds down to the nearest integer).Examples:
Floor(Datacube("test1"))Floor(-5.4)
- Parameters:
op (OperandType)
- class Ceil(op)[source]¶
Bases:
UnaryFuncComputes the ceiling of
op(rounds up to the nearest integer).Examples:
Ceil(Datacube("test1"))Ceil(-5.4)
- Parameters:
op (OperandType)
- class Exp(op)[source]¶
Bases:
UnaryFuncComputes the exponential (e^x) of
op.Examples:
Exp(Datacube("test1"))
- Parameters:
op (OperandType)
- class Log(op)[source]¶
Bases:
UnaryFuncComputes the logarithm (base 10) of
op.Examples:
Log(Datacube("test1"))
- Parameters:
op (OperandType)
- class Ln(op)[source]¶
Bases:
UnaryFuncComputes the natural logarithm (base e) of
op.Examples:
Ln(Datacube("test1"))
- Parameters:
op (OperandType)
- class Sqrt(op)[source]¶
Bases:
UnaryFuncComputes the square root of
op.Examples:
Sqrt(Datacube("test1"))
- Parameters:
op (OperandType)
- class Pow(op1, op2)[source]¶
Bases:
BinaryFuncRaises
op1to the power ofop2.Examples:
Pow(Datacube("test1"), Datacube("test2"))Pow(Datacube("test1"), 5)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Sin(op)[source]¶
Bases:
UnaryFuncComputes the sine of
op.Examples:
Sin(Datacube("test1"))
- Parameters:
op (OperandType)
- class Cos(op)[source]¶
Bases:
UnaryFuncComputes the cosine of
op.Examples:
Cos(Datacube("test1"))
- Parameters:
op (OperandType)
- class Tan(op)[source]¶
Bases:
UnaryFuncComputes the tangent of
op.Examples:
Tan(Datacube("test1"))
- Parameters:
op (OperandType)
- class Sinh(op)[source]¶
Bases:
UnaryFuncComputes the hyperbolic sine of
op.Examples:
Sinh(Datacube("test1"))
- Parameters:
op (OperandType)
- class Cosh(op)[source]¶
Bases:
UnaryFuncComputes the hyperbolic cosine of
op.Examples:
Cosh(Datacube("test1"))
- Parameters:
op (OperandType)
- class Tanh(op)[source]¶
Bases:
UnaryFuncComputes the hyperbolic tangent of
op.Examples:
Tanh(Datacube("test1"))
- Parameters:
op (OperandType)
- class ArcSin(op)[source]¶
Bases:
UnaryFuncComputes the inverse sine of
op.Examples:
ArcSin(Datacube("test1"))
- Parameters:
op (OperandType)
- class ArcCos(op)[source]¶
Bases:
UnaryFuncComputes the inverse cosine of
op.Examples:
ArcCos(Datacube("test1"))
- Parameters:
op (OperandType)
- class ArcTan(op)[source]¶
Bases:
UnaryFuncComputes the inverse tangent of
op.Examples:
ArcTan(Datacube("test1"))
- Parameters:
op (OperandType)
- class ArcTan2(op)[source]¶
Bases:
UnaryFuncComputes the two-argument inverse tangent of
op.Examples:
ArcTan2(Datacube("test1"))
- Parameters:
op (OperandType)
- class Gt(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is greater thanop2.Examples:
Gt(Datacube("test1"), Datacube("test2"))Gt(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Lt(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is less thanop2.Examples:
Lt(Datacube("test1"), Datacube("test2"))Lt(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Ge(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is greater than or equal toop2.Examples:
Ge(Datacube("test1"), Datacube("test2"))Ge(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Le(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is less than or equal toop2.Examples:
Le(Datacube("test1"), Datacube("test2"))Le(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Eq(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is equal toop2.Examples:
Eq(Datacube("test1"), Datacube("test2"))Eq(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Ne(op1, op2)[source]¶
Bases:
BinaryOpChecks if
op1is not equal toop2.Examples:
Ne(Datacube("test1"), Datacube("test2"))Ne(Datacube("test1"), 10)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class And(op1, op2)[source]¶
Bases:
BinaryOpPerforms a logical AND operation between
op1andop2.Examples:
And(Datacube("test1"), Datacube("test2"))And(Datacube("test1"), True)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Or(op1, op2)[source]¶
Bases:
BinaryOpPerforms a logical OR operation between
op1andop2.Examples:
Or(Datacube("test1"), Datacube("test2"))Or(Datacube("test1"), False)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Xor(op1, op2)[source]¶
Bases:
BinaryOpPerforms a logical XOR operation between
op1andop2.Examples:
Xor(Datacube("test1"), Datacube("test2"))Xor(Datacube("test1"), True)
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Not(op)[source]¶
Bases:
UnaryOpPerforms a logical Not operation on
op.Examples:
Not(Datacube("test1"))Not(True)
- Parameters:
op (OperandType)
- class Overlay(op1, op2)[source]¶
Bases:
BinaryOpPerforms an overlay operation, placing
op2“on top” ofop1:wherever the cell value of
op2is not zero and not null, the result value will be this value.wherever the cell value of
op2is zero or null, the cell value ofop1will be taken.
Examples:
Overlay(Datacube("test1"), Datacube("test2"))
- Parameters:
op1 (OperandType)
op2 (OperandType)
- class Bit(op, pos)[source]¶
Bases:
BinaryFuncTake the bit in the cell values of
opat nonnegative position numberpos, and put it as a Boolean value into a byte. Position counting starts with 0 and runs from least to most significant bit.- Parameters:
pos (OperandType) – The position at which the bit value should be extracted
op (OperandType)
Examples:
Bit(Datacube("test1", 5)
- class Band(op, field)[source]¶
Bases:
WCPSExprSelect a field (band, channel) from a multiband operand.
- class MultiBand(bands)[source]¶
Bases:
WCPSExprCreate a multiband value. :param bands: a dictionary of (band name, value), e.g. {“red”: cov1, “blue”: 2}
- Parameters:
bands (dict)
- rgb(r, g, b)[source]¶
Utility method for conveniently specifying RGB (red, green, blue) multiband values. Examples:
rgb(255,255,255)rgb(red_cov, blue_cov, 0)
- Parameters:
r (OperandType) – red band
g (OperandType) – green band
b (OperandType) – blue band
- Returns:
a MultiBand object with red, green and blue bands correspondingly.
- Return type:
- rgba(r, g, b, a)[source]¶
Utility method for conveniently specifying RGBA (red, green, blue, alpha) multiband values. Examples:
rgb(255,255,255,255)rgb(red_cov, blue_cov, 0, 255)
- Parameters:
r (OperandType) – red band
g (OperandType) – green band
b (OperandType) – blue band
a (OperandType) – alpha band
- Returns:
a MultiBand object with red, green, blue and alpha bands correspondingly.
- Return type:
- class Axis(axis_name, low, high=None, crs=None)[source]¶
Bases:
WCPSExprRepresents an axis interval for defining spatial, temporal, or other dimensional subsets in WCPS queries. An axis subset specifies a trim (or slice) along a specific axis, optionally with a Coordinate Reference System (CRS) if the low/high are not in the native CRS.
This object can be used in operations like subsetting, extending, or scaling coverages. It supports both single values (slicing) and ranges (trimming).
- Parameters:
axis_name (str) – The name of the axis (e.g., “X”, “Y”, “time”).
low (BoundType) – The lower bound of a subset trim, or a slice value if
highis not given.high (Optional[BoundType]) – The upper bound of a subset trim.
crs (Optional[str]) – The CRS associated with the axis (e.g., “EPSG:4326”), usually set if the low/high values are not in the native CRS.
- Constants:
MIN (‘*’): Can be used for the minimum bound of an axis. MAX (‘*’): Can be used for the maximum bound of an axis.
Examples:
# Define a spatial axis subset from 15.0 to 20.0 with CRS "EPSG:4326" axis = Axis("X", 15.0, 20.0, "EPSG:4326") # Define slicing on the temporal axis time axis = Axis("time", "2025-01-01")
- Raises:
WCPSClientException – If the axis name is empty.
- Parameters:
- static get_axis_list(axes)[source]¶
Normalizes
axesinto a list of Axis objects. :param axes: may be:a single Axis, e.g.
Axis("X", 0, 100.5, "EPSG:4326")a single slice, e.g.
"X":1, or"X":1:15.3a tuple of Axis objects, e.g.
(Axis(...), Axis(...), ...)a single in-place axis tuple, e.g.
("X", 0, 100.5, "EPSG:4326")a tuple of axis tuples, e.g.
(("X", 0, 100.5), (...), ...)a tuple of slices, e.g.
("X":1, "Y":0:100.5)a list of Axis objects, e.g.
[Axis(...), Axis(...), ...]a list of axis tuples, e.g.
[("X", 0, 100.5), (...), ...]
- Raise:
a
WCPSClientExceptionin caseaxesis in invalid shape.- Return type:
- class Subset(op, axes)[source]¶
Bases:
WCPSExprSelect a spatio-temporal area from a coverage operand.
- Parameters:
op (WCPSExpr)
- class Extend(op, axes)[source]¶
Bases:
WCPSExprEnlarge a coverage with new areas set to null values.
- Parameters:
op (WCPSExpr)
- class Scale(op)[source]¶
Bases:
WCPSExprResamples the coverage values to fit a new domain. The target domain can be:
An explicit grid domain for each axis with
to_explicit_grid_domain():Scale(cov).to_explicit_grid_domain( [("X", 15, 30), ("Y", 20, 40)])
A grid domain matching another coverage with
to_grid_domain_of():Scale(cov).to_grid_domain_of(cov2)
A scale factor equally applied to all axes with
by_factor():Scale(cov).by_factor(0.5)
A scale factor per axis with
by_factor_per_axis():Scale(cov).by_factor_per_axis([0.5, 2])
- Parameters:
op (WCPSExpr)
- to_explicit_grid_domain(grid_axes)[source]¶
Scale to fit the grid domain specified by the
grid_axes.- Parameters:
grid_axes – a list of
Axis
- to_grid_domain_of(another_coverage)[source]¶
Scale to fit the grid domain of
another_coverage.- Parameters:
another_coverage (WCPSExpr) – a coverage expression
- class ResampleAlg[source]¶
Bases:
StrEnumPossible interpolation methods for
Reproject.Initialize self. See help(type(self)) for accurate signature.
- class Reproject(op, target_crs, interpolation_method=None)[source]¶
Bases:
WCPSExprReproject a coverage to a different CRS.
- Parameters:
op (WCPSExpr) – the coverage value to be reprojected.
target_crs (str) –
the CRS to which
opshould be reprojected. It can be in one of these formats:Full CRS URL, e.g.
http://localhost:8080/rasdaman/def/crs/EPSG/0/4326(OGC standard format)Shorthand CRS with authority, version and code, e.g.
EPSG/0/4326Shorthand CRS with authority and code, e.g.
EPSG:4326
interpolation_method (Optional[ResampleAlg]) – one of the
ResampleAlgconstants, e.g.ResampleAlg.BILINEAR.
- to_axis_resolutions(axis_resolutions)[source]¶
The reprojected result will be resampled to these resolutions.
- Parameters:
axis_resolutions – a list of
Axisobjects with only the axis name and low bound (corresponding to a resolution) specified.- Raise:
WCPSClientExceptionif an axis object has theAxis.highorAxis.crsset.- Return type:
Example:
cov1 = Datacube("cov1") Reproject(cov1, "EPSG:4326", ResampleAlg.AVERAGE) .to_axis_resolutions([("X", 1.5), ("Y", 2)])
- subset_by_axes(axis_subsets)[source]¶
The reprojected result will be cropped to the specified axis subsets.
- Parameters:
axis_subsets – a list of
Axisobjects.- Raise:
WCPSClientExceptionif an axis object does not have theAxis.highset, or it has theAxis.crsset.- Return type:
Example:
cov1 = Datacube("cov1") Reproject(cov1, "EPSG:4326") .subset_by_axes([("X", 1.5, 2.5), ("Y", 2, 4)])
- subset_by_coverage_domain(subset_domain)[source]¶
The reprojected result will be cropped to the domain of a coverage expression
subset_domain.- Parameters:
subset_domain – a coverage expression
- Return type:
Example:
cov1 = Datacube("cov1") cov2 = Datacube("cov2") Reproject(cov1, "EPSG:4326") .subset_by_coverage_domain(cov2)
- class CastType[source]¶
Bases:
StrEnumPossible cell types to which a value can be casted.
Initialize self. See help(type(self)) for accurate signature.
- class Cast(op, target_type=None)[source]¶
Bases:
WCPSExprCast a value to a new type. The type can be specified with the
to()method.- Parameters:
op (OperandType) – the operand to be casted.
target_type (Optional[Union[CastType, str]]) – must be one of the
CastTypeconstants, e.g.CastType.CHAR.
Examples:
Cast(Datacube("test"), CastType.CHAR)
- class Sum(op)[source]¶
Bases:
UnaryFuncComputes the sum of the cell values of the operand
op.Examples:
Sum(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class Count(op)[source]¶
Bases:
UnaryFuncCounts the number of true values in the boolean operand
op.Examples:
Count(Datacube("test1") > 5)
- Parameters:
op (WCPSExpr)
- class Avg(op)[source]¶
Bases:
UnaryFuncComputes the average (mean) of the cell values of the operand
op.Examples:
Avg(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class Min(op)[source]¶
Bases:
UnaryFuncReturns the minimum value among the elements of the operand
op.Examples:
Min(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class Max(op)[source]¶
Bases:
UnaryFuncReturns the maximum value among the elements of the operand
op.Examples:
Max(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class All(op)[source]¶
Bases:
UnaryFuncReturns true if all elements in the operand
opare true.Examples:
All(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class Some(op)[source]¶
Bases:
UnaryFuncReturns true if some elements in the operand
opare true.Examples:
Some(Datacube("test1"))
- Parameters:
op (WCPSExpr)
- class AxisIter(var_name, axis_name)[source]¶
Bases:
WCPSExprAn axis iterator expression set in a
Condense.over()or aCoverage.over()methods. The iteration can be over an integer gridinterval(),of_grid_axis()domain of a particular coverage, orof_of_geo_axis()domain of a coverage.The
ref()method should be used to get a reference to anAxisIterthat can be used in expressions for theCondense.where(),Condense.using(), orCoverage.values()clauses.- Parameters:
Examples:
AxisIter('$x', 'X').interval(0, 100)- iterate from 0 to 100, inclusiveAxisIter('$pt', 'time').of_grid_axis(Datacube("timeseries"))AxisIter('$plat', 'Lat').of_geo_axis(Datacube("cov"))
- of_grid_axis(cov_expr)[source]¶
Iterate over the grid axis domain of a coverage
cov_expr.- Parameters:
cov_expr (WCPSExpr)
- of_geo_axis(cov_expr)[source]¶
Iterate over the geo axis domain of a coverage
cov_expr.- Parameters:
cov_expr (WCPSExpr)
- ref()[source]¶
- Returns:
a reference object that can be used in expressions set in the
Condense.where(),Condense.using(), orCoverage.values()methods.- Return type:
- class AxisIterRef(axis_iter)[source]¶
Bases:
WCPSExpr- Reference to an
AxisIterobject, to be used in expressions set in the Condense.where(),Condense.using(), orCoverage.values()methods.
- Parameters:
axis_iter (AxisIter)
- Reference to an
- class CondenseOp[source]¶
Bases:
StrEnumPossible general
Condenseoperators.Initialize self. See help(type(self)) for accurate signature.
- class Condense(condense_op, over=None, using=None, where=None)[source]¶
Bases:
WCPSExprA general coverage condense (aggregation) operation. It aggregates values
over()an iteration domain formed of a list ofAxisIter, with a condenser operation (one of+,*,max,min,and, oror). For each coordinate in the iteration domain defined by the over clause, theusing()expression is evaluated and added to the final aggregated result; the optionalwhere()expression allows to filter values from the aggregation.It corresponds to a WCPS expression of the following form:
condense op over $iterVar axis(lo:hi), ... [ where boolScalarExpr ] using scalarExpr
Typically, the iterator variable iterates through a grid domain (
AxisIter.interval()orAxisIter.of_grid_axis()). However, iteration over a geo domain is also supported withAxisIter.of_geo_axis().- Parameters:
condense_op (CondenseOp) – one of the
CondenseOpconstants, e.g.CondenseOp.PLUSusing (Optional[WCPSExpr]) – an expression that aggregates into the final value
where (Optional[WCPSExpr]) – an optional expression to filter which expression values are evaluated
For example, to sum the values of a coverage
mycov(same as using theSumshorthand):cov = Datacube("mycov") pt_var = AxisIter('$pt', 'time').of_grid_axis(cov) pt_ref = pt_var.ref() Condense(CondenseOp.PLUS) .over(pt_var) .using(cov1[('time', pt_ref)])
- condense_op[source]¶
One of the
CondenseOpconstants, e.g.CondenseOp.PLUS
- over(iter_var)[source]¶
Add an iterator variable to a Condense or a Coverage operand. Calling this method on another object type will raise a WCPSClientException.
- Parameters:
iter_var (Union[AxisIter, list[AxisIter]]) – an iterator variable
- Returns:
the same object with the iter_var appended to its iterator variables list
- Return type:
Examples:
cov = Datacube("testcube") pt_var = AxisIter('$pt', 'time').of_grid_axis(cov) px_var = AxisIter('$px', 'X').interval(0, 100) cov.condense(CondenseOp.PLUS).over(pt_var).over(px_var)
- using(using)[source]¶
Specify an aggregation expression, evaluated for each point in the
over()domain and aggregated into the final result with thecondense_op.- Parameters:
using (OperandType)
- Return type:
- class Coverage(name, over=None, values_clause=None, value_list_clause=None)[source]¶
Bases:
WCPSExprA general coverage constructor operation. It allows to create a coverage
over()a spatio-temporal domain, where for each coordinate in the domain the value is dynamically calculated from avalues()expression which potentially references the iterator variables set in theover()method. It corresponds to a WCPS expression of the following form:coverage covName over $iterVar axis(lo:hi), ... values scalarExpr
Typically, the iterator variable iterates through a grid domain (
AxisIter.interval()orAxisIter.of_grid_axis()). However, iteration over a geo domain is also supported withAxisIter.of_geo_axis().- Parameters:
name (str) – a name for the new coverage
over (Optional[list]) – a list of axis iterators
values_clause (Optional[OperandType]) – an expression evaluating to a value for each point in the over domain; exclusive with
value_list_clause.value_list_clause (Optional[list[ScalarType]]) – a list enumerating all cell values in the coverage domain; exclusive with
values_clause.
For example, to create a 2D geo-referenced coverage with Lat and Lon axes, based on an existing geo-referenced coverage
mycov:cov = Datacube("mycov") plat_var = AxisIter('$pLat', 'Lat') .of_geo_axis(cov['Lat', -30, -28.5]) plon_var = AxisIter('$pLon', 'Lon') .of_geo_axis(cov['Lon', 111.975, 113.475]) Coverage("copy_of_mycov") .over(plat_var).over(plon_var) .values(cov1[('Lat', plat_var.ref()), ('Lon', plon_var.ref())]))
- over(iter_var)[source]¶
Add an iterator variable to the coverage constructor.
- Parameters:
iter_var (Union[AxisIter, list[AxisIter]]) – an iterator variable or a list of iterator variables
- Returns:
the same object with the
iter_varappended to its iterator variables list- Return type:
Examples:
cov = Datacube("testcube") pt_var = AxisIter('$pt', 'time').of_grid_axis(cov) px_var = AxisIter('$px', 'X').interval(0, 100) cov.condense(CondenseOp.PLUS).over(pt_var).over(px_var)
- values(values_clause)[source]¶
Specify a VALUES expression, evaluated for each point in the
over()domain.- Parameters:
values_clause (OperandType)
- Return type:
- class Switch[source]¶
Bases:
WCPSExprPerform a switch operation for conditional evaluation. This produces a WCPS query fragment of the format:
switch case boolCovExpr return covExpr case boolCovExpr return covExpr ... default return covExpr
Use pairs of
case()andthen()method calls to specify case/return branches. Finally make adefault()method call to specify a default case executed when none of the case conditions are satisfied.Examples:
cov1 = Datacube("cube1") cov2 = Datacube("cube2") Switch().case(cov1 > 5).then(cov2).default(cov1)
- case_expr: list[OperandType] = [][source]¶
- then_expr: list[OperandType] = [][source]¶
- case(case_expr)[source]¶
Specify a condition expression. :param case_expr: the boolean case expression. :raise:
WCPSClientExceptionif there is a mismatch between the number of case/then expressions.- Parameters:
case_expr (OperandType)
- Return type:
- then(then_expr)[source]¶
Specify an expression to be evaluated when the previously set
caseexpression is true.- Parameters:
then_expr (OperandType) – the then expression.
- Raise:
WCPSClientExceptionif there is a mismatch between the number of case/then expressions.- Return type:
- default(default_expr)[source]¶
Specify a default expressions executed when none of the case conditions are satisfied.
- Parameters:
default_expr (OperandType) – the default expression.
- Raise:
WCPSClientExceptionif no case expressions have been specified, or if a default expression has already been set.- Return type:
- class Clip(op, wkt)[source]¶
Bases:
WCPSExprClip
opwith the given WKT string. For supported WKT parameters see https://doc.rasdaman.org/05_geo-services-guide.html#polygon-raster-clippingExamples:
c = Datacube("cov") Clip(c, "POLYGON((13589894.568 -2015496.69612, 15086830.0246 -1780682.3822))") Clip(c, 'LineString("2008-01-01T02:01:20.000Z" 75042.7273594 5094865.55794, "2008-01-08T00:02:58.000Z" 705042.727359 5454865.55794)') Clip(c, "Multipolygon( ((-23.189600 118.432617, -27.458321 117.421875, -30.020354 126.562500, -24.295789 125.244141)), ((-27.380304 137.768555, -30.967012 147.700195, -25.491629 151.259766, -18.050561 142.075195)) )") Clip(c, "CURTAIN(projection(Lat, Long), Polygon((25 40, 30 40, 30 45, 30 42)) )") Clip(c, 'CORRIDOR(projection(E, N), LineString("2008-01-01T02:01:20.000Z" 75042.7273594 5094865.55794, "2008-01-01T02:01:20.000Z" 75042.7273594 5194865.55794), LineString(75042.7273594 5094865.55794, 75042.7273594 5094865.55794, 85042.7273594 5194865.55794, 95042.7273594 5194865.55794) )') Clip(c, 'CORRIDOR(projection(Lat, Long), LineString(26 41 "1950-01-01", 28 41 "1950-01-02"), Polygon((25 40, 30 40, 30 45, 25 45)), discrete)')
- Parameters:
- class Udf(function_name, operands)[source]¶
Bases:
WCPSExprExecute a user-defined function (UDF), or any other WCPS function for which no concrete class exists yet.
- Parameters:
function_name (str) – the UDF name, e.g. image.stretch
operands (list[OperandType]) – a list of operands that the UDF expects
Examples:
stretch = Udf('stretch', Datacube('cov1'))
- class Encode(op, data_format=None, format_params=None)[source]¶
Bases:
WCPSExprEncode a coverage to some data format. The data format must be specified with the
to()method if it isn’t provided here. Format parameters can be specified with theparams()method.- Parameters:
Examples:
Encode(Datacube("test")).to("GTiff")Encode(Datacube("test"), "GTiff")Encode(Datacube("test"), "GTiff", "...")