diff --git a/services/eoapi.json b/services/eoapi.json index 39c5fee..cd7ad50 100644 --- a/services/eoapi.json +++ b/services/eoapi.json @@ -341,7 +341,7 @@ "tile_size": 256, "minzoom": 12, "maxzoom": 19, - "extent": [29.987132801982625, 31.587422555628876, -30.8587632892144, -28.886191362214085] + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] }, "enabled": true, "process": { @@ -401,6 +401,12 @@ "inputMax": 5000, "outputMin": 0, "outputMax": 255 + } + }, + "trunc": { + "process_id": "trunc", + "arguments": { + "x": {"from_node": "linear1"} }, "result": true } @@ -433,7 +439,7 @@ "tile_size": 256, "minzoom": 12, "maxzoom": 19, - "extent": [29.987132801982625, 31.587422555628876, -30.8587632892144, -28.886191362214085] + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] }, "enabled": true, "process": { @@ -490,6 +496,12 @@ "inputMax": 1, "outputMin": 0, "outputMax": 255 + } + }, + "trunc": { + "process_id": "trunc", + "arguments": { + "x": {"from_node": "linear1"} }, "result": true } @@ -522,7 +534,7 @@ "tile_size": 256, "minzoom": 12, "maxzoom": 19, - "extent": [29.987132801982625, 31.587422555628876, -30.8587632892144, -28.886191362214085] + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] }, "enabled": true, "process": { @@ -604,11 +616,17 @@ "outputMax": 255 } }, + "trunc": { + "process_id": "trunc", + "arguments": { + "x": {"from_node": "linear_scale_range"} + } + }, "save5": { "process_id": "save_result", "arguments": { "data": { - "from_node": "linear_scale_range" + "from_node": "trunc" }, "format": "PNG" }, @@ -629,7 +647,7 @@ "tile_size": 256, "minzoom": 12, "maxzoom": 19, - "extent": [29.987132801982625, 31.587422555628876, -30.8587632892144, -28.886191362214085] + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] }, "enabled": true, "process": { @@ -696,8 +714,8 @@ "tile_size": 256, "minzoom": 12, "maxzoom": 19, - "extent": [29.987132801982625,-31.587422555628876, 30.8587632892144, -28.886191362214085] - }, + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] + }, "enabled": true, "process": { "process_graph": { @@ -752,5 +770,199 @@ "parameters": [] } } + }, + "48ce6183-d431-4625-b492-ab2f1b63c00a": { + "user_id": "12d6b89f-0f26-4fe7-a461-67418919b794", + "service": { + "id": "48ce6183-d431-4625-b492-ab2f1b63c00a", + "title": "South-Africa Flooding 2022 - NDVI - Viridis", + "type": "XYZ", + "configuration": { + "tile_size": 256, + "minzoom": 12, + "maxzoom": 19, + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] + }, + "enabled": true, + "process": { + "process_graph": { + "load1": { + "process_id": "load_collection_and_reduce", + "arguments": { + "bands": [ + "ms_analytic" + ], + "properties": {}, + "id": "MAXAR_southafrica_flooding22", + "spatial_extent": { + "east": { + "from_parameter": "spatial_extent_east" + }, + "north": { + "from_parameter": "spatial_extent_north" + }, + "south": { + "from_parameter": "spatial_extent_south" + }, + "west": { + "from_parameter": "spatial_extent_west" + } + }, + "temporal_extent": [ + "2022-04-21T00:00:00Z", + "2022-05-01T00:00:00Z" + ] + } + }, + "ndvi": { + "process_id": "ndvi", + "arguments": { + "data": { + "from_node": "load1" + }, + "nir": 8, + "red": 1 + } + }, + "apply4": { + "process_id": "apply", + "arguments": { + "data": {"from_node": "ndvi"}, + "process": { + "process_graph": { + "linear1": { + "process_id": "linear_scale_range", + "arguments": { + "x": {"from_parameter": "x"}, + "inputMin": -1, + "inputMax": 1, + "outputMin": 0, + "outputMax": 255 + } + }, + "trunc": { + "process_id": "trunc", + "arguments": { + "x": {"from_node": "linear1"} + }, + "result": true + } + } + } + } + }, + "cmap": { + "process_id": "get_colormap", + "arguments": { + "name": "viridis" + } + }, + "colormap1": { + "process_id": "colormap", + "arguments": { + "data": { + "from_node": "apply4" + }, + "colormap": { + "from_node": "cmap" + } + } + }, + "save5": { + "process_id": "save_result", + "arguments": { + "data": { + "from_node": "colormap1" + }, + "format": "PNG" + }, + "result": true + } + }, + "parameters": [] + } + } + }, + "b9cb48ae-f210-401d-a644-859deefafb18": { + "user_id": "12d6b89f-0f26-4fe7-a461-67418919b794", + "service": { + "id": "b9cb48ae-f210-401d-a644-859deefafb18", + "title": "South-Africa Flooding 2022 - NDVI - Custom ColorMap", + "type": "XYZ", + "configuration": { + "tile_size": 256, + "minzoom": 12, + "maxzoom": 19, + "extent": [29.987132801982625, -30.8587632892144, 31.587422555628876, -28.886191362214085] + }, + "enabled": true, + "process": { + "process_graph": { + "load1": { + "process_id": "load_collection_and_reduce", + "arguments": { + "bands": [ + "ms_analytic" + ], + "properties": {}, + "id": "MAXAR_southafrica_flooding22", + "spatial_extent": { + "east": { + "from_parameter": "spatial_extent_east" + }, + "north": { + "from_parameter": "spatial_extent_north" + }, + "south": { + "from_parameter": "spatial_extent_south" + }, + "west": { + "from_parameter": "spatial_extent_west" + } + }, + "temporal_extent": [ + "2022-04-21T00:00:00Z", + "2022-05-01T00:00:00Z" + ] + } + }, + "ndvi": { + "process_id": "ndvi", + "arguments": { + "data": { + "from_node": "load1" + }, + "nir": 8, + "red": 1 + } + }, + "colormap1": { + "process_id": "colormap", + "arguments": { + "data": { + "from_node": "ndvi" + }, + "colormap": [ + [[-2, -1], [0, 255, 0, 255]], + [[-1, 0], [0, 255, 0, 255]], + [[0, 0.5], [255, 0, 0, 255]], + [[0.5, 1.1], [255, 255, 0, 255]] + ] + } + }, + "save5": { + "process_id": "save_result", + "arguments": { + "data": { + "from_node": "colormap1" + }, + "format": "PNG" + }, + "result": true + } + }, + "parameters": [] + } + } } } diff --git a/titiler/openeo/processes/data/colormap.json b/titiler/openeo/processes/data/colormap.json new file mode 100644 index 0000000..255c0d3 --- /dev/null +++ b/titiler/openeo/processes/data/colormap.json @@ -0,0 +1,81 @@ +{ + "id": "colormap", + "summary": "Apply a color formula to an image.", + "description": "Return Image data with a colormap applied.", + "categories": [ + "images", + "color" + ], + "parameters": [ + { + "name": "data", + "description": "An image.", + "schema": { + "type": "object", + "subtype": "imagedata" + } + }, + { + "name": "colormap", + "description": "The colormap to apply.", + "schema": [ + { + "title": "GDAL ColorMap", + "description":"An GDAL defined colormap in form of `{val: (r, g, b, alpha), ...}`.", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { + "type": "number" + } + } + } + }, + { + "title": "Interval ColorMap", + "description":"An Interval colormap in form of `[[(min, max), (r, g, b, alpha)], ...]`.", + "type": "array", + "minItems": 1, + "items": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "array", + "prefixItems": [ + { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "number" + } + }, + { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { + "type": "number" + } + } + ] + } + } + } + ] + } + ], + "returns": { + "description": "The image with the colormap applied.", + "schema": { + "type": "object", + "subtype": "imagedata" + } + }, + "exceptions": {}, + "examples": [] +} diff --git a/titiler/openeo/processes/data/get_colormap.json b/titiler/openeo/processes/data/get_colormap.json new file mode 100644 index 0000000..a028f19 --- /dev/null +++ b/titiler/openeo/processes/data/get_colormap.json @@ -0,0 +1,77 @@ +{ + "id": "get_colormap", + "summary": "Get rio-tiler Colormap object.", + "description": "Get rio-tiler Colormap object.", + "categories": [ + "color" + ], + "parameters": [ + { + "name": "name", + "description": "The name of the colormap.", + "schema": { + "type": "string" + } + } + ], + "returns": { + "description": "The Colormap object.", + "schema": [ + { + "name": "colormap", + "description": "The colormap to apply.", + "schema": [ + { + "title": "GDAL ColorMap", + "description":"An GDAL defined colormap in form of `{val: (r, g, b, alpha), ...}`.", + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { + "type": "number" + } + } + } + }, + { + "title": "Interval ColorMap", + "description":"An Interval colormap in form of `[[(min, max), (r, g, b, alpha)], ...]`.", + "type": "array", + "minItems": 1, + "items": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "array", + "prefixItems": [ + { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "number" + } + }, + { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { + "type": "number" + } + } + ] + } + } + } + ] + } + ] + }, + "exceptions": {}, + "examples": [] +} diff --git a/titiler/openeo/processes/implementations/apply.py b/titiler/openeo/processes/implementations/apply.py index b77e9e2..681b96c 100644 --- a/titiler/openeo/processes/implementations/apply.py +++ b/titiler/openeo/processes/implementations/apply.py @@ -26,7 +26,6 @@ def _process_img(img: ImageData): assets=img.assets, crs=img.crs, bounds=img.bounds, - band_names=img.band_names, ) if isinstance(data, ImageData): diff --git a/titiler/openeo/processes/implementations/image.py b/titiler/openeo/processes/implementations/image.py index a00412c..3dda28d 100644 --- a/titiler/openeo/processes/implementations/image.py +++ b/titiler/openeo/processes/implementations/image.py @@ -3,10 +3,18 @@ from typing import Sequence import numpy +from rio_tiler.colormap import cmap as default_cmap +from rio_tiler.types import ColorMapType from .data_model import ImageData -__all__ = ["image_indexes", "to_array", "color_formula"] +__all__ = [ + "image_indexes", + "to_array", + "color_formula", + "colormap", + "get_colormap", +] def image_indexes(data: ImageData, indexes: Sequence[int]) -> ImageData: @@ -41,3 +49,13 @@ def to_array(data: ImageData) -> numpy.ma.MaskedArray: def color_formula(data: ImageData, formula: str) -> ImageData: """Apply color formula to ImageData.""" return data.apply_color_formula(formula) + + +def get_colormap(name: str) -> ColorMapType: + """Return rio-tiler colormap.""" + return default_cmap.get(name) + + +def colormap(data: ImageData, colormap: ColorMapType) -> ImageData: + """Apply colormap to ImageData.""" + return data.apply_colormap(colormap) diff --git a/titiler/openeo/processes/implementations/indices.py b/titiler/openeo/processes/implementations/indices.py index ed69902..16e2f46 100644 --- a/titiler/openeo/processes/implementations/indices.py +++ b/titiler/openeo/processes/implementations/indices.py @@ -16,5 +16,7 @@ def ndvi(data: ImageData, nir: int, red: int): assets=data.assets, crs=data.crs, bounds=data.bounds, - band_names=data.band_names, + band_names=[ + "ndvi", + ], )