Skip to content

Commit

Permalink
Merge branch 'dev' into gtc-3025/filter-alerts-by-forest
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon-negusse authored Nov 1, 2024
2 parents a8ffd95 + bc349c0 commit 78af193
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .routes import preview

from .routes.titiler import routes as titiler_routes
from .routes.titiler.integrated_alerts import router as alerts_router
from .routes.titiler.gfw_integrated_alerts import router as integrated_alerts_router
from .routes.titiler.umd_glad_dist_alerts import router as dist_alerts_router

gunicorn_logger = logging.getLogger("gunicorn.error")
Expand All @@ -57,7 +57,7 @@
burned_areas_tiles.router,
dynamic_vector_tiles.router,
vector_tiles.router,
alerts_router,
integrated_alerts_router,
dist_alerts_router,
umd_tree_cover_loss_raster_tiles.router,
umd_glad_landsat_alerts_raster_tiles.router,
Expand Down
20 changes: 17 additions & 3 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 RenderType
from app.models.enumerators.titiler import IntegratedAlertConfidence, RenderType

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

conf_colors: Optional[OrderedDict] = None

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


record_start_date: str = "2014-12-31"

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

# metadata
input_nbands: int = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class GfwIntegratdAlertsVersions(str, Enum):
_versions = get_versions(dataset, TileCacheType.cog)
for _version in _versions:
extend_enum(GfwIntegratdAlertsVersions, _version, _version)
# TODO: add version validation


# will turn this on when we're ready to replace tile cache service
Expand All @@ -51,7 +50,7 @@ class GfwIntegratdAlertsVersions(str, Enum):
)
async def gfw_integrated_alerts_raster_tile(
*,
version,
version: GfwIntegratdAlertsVersions,
xyz: Tuple[int, int, int] = Depends(raster_xyz),
start_date: Optional[str] = Query(
None,
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/session_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ INSERT INTO public.assets (dataset, version, asset_type, creation_options, metad
INSERT INTO public.assets (dataset, version, asset_type, creation_options, metadata, fields, asset_id, status, asset_uri, is_managed, is_default)
VALUES ('umd_glad_landsat_alerts', 'v20210101', 'COG', '{"implementation": "default", "source_asset_id": "3ac4028e-798d-4854-9b5e-6a9771ed06ed", "resampling":"mode", "blocksize": 256}', '{}', '[]', '821f0211-e439-4302-93bb-0925099df65d', 'saved', 'my_uri13', true, false);

INSERT INTO public.datasets (dataset) VALUES ('gfw_integrated_alerts');
INSERT INTO public.versions (dataset, version, is_latest, status)
VALUES ('gfw_integrated_alerts', 'v20201012', true, 'saved');

INSERT INTO public.assets (dataset, version, asset_type, creation_options, metadata, fields, asset_id, status, asset_uri, is_managed, is_default)
VALUES ('gfw_integrated_alerts', 'v20201012', 'COG', '{"implementation": "default", "source_asset_id": "3ac4028e-798d-4854-9b5e-6a9771ed06dd", "resampling":"mode", "blocksize": 256}', '{}', '[]', '821f0211-e439-4302-93bb-0925099df66d', 'saved', 'my_uri14', true, false);


CREATE SCHEMA umd_modis_burned_areas;
CREATE TABLE umd_modis_burned_areas.v202003 (alert__date date, gfw_area__ha numeric, geom_wm geometry);
5 changes: 2 additions & 3 deletions tests/routes/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
def test_viirs_vector_tile_server(client):
"""
Basic test to check if empty data api response as expected
"""
"""Basic test to check if empty data api response as expected."""

response = client.get("/_latest")
api_data = response.json()
api_data["data"] = sorted(api_data["data"], key=lambda x: x["dataset"])

assert api_data == {
"data": [
{"dataset": "gfw_integrated_alerts", "version": "v20201012"},
{"dataset": "nasa_viirs_fire_alerts", "version": "v202003"},
{"dataset": "umd_glad_landsat_alerts", "version": "v20210101"},
{"dataset": "umd_modis_burned_areas", "version": "v202003"},
Expand Down

0 comments on commit 78af193

Please sign in to comment.