Skip to content

Commit

Permalink
Merge pull request #114 from wri/fix-distalert-no-context
Browse files Browse the repository at this point in the history
Flat dist alert structure for cases without context layer
  • Loading branch information
yellowcap authored Jan 20, 2025
2 parents 1eaf521 + 26130b8 commit d0eecb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/test_dist_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,20 @@ def test_dist_alert_tool_buffer():
assert (
result["natural short vegetation"] < result_buffered["natural short vegetation"]
)


def test_dist_alert_tool_no_context():
result = tools.dist_alerts_tool.invoke(
input={
"name": "BRA.13.369_2",
"gadm_id": "BRA.13.369_2",
"gadm_level": 2,
"context_layer_name": None,
"threshold": 8,
"min_date": datetime.date(2021, 8, 12),
"max_date": datetime.date(2024, 8, 12),
}
)

assert len(result) == 1
assert "disturbances" in result
6 changes: 3 additions & 3 deletions zeno/agents/distalert/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def get_distalerts_unfiltered(
scale=DIST_ALERT_STATS_SCALE,
).getInfo()

zone_stats_result = {"context_layer_name": None}
for feat in zone_stats["features"]:
zone_stats_result[name] = {"disturbances": feat["properties"]["sum"]}
zone_stats_result= {"disturbances": zone_stats["features"][0]["properties"]["sum"]}

vectorize = (
distalerts.gte(threshold).updateMask(distalerts.gte(threshold)).selfMask()
Expand Down Expand Up @@ -233,6 +231,8 @@ def dist_alerts_tool(
This tool quantifies vegetation disturbance alerts over an area of interest
and summarizes the alerts in statistics by context layer types.
The unit of disturbances that are returned are hectares.
"""
print("---DIST ALERTS TOOL---")

Expand Down

0 comments on commit d0eecb0

Please sign in to comment.