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
2 changes: 1 addition & 1 deletion app/routes/titiler/algorithms/integrated_alerts_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def create_mask(self):
condition are masked.
"""

mask = self.alert_drivers > 0
mask = ~self.no_data * (self.alert_drivers > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch of the dark pixels issue


if self.alert_confidence:
confidence_mask = (
Expand Down
15 changes: 9 additions & 6 deletions app/routes/titiler/gfw_integrated_alerts_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from typing import Optional, Tuple

from aenum import Enum, extend_enum
from fastapi import APIRouter, Depends, Query, Response
from fastapi import APIRouter, Depends, Query, Response, HTTPException
from rio_tiler.errors import TileOutsideBounds
from titiler.core.resources.enums import ImageType
from titiler.core.utils import render_image

Expand Down Expand Up @@ -81,7 +82,10 @@ async def gfw_integrated_alerts_drivers_raster_tile(
folder: str = f"s3://{DATA_LAKE_BUCKET}/gfw_integrated_alerts/{integrated_alerts_version}/raster/epsg-4326/cog"
with AlertsReader(input=folder) as reader:
tile_x, tile_y, zoom = xyz
image_data = reader.tile(tile_x, tile_y, zoom, bands=bands)
try:
image_data = reader.tile(tile_x, tile_y, zoom, bands=bands)
except TileOutsideBounds:
raise HTTPException(status_code=404, detail="Tile outside of bounds of this dataset")

integrated_alerts_drivers = IntegratedAlertsDrivers(
start_date=start_date,
Expand All @@ -93,11 +97,10 @@ async def gfw_integrated_alerts_drivers_raster_tile(
with COGReader(
f"s3://{DATA_LAKE_BUCKET}/wur_integration_alert_drivers_class/{version}/raster/epsg-4326/cog/class.tif"
) as reader:
if reader.tile_exists(tile_x, tile_y, zoom):
try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's too bad that the reader.tile_exists() call doesn't catch all particular cases of a TileOutsideBounds requests. I'm just wondering if you could do a ChatGPT/gemini query to see if there is a better function or condition check that would figure out when the access will be out of bounds that wouldn't require catching an exception. But I understand the exception catching is working, so no need to fix unless you find something that seems solid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, worth exploring, thanks! Will do as a follow-up though.

integrated_alerts_drivers.alert_drivers = reader.tile(tile_x, tile_y, zoom).data[0]
else:
print("Non-existent tile, wur_integration_alert_drivers_class")
integrated_alerts_drivers.alert_drivers = None
except TileOutsideBounds:
raise HTTPException(status_code=404, detail="Tile outside of bounds of this dataset")

processed_image = integrated_alerts_drivers(image_data)

Expand Down