deadleaves.leaf_masks#

Attributes#

MaskFn

Mask Function type

Classes#

LeafMaskSpec

Leaf mask data class

Functions#

get_leaf_mask_kw(→ dict[str, LeafMaskSpec])

Return dictionary mapping leaf shapes to their mask functions

circular(→ torch.Tensor)

Generate mask of circle from given area and x-y-position on tensor.

rectangular(→ torch.Tensor)

Generate mask of rectangle from given area, aspect ratio, orientation,

ellipsoid(→ torch.Tensor)

Generate mask of ellipsoid from given area, aspect ratio, orientation,

polygon(→ torch.Tensor)

Generate mask of regular polygon from given area, number of vertices

leaf_aabb(→ tuple[int, int, int, int])

Compute the axis-aligned bounding box of a leaf.

Module Contents#

deadleaves.leaf_masks.MaskFn#

Mask Function type

class deadleaves.leaf_masks.LeafMaskSpec#

Leaf mask data class

fn: MaskFn#

Leaf mask function, mapping shape parameters to a leaf mask.

required: set[str] | list[set[str]]#

Parameters of the leaf shape.

bbox: Callable[[dict[str, torch.Tensor], str], tuple[int, int, int, int]]#

Axis-aligned bounding box function.

deadleaves.leaf_masks.get_leaf_mask_kw() dict[str, LeafMaskSpec]#

Return dictionary mapping leaf shapes to their mask functions and required parameters.

deadleaves.leaf_masks.circular(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#

Generate mask of circle from given area and x-y-position on tensor.

Args:
index_grid (tuple[tensor, tensor]):

x and y indices of area to be masked.

params (dict[str, tensor]):

Value for each parameter.

Returns:
torch.Tensor:

Leaf mask.

deadleaves.leaf_masks.rectangular(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#

Generate mask of rectangle from given area, aspect ratio, orientation, and x-y-position on tensor.

Args:
index_grid (tuple[tensor, tensor]):

x and y indices of area to be masked.

params (dict[str, tensor]):

Value for each parameter.

Returns:
torch.Tensor:

Leaf mask.

deadleaves.leaf_masks.ellipsoid(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#

Generate mask of ellipsoid from given area, aspect ratio, orientation, and x-y-position on tensor.

Args:
index_grid (tuple[tensor, tensor]):

x and y indices of area to be masked.

params (dict[str, tensor]):

Value for each parameter.

Returns:
torch.Tensor:

Leaf mask.

deadleaves.leaf_masks.polygon(index_grid: tuple[torch.Tensor, torch.Tensor], params: dict[str, torch.Tensor] | pandas.Series) torch.Tensor#

Generate mask of regular polygon from given area, number of vertices and x-y-position on tensor.

Args:
index_grid (tuple[tensor, tensor]):

x and y indices of area to be masked.

params (dict[str, tensor]):

Value for each parameter.

Returns:
torch.Tensor:

Leaf mask.

deadleaves.leaf_masks.leaf_aabb(params: dict[str, torch.Tensor], leaf_shape: str) tuple[int, int, int, int]#

Compute the axis-aligned bounding box of a leaf.

Args:
params:

Sampled leaf parameters (x_pos, y_pos, area / radius, …).

leaf_shape:

One of “circular”, “ellipsoid”, “rectangular”, “polygon”.

Returns:

(y_min, x_min, y_max, x_max) as ints, not yet clipped to canvas.