Skip to content

Commit

Permalink
feat: add title and description to algorithm metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
JinIgarashi committed Mar 6, 2024
1 parent f7752c5 commit 0210233
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/titiler/core/titiler/core/algorithm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __call__(self, img: ImageData) -> ImageData:

class AlgorithmMetadata(BaseModel):
"""Algorithm metadata."""
title: Optional[str] = None
description: Optional[str] = None

inputs: Dict
outputs: Dict
Expand Down
12 changes: 12 additions & 0 deletions src/titiler/core/titiler/core/algorithm/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
class HillShade(BaseAlgorithm):
"""Hillshade."""

title: str = "Hillshade"
description: str = "Create hillshade from DEM dataset."

# parameters
azimuth: int = Field(90, ge=0, lt=360)
angle_altitude: float = Field(90.0, ge=-90.0, lt=90.0)
Expand Down Expand Up @@ -62,6 +65,9 @@ class Contours(BaseAlgorithm):
Original idea from https://custom-scripts.sentinel-hub.com/dem/contour-lines/
"""

title: str = "Contours"
description: str = "Create contours from DEM dataset."

# parameters
increment: int = Field(35, ge=0, lt=999)
thickness: int = Field(1, ge=0, lt=10)
Expand Down Expand Up @@ -100,6 +106,9 @@ def __call__(self, img: ImageData) -> ImageData:
class Terrarium(BaseAlgorithm):
"""Encode DEM into RGB (Mapzen Terrarium)."""

title: str = "Terrarium"
description: str = "Encode DEM into RGB (Mapzen Terrarium)."

# metadata
input_nbands: int = 1
output_nbands: int = 3
Expand All @@ -123,6 +132,9 @@ def __call__(self, img: ImageData) -> ImageData:
class TerrainRGB(BaseAlgorithm):
"""Encode DEM into RGB (Mapbox Terrain RGB)."""

title: str = "Terrarium"
description: str = "Encode DEM into RGB (Mapbox Terrain RGB)."

# parameters
interval: float = Field(0.1, ge=0.0, lt=1.0)
baseval: float = Field(-10000.0, ge=-99999.0, lt=99999.0)
Expand Down
3 changes: 3 additions & 0 deletions src/titiler/core/titiler/core/algorithm/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
class NormalizedIndex(BaseAlgorithm):
"""Normalized Difference Index."""

title: str = "Normalized Difference Index"
description: str = "Compute normalized difference index from two bands."

# metadata
input_nbands: int = 2
output_nbands: int = 1
Expand Down
13 changes: 11 additions & 2 deletions src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,15 @@ def metadata(algorithm: BaseAlgorithm) -> AlgorithmMetadata:
"""Algorithm Metadata"""
props = algorithm.model_json_schema()["properties"]

# title and description
info = {
k: v['default']
for k, v in props.items()
if k == "title" or k == "description"
}
title = info.get('title', None)
description = info.get('description', None)

# Inputs Metadata
ins = {
k.replace("input_", ""): v["default"]
Expand All @@ -1671,9 +1680,9 @@ def metadata(algorithm: BaseAlgorithm) -> AlgorithmMetadata:
params = {
k: v
for k, v in props.items()
if not k.startswith("input_") and not k.startswith("output_")
if not k.startswith("input_") and not k.startswith("output_") and k != "title" and k != "description"
}
return AlgorithmMetadata(inputs=ins, outputs=outs, parameters=params)
return AlgorithmMetadata(title=title, description=description, inputs=ins, outputs=outs, parameters=params)

@self.router.get(
"/algorithms",
Expand Down

0 comments on commit 0210233

Please sign in to comment.