-
Notifications
You must be signed in to change notification settings - Fork 1
GTC-3442: Catch rasterio exceptions on missing data for integrated drivers #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe8e5b2
fc2f7d8
d18a93d
27347c0
1ec45d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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, | ||
|
|
@@ -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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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