Skip to content

Commit

Permalink
consistent and descriptive forest filter query params; detailed decod…
Browse files Browse the repository at this point in the history
…ing doc
  • Loading branch information
solomon-negusse committed Nov 13, 2024
1 parent 74e8504 commit 2692cd6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/routes/titiler/umd_glad_dist_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ async def glad_dist_alerts_raster_tile(
description="Only show alerts until given date.",
),
render_type: RenderType = Query(
RenderType.encoded, description="Render true color or encoded tiles"
RenderType.encoded,
description="Render true color or encoded tiles. Encoded tiles have the alert date and confidence packed in the image RGB channels for front-end interactive use, such as date filtering with supported technologies. Decoding instructions: Alert Date is calculated as `red * 255 + green`, representing days since 2020-12-31. Confidence is calculated as `floor(blue / 100)`, with values of `2` (high) or `1` (low). Intensity is calculated as `mod(blue, 100)`, with a maximum value of `55`.",
),
alert_confidence: Optional[AlertConfidence] = Query(
AlertConfidence.low,
description="Show alerts that are at least of this confidence level",
),
tree_cover_density: Optional[int] = Query(
tree_cover_density_threshold: Optional[int] = Query(
None,
ge=0,
le=100,
description="Alerts in pixels with tree cover density (in percent) below this threshold won't be displayed. `umd_tree_cover_density_2010` is used for this masking.",
),
tree_cover_height: Optional[int] = Query(
tree_cover_height_threshold: Optional[int] = Query(
None,
description="Alerts in pixels with tree cover height (in meters) below this threshold won't be displayed. `umd_tree_cover_height_2020` dataset in the API is used for this masking.",
),
tree_cover_loss_cutoff: Optional[int] = Query(
tree_cover_loss_threshold: Optional[int] = Query(
None,
ge=2021,
description="""This filter is to be used in conjunction with `tree_cover_density` and `tree_cover_height` filters to detect only alerts in forests, by masking out pixels that have had tree cover loss prior to the alert.""",
Expand All @@ -89,27 +90,27 @@ async def glad_dist_alerts_raster_tile(
end_date=end_date,
render_type=render_type,
alert_confidence=alert_confidence,
tree_cover_density_mask=tree_cover_density,
tree_cover_height_mask=tree_cover_height,
tree_cover_loss_mask=tree_cover_loss_cutoff,
tree_cover_density_mask=tree_cover_density_threshold,
tree_cover_height_mask=tree_cover_height_threshold,
tree_cover_loss_mask=tree_cover_loss_threshold,
)

filter_datasets = GLOBALS.dist_alerts_forest_filters
if tree_cover_density:
if tree_cover_density_threshold:
filter_dataset = filter_datasets["tree_cover_density"]
with COGReader(
f"s3://{DATA_LAKE_BUCKET}/{filter_dataset['dataset']}/{filter_dataset['version']}/raster/epsg-4326/cog/default.tif"
) as reader:
dist_alert.tree_cover_density_data = reader.tile(tile_x, tile_y, zoom)

if tree_cover_height:
if tree_cover_height_threshold:
filter_dataset = filter_datasets["tree_cover_height"]
with COGReader(
f"s3://{DATA_LAKE_BUCKET}/{filter_dataset['dataset']}/{filter_dataset['version']}/raster/epsg-4326/cog/default.tif"
) as reader:
dist_alert.tree_cover_height_data = reader.tile(tile_x, tile_y, zoom)

if tree_cover_loss_cutoff:
if tree_cover_loss_threshold:
filter_dataset = filter_datasets["tree_cover_loss"]
with COGReader(
f"s3://{DATA_LAKE_BUCKET}/{filter_dataset['dataset']}/{filter_dataset['version']}/raster/epsg-4326/cog/default.tif"
Expand Down

0 comments on commit 2692cd6

Please sign in to comment.