Skip to content

Commit

Permalink
don't use default alertconfidence enum; create separate alertconf enu…
Browse files Browse the repository at this point in the history
…m for dist/integrated alerts as we surface in api doc
  • Loading branch information
solomon-negusse committed Oct 25, 2024
1 parent d0e57d4 commit d255c24
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
5 changes: 5 additions & 0 deletions app/models/enumerators/titiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
class AlertConfidence(str, Enum):
low = "low"
high = "high"


class IntegratedAlertConfidence(str, Enum):
low = "low"
high = "high"
highest = "highest"


Expand Down
18 changes: 3 additions & 15 deletions app/routes/titiler/algorithms/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rio_tiler.models import ImageData
from titiler.core.algorithm import BaseAlgorithm

from app.models.enumerators.titiler import AlertConfidence, RenderType
from app.models.enumerators.titiler import RenderType

Colors: namedtuple = namedtuple("Colors", ["red", "green", "blue"])
AlertConfig: namedtuple = namedtuple("AlertConfig", ["confidence", "colors"])
Expand All @@ -18,25 +18,13 @@ class Alerts(BaseAlgorithm):
title: str = "Deforestation Alerts"
description: str = "Decode and visualize alerts"

conf_colors: OrderedDict = OrderedDict(
{
AlertConfidence.low: AlertConfig(
confidence=2, colors=Colors(237, 164, 194)
),
AlertConfidence.high: AlertConfig(
confidence=3, colors=Colors(220, 102, 153)
),
AlertConfidence.highest: AlertConfig(
confidence=4, colors=Colors(201, 42, 109)
),
}
)
conf_colors: OrderedDict = None

record_start_date: str = "2014-12-31"

start_date: Optional[str] = None
end_date: Optional[str] = None
alert_confidence: Optional[AlertConfidence] = None
alert_confidence: Optional[str] = None
render_type: Optional[RenderType] = RenderType.true_color

# metadata
Expand Down
8 changes: 4 additions & 4 deletions app/routes/titiler/algorithms/integrated_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from app.models.enumerators.titiler import AlertConfidence
from app.models.enumerators.titiler import IntegratedAlertConfidence

from .alerts import AlertConfig, Alerts, Colors

Expand All @@ -13,13 +13,13 @@ class IntegratedAlerts(Alerts):

conf_colors: OrderedDict = OrderedDict(
{
AlertConfidence.low: AlertConfig(
IntegratedAlertConfidence.low: AlertConfig(
confidence=2, colors=Colors(237, 164, 194)
),
AlertConfidence.high: AlertConfig(
IntegratedAlertConfidence.high: AlertConfig(
confidence=3, colors=Colors(220, 102, 153)
),
AlertConfidence.highest: AlertConfig(
IntegratedAlertConfidence.highest: AlertConfig(
confidence=4, colors=Colors(201, 42, 109)
),
}
Expand Down
7 changes: 4 additions & 3 deletions app/routes/titiler/integrated_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ...crud.sync_db.tile_cache_assets import get_versions
from ...models.enumerators.tile_caches import TileCacheType
from ...models.enumerators.titiler import RenderType
from ...models.enumerators.titiler import IntegratedAlertConfidence, RenderType
from .. import DATE_REGEX, optional_implementation_dependency, raster_xyz
from .algorithms.integrated_alerts import IntegratedAlerts
from .readers import AlertsReader
Expand Down Expand Up @@ -63,8 +63,9 @@ async def gfw_integrated_alerts_raster_tile(
render_type: RenderType = Query(
RenderType.encoded, description="Render true color or encoded tiles"
),
alert_confidence: Optional[bool] = Query(
None, description="Show alerts with at least this confidence level"
alert_confidence: Optional[IntegratedAlertConfidence] = Query(
IntegratedAlertConfidence.low,
description="Show alerts with at least this confidence level",
),
implementation: str = Depends(optional_implementation_dependency),
) -> Response:
Expand Down
2 changes: 1 addition & 1 deletion app/routes/titiler/umd_glad_dist_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def glad_dist_alerts_raster_tile(
render_type: RenderType = Query(
RenderType.encoded, description="Render true color or encoded tiles"
),
alert_confidence: Optional[bool] = Query(
alert_confidence: Optional[AlertConfidence] = Query(
AlertConfidence.low,
description="Show alerts that are at least of this confidence level",
),
Expand Down
7 changes: 3 additions & 4 deletions tests/titiler/test_alerts_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import numpy as np
import rasterio
from dateutil.relativedelta import relativedelta
from rio_tiler.models import ImageData

from app.models.enumerators.titiler import AlertConfidence, RenderType
from app.models.enumerators.titiler import IntegratedAlertConfidence, RenderType
from app.routes.titiler.algorithms.integrated_alerts import IntegratedAlerts
from tests.conftest import DATE_CONF_TIF, INTENSITY_TIF

Expand Down Expand Up @@ -50,7 +49,7 @@ def test_create_date_range_mask():

def test_create_confidence_mask():
"""Test confidence filters are applied correctly."""
alerts = IntegratedAlerts(alert_confidence=AlertConfidence.highest)
alerts = IntegratedAlerts(alert_confidence=IntegratedAlertConfidence.highest)
alerts.start_date = alerts.record_start_date

img = get_tile_data()
Expand All @@ -63,7 +62,7 @@ def test_create_confidence_mask():

def test_mask_logic_with_nodata():
"""Test that the mask properly handles no-data values."""
alerts = IntegratedAlerts(alert_confidence=AlertConfidence.low)
alerts = IntegratedAlerts(alert_confidence=IntegratedAlertConfidence.low)

img = get_tile_data()

Expand Down

0 comments on commit d255c24

Please sign in to comment.