Skip to content

Operators

The following symbolic operators are supported on layers:

Symbol Operator
+ add
- subtract
* multiply
/ division
// floor division
% mod
^ power
== equal
!= not equal
< less than
<= less than or equal
> greater than
>= greater than or equal
& bitwise and
| bitwise or

On a layer you can also invoke the following operations using layer.operator(...) syntax:

Operator
abs
as_area
as_projection
as_type
ceil
clip
conv2d
exp
exp2
floor
isin
isnan
log
log10
log2
nan_to_num

You can also call the following methods from yirgacheffe:

abs(layer)

Returns a layer where the values are the absolute value of the input values.

Parameters:

Name Type Description Default
layer

The layer of which to take the absolute values.

required

Returns:

Type Description

A new layer where the values are the absolute value of the input layer's values.

Note

Can also be called as layer.abs().

all(layers)

Combine layers with AND operation.

Returns a raster where each pixel is 1 only if ALL input layers have non-zero values at that geospatial location.

Similar to Python's built-in all() but for Yirgacheffe layers.

Parameters:

Name Type Description Default
layers list

List/sequence of layers to AND

required

Returns:

Type Description

A new raster layer with pixel-wise sums

any(layers)

Combine layers with OR operation.

Returns a raster where each pixel is 1 if ANY input layers has a non-zero value at that geospatial location.

Similar to Python's built-in any() but for Yirgacheffe layers.

Parameters:

Name Type Description Default
layers list

List/sequence of layers to OR

required

Returns:

Type Description

A new raster layer with pixel-wise sums

ceil(layer)

Returns a layer where the values are the rounded up (ceiling) of the input values.

Parameters:

Name Type Description Default
layer

The layer of which to ceiling.

required

Returns:

Type Description

A new layer where the values are the ceiling of the input layer's values.

Note

Can also be called as layer.ceil().

clip(layer, min=None, max=None)

Clip a layer to either an miniumum or maximum value, or both.

Parameters:

Name Type Description Default
layer

The layer on which to clip.

required
min

If specified, the lower bound of value that will be in the result layer.

None
max

If specified, the upper bound of value that will be in the result layer.

None

Returns:

Type Description

A new layer with the values clipped as specified.

exp(layer)

Returns the exponent of the layer.

Parameters:

Name Type Description Default
layer

The layer of which to take the exponent.

required

Returns:

Type Description

A layer where each value is the exponent of the input.

Note

Can also be called as layer.exp().

exp2(layer)

Returns the base-2 exponent of the layer.

Parameters:

Name Type Description Default
layer

The layer of which to take the base-2 exponent.

required

Returns:

Type Description

A layer where each value is the base-2 exponent of the input.

Note

Can also be called as layer.exp2().

floor(layer)

Returns a layer where the values are the rounded down (floor) of the input values.

Parameters:

Name Type Description Default
layer

The layer of which to floor.

required

Returns:

Type Description

A new layer where the values are the floor of the input layer's values.

Note

Can also be called as layer.floor().

isin(layer, test_elements)

Returns a layer of boolean values that indicate if the corresponding value of the source was fouind in the provided test_elements.

Parameters:

Name Type Description Default
layer

The layer to be evaluted.

required
test_elements

A sequence (list, tuple, set) of values to be tested against.

required

Returns:

Type Description

A new layer where the values are True if the source layer value was in the test_elements,

otherwise False.

Note

Can also be called as layer.isin(test_elements).

log(layer)

Returns the natural logarithm of the layer.

Parameters:

Name Type Description Default
layer

The layer of which to take the natural logarithm.

required

Returns:

Type Description

A layer where each value is the natural logarithm of the input.

Note

Can also be called as layer.log().

log10(layer)

Returns the base-10 logarithm of the layer.

Parameters:

Name Type Description Default
layer

The layer of which to take the base-10 logarithm.

required

Returns:

Type Description

A layer where each value is the base-10 logarithm of the input.

Note

Can also be called as layer.log10().

log2(layer)

Returns the base-2 logarithm of the layer.

Parameters:

Name Type Description Default
layer

The layer of which to take the base-2 logarithm.

required

Returns:

Type Description

A layer where each value is the base-2 logarithm of the input.

Note

Can also be called as layer.log2().

logical_and(layer1, layer2)

Returns a boolean layer that is the logical and of the values in the two input layers.

Note that this is not the same as using the & operator which will do a bitwise and.

Parameters:

Name Type Description Default
layer1

First input layer.

required
layer2

Second input layer.

required

Returns:

Type Description

A new layer that is the logical and of the two input layers.

logical_or(layer1, layer2)

Returns a boolean layer that is the logical or of the values in the two input layers.

Note that this is not the same as using the | operator which will do a bitwise or.

Parameters:

Name Type Description Default
layer1

First input layer.

required
layer2

Second input layer.

required

Returns:

Type Description

A new layer that is the logical or of the two input layers.

logical_not(layer)

Returns a boolean layer that is the logical inverse of the input layer.

Parameters:

Name Type Description Default
layer

The input layer.

required

Returns:

Type Description

A new layer that is the logical inverse of the input.

logical_xor(layer1, layer2)

Returns a boolean layer that is the logical xor of the values in the two input layers.

Parameters:

Name Type Description Default
layer1

First input layer.

required
layer2

Second input layer.

required

Returns:

Type Description

A new layer that is the logical xor of the two input layers.

maximum(a, b)

Element-wise maximum of layer elements.

Behaves like numpy.maximum(x1, x2), comparing two layers element-by-element and returning a new layer with the maximum values.

Parameters:

Name Type Description Default
a

First layer or constant to compare.

required
b

Second layer or constant to compare.

required

Returns:

Type Description

New layer representing the element-wise maximum of the inputs.

minimum(a, b)

Element-wise minimum of layer elements.

Behaves like numpy.minimum(x1, x2), comparing two layers element-by-element and returning a new layer with the minimum values.

Parameters:

Name Type Description Default
a

First layer or constant to compare.

required
b

Second layer or constant to compare.

required

Returns:

Type Description

New layer representing the element-wise minimum of the inputs.

nan_to_num(layer, nan=0, posinf=None, neginf=None)

Replace nan and infinity values with zero and large finate values respecitively, or with the values provided.

Parameters:

Name Type Description Default
layer

The layer to evaluate.

required
nan

The value used to replace nan values. Defaults to 0.

0
posinf

The value used to replace positive infinity. Defaults to a large finite value dependant on type.

None
posinf

The value used to replace negative infinity. Defaults to a negative large finite value dependant on type.

None

Returns:

Type Description

A new layer with the values appropriately substituted.

Note

Can also be called as layer.nan_to_num(...).

round(layer)

Returns a layer where the values are rounded from the input values.

Parameters:

Name Type Description Default
layer

The layer of which to round.

required

Returns:

Type Description

A new layer where the values are rounded from the input layer's values.

Note

Can also be called as layer.round().

sum(layers)

Combine multiple layers by summing spatially corresponding pixels.

Creates a new raster where each pixel is the sum of that pixel's values across all input rasters for the same location.

Parameters:

Name Type Description Default
layers list

List/sequence of layers to sum

required

Returns:

Type Description

A new raster layer with pixel-wise sums

Examples:

Combine 100 species habitat rasters into richness map

richness = yg.sum(habitat_layers)

Note

To sum all pixels within a single raster to get a scalar, use the .sum() method instead: layer.sum()

where(cond, a, b)

Return elements chosen from a or b depending on cond.

Behaves like numpy.where(condition, x, y), returning a layer operation where elements from a are selected where cond is True, and elements from b are selected where cond is False.

Parameters:

Name Type Description Default
cond

Layer or constant used as condition. Where True, yield a, otherwise yield b.

required
a

Layer or constant with values from which to choose where cond is True.

required
b

Layer or constant with values from which to choose where cond is False.

required

Returns:

Type Description

New layer representing the conditional selection.