Skip to content

Commit 247da5d

Browse files
feat: added min and max value to algorithms (#783)
* feat: added min and max value to algorithms * feat: add title and description to algorithm metadata * lint * update changelog --------- Co-authored-by: vincentsarago <[email protected]>
1 parent 49d5f8e commit 247da5d

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### titiler.core
66

77
* Add `use_epsg` parameter to WMTS endpoint to resolve ArcMAP issues and fix XML formating (author @gadomski, https://github.com/developmentseed/titiler/pull/782)
8+
* Add more OpenAPI metadata for algorithm (author @JinIgarashi, https://github.com/developmentseed/titiler/pull/783)
89

910
### titiler.application
1011

src/titiler/core/titiler/core/algorithm/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def __call__(self, img: ImageData) -> ImageData:
3232
class AlgorithmMetadata(BaseModel):
3333
"""Algorithm metadata."""
3434

35+
title: Optional[str] = None
36+
description: Optional[str] = None
37+
3538
inputs: Dict
3639
outputs: Dict
3740
parameters: Dict

src/titiler/core/titiler/core/algorithm/dem.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""titiler.core.algorithm DEM."""
22

33
import numpy
4+
from pydantic import Field
45
from rasterio import windows
56
from rio_tiler.colormap import apply_cmap, cmap
67
from rio_tiler.models import ImageData
@@ -12,10 +13,13 @@
1213
class HillShade(BaseAlgorithm):
1314
"""Hillshade."""
1415

16+
title: str = "Hillshade"
17+
description: str = "Create hillshade from DEM dataset."
18+
1519
# parameters
16-
azimuth: int = 90
17-
angle_altitude: float = 90.0
18-
buffer: int = 3
20+
azimuth: int = Field(90, ge=0, lt=360)
21+
angle_altitude: float = Field(90.0, ge=-90.0, lt=90.0)
22+
buffer: int = Field(3, ge=0, lt=99)
1923

2024
# metadata
2125
input_nbands: int = 1
@@ -61,11 +65,14 @@ class Contours(BaseAlgorithm):
6165
Original idea from https://custom-scripts.sentinel-hub.com/dem/contour-lines/
6266
"""
6367

68+
title: str = "Contours"
69+
description: str = "Create contours from DEM dataset."
70+
6471
# parameters
65-
increment: int = 35
66-
thickness: int = 1
67-
minz: int = -12000
68-
maxz: int = 8000
72+
increment: int = Field(35, ge=0, lt=999)
73+
thickness: int = Field(1, ge=0, lt=10)
74+
minz: int = Field(-12000, ge=-99999, lt=99999)
75+
maxz: int = Field(8000, ge=-99999, lt=99999)
6976

7077
# metadata
7178
input_nbands: int = 1
@@ -99,6 +106,9 @@ def __call__(self, img: ImageData) -> ImageData:
99106
class Terrarium(BaseAlgorithm):
100107
"""Encode DEM into RGB (Mapzen Terrarium)."""
101108

109+
title: str = "Terrarium"
110+
description: str = "Encode DEM into RGB (Mapzen Terrarium)."
111+
102112
# metadata
103113
input_nbands: int = 1
104114
output_nbands: int = 3
@@ -122,9 +132,12 @@ def __call__(self, img: ImageData) -> ImageData:
122132
class TerrainRGB(BaseAlgorithm):
123133
"""Encode DEM into RGB (Mapbox Terrain RGB)."""
124134

135+
title: str = "Terrarium"
136+
description: str = "Encode DEM into RGB (Mapbox Terrain RGB)."
137+
125138
# parameters
126-
interval: float = 0.1
127-
baseval: float = -10000.0
139+
interval: float = Field(0.1, ge=0.0, lt=1.0)
140+
baseval: float = Field(-10000.0, ge=-99999.0, lt=99999.0)
128141

129142
# metadata
130143
input_nbands: int = 1

src/titiler/core/titiler/core/algorithm/index.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
class NormalizedIndex(BaseAlgorithm):
1212
"""Normalized Difference Index."""
1313

14+
title: str = "Normalized Difference Index"
15+
description: str = "Compute normalized difference index from two bands."
16+
1417
# metadata
1518
input_nbands: int = 2
1619
output_nbands: int = 1

src/titiler/core/titiler/core/factory.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,15 @@ def metadata(algorithm: BaseAlgorithm) -> AlgorithmMetadata:
16671667
"""Algorithm Metadata"""
16681668
props = algorithm.model_json_schema()["properties"]
16691669

1670+
# title and description
1671+
info = {
1672+
k: v["default"]
1673+
for k, v in props.items()
1674+
if k == "title" or k == "description"
1675+
}
1676+
title = info.get("title", None)
1677+
description = info.get("description", None)
1678+
16701679
# Inputs Metadata
16711680
ins = {
16721681
k.replace("input_", ""): v["default"]
@@ -1685,9 +1694,18 @@ def metadata(algorithm: BaseAlgorithm) -> AlgorithmMetadata:
16851694
params = {
16861695
k: v
16871696
for k, v in props.items()
1688-
if not k.startswith("input_") and not k.startswith("output_")
1697+
if not k.startswith("input_")
1698+
and not k.startswith("output_")
1699+
and k != "title"
1700+
and k != "description"
16891701
}
1690-
return AlgorithmMetadata(inputs=ins, outputs=outs, parameters=params)
1702+
return AlgorithmMetadata(
1703+
title=title,
1704+
description=description,
1705+
inputs=ins,
1706+
outputs=outs,
1707+
parameters=params,
1708+
)
16911709

16921710
@self.router.get(
16931711
"/algorithms",

0 commit comments

Comments
 (0)