diff --git a/app/routes/titiler/algorithms/alerts.py b/app/routes/titiler/algorithms/alerts.py index ac0bc8fd..2b403967 100644 --- a/app/routes/titiler/algorithms/alerts.py +++ b/app/routes/titiler/algorithms/alerts.py @@ -18,7 +18,7 @@ class Alerts(BaseAlgorithm): title: str = "Deforestation Alerts" description: str = "Decode and visualize alerts" - conf_colors: OrderedDict = None + conf_colors: Optional[OrderedDict] = None record_start_date: str = "2014-12-31" diff --git a/app/routes/titiler/algorithms/dist_alerts.py b/app/routes/titiler/algorithms/dist_alerts.py index 704045c9..6db2d16d 100644 --- a/app/routes/titiler/algorithms/dist_alerts.py +++ b/app/routes/titiler/algorithms/dist_alerts.py @@ -1,5 +1,4 @@ from collections import OrderedDict -from datetime import datetime from typing import Optional from pydantic import ConfigDict @@ -53,11 +52,13 @@ def create_mask(self): ) if self.tree_cover_loss_mask: + # Tree cover loss before 2020 can't be used to filter out pixels as not forest + # if they had tree cover loss. Instead we use tree cover height taken that year + # is used as source of truth. mask *= ( - self.tree_cover_loss_data.array[0, :, :] >= self.tree_cover_loss_mask - or self.tree_cover_loss_data.array[0, :, :] == 0 - or self.tree_cover_loss_data.array[0, :, :] - <= datetime.strptime(self.record_start_date, "%Y-%m-%d").year + (self.tree_cover_loss_data.array[0, :, :] >= self.tree_cover_loss_mask) + | (self.tree_cover_loss_data.array[0, :, :] == 0) + | (self.tree_cover_loss_data.array[0, :, :] <= 2020) ) return mask