Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions docs/guides/inventories.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ To adjust tree measurements based on conditions:
# Reduce height of all trees over 20m by 10%
tree_inventory = inventories.create_tree_inventory_from_treemap(
modifications={
"conditions": [{"field": "HT", "operator": "gt", "value": 20}],
"actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
"conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
"actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
}
)
```
Expand All @@ -84,6 +84,36 @@ tree_inventory = inventories.create_tree_inventory_from_treemap(
)
```

To remove trees based on attribute conditions:

```python
# Remove all trees with diameter less than 10cm
tree_inventory = inventories.create_tree_inventory_from_treemap(
modifications={
"conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
"actions": [{"attribute": "all", "modifier": "remove"}]
}
)
```

You can also combine multiple modifications, including removal:

```python
# Reduce height of tall trees AND remove small trees
tree_inventory = inventories.create_tree_inventory_from_treemap(
modifications=[
{
"conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
"actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
},
{
"conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
"actions": [{"attribute": "all", "modifier": "remove"}]
}
]
)
```

## How to Apply Forest Management Treatments

To thin to a target basal area:
Expand Down Expand Up @@ -157,8 +187,8 @@ If you need to create an inventory with multiple modifications:
tree_inventory = inventories.create_tree_inventory_from_treemap(
seed=42,
modifications={
"conditions": [{"field": "HT", "operator": "gt", "value": 20}],
"actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
"conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
"actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
},
treatments={
"method": "proportionalThinning",
Expand Down
72 changes: 55 additions & 17 deletions fastfuels_sdk/inventories.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,29 @@ def create_tree_inventory(
- seed: Integer for reproducible generation (optional)

modifications : dict or list[dict], optional
List of modifications to apply. Each modification has:
- conditions: List of conditions that must be met
- actions: List of actions to apply when conditions are met
Rules for modifying or removing tree attributes. Each modification has:
- conditions: List of conditions that trees must meet
- actions: List of actions to apply to matching trees

Example:
Example - Modify attribute:
```python
{
"conditions": [{"field": "HT", "operator": "gt", "value": 20}],
"actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
"conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
"actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
}
```

Example - Remove trees:
```python
{
"conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
"actions": [{"attribute": "all", "modifier": "remove"}]
}
```

Available attributes: HT (height), DIA (diameter), CR (crown ratio), SPCD (species code)
Available modifiers: multiply, divide, add, subtract, replace, remove

treatments : dict or list[dict], optional
List of silvicultural treatments to apply. Supports:

Expand Down Expand Up @@ -220,8 +231,17 @@ def create_tree_inventory(
>>> inventory = inventories.create_tree_inventory(
... sources="TreeMap",
... modifications={
... "conditions": [{"field": "HT", "operator": "gt", "value": 20}],
... "actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
... "conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
... "actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
... }
... )

Remove small trees:
>>> inventory = inventories.create_tree_inventory(
... sources="TreeMap",
... modifications={
... "conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
... "actions": [{"attribute": "all", "modifier": "remove"}]
... }
... )

Expand Down Expand Up @@ -314,24 +334,34 @@ def create_tree_inventory_from_treemap(
- "Meta2024": Meta's 2024 global canopy height map at 1-meter resolution

modifications : dict or list[dict], optional
Rules for modifying tree attributes. Each modification includes:
Rules for modifying or removing tree attributes. Each modification includes:
- conditions: List of criteria that trees must meet
- actions: Changes to apply to matching trees

Example - Reduce height of tall trees:
Example - Modify attribute:
```python
{
"conditions": [{"field": "HT", "operator": "gt", "value": 20}],
"actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
"conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
"actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
}
```

Available fields:
Example - Remove trees:
```python
{
"conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
"actions": [{"attribute": "all", "modifier": "remove"}]
}
```

Available attributes:
- HT: Height (meters)
- DIA: Diameter at breast height (centimeters)
- CR: Crown ratio (0-1)
- SPCD: Species code (integer)

Available modifiers: multiply, divide, add, subtract, replace, remove

treatments : dict or list[dict], optional
Silvicultural treatments to apply. Supports:

Expand Down Expand Up @@ -395,8 +425,16 @@ def create_tree_inventory_from_treemap(
Reduce height of tall trees:
>>> tree_inventory = inventories.create_tree_inventory_from_treemap(
... modifications={
... "conditions": [{"field": "HT", "operator": "gt", "value": 20}],
... "actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
... "conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
... "actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
... }
... )

Remove small trees:
>>> tree_inventory = inventories.create_tree_inventory_from_treemap(
... modifications={
... "conditions": [{"attribute": "DIA", "operator": "lt", "value": 10}],
... "actions": [{"attribute": "all", "modifier": "remove"}]
... }
... )

Expand All @@ -418,8 +456,8 @@ def create_tree_inventory_from_treemap(
>>> tree_inventory = inventories.create_tree_inventory_from_treemap(
... seed=42,
... modifications={
... "conditions": [{"field": "HT", "operator": "gt", "value": 20}],
... "actions": [{"field": "HT", "modifier": "multiply", "value": 0.9}]
... "conditions": [{"attribute": "HT", "operator": "gt", "value": 20}],
... "actions": [{"attribute": "HT", "modifier": "multiply", "value": 0.9}]
... },
... treatments={
... "method": "proportionalThinning",
Expand Down
Loading