-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82147ed
commit f7c90f8
Showing
49 changed files
with
2,768 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,40 @@ | ||
"""titiler.openeo.processes.""" | ||
|
||
import builtins | ||
import importlib | ||
import inspect | ||
import json | ||
import keyword | ||
from pathlib import Path | ||
|
||
from openeo_pg_parser_networkx import ProcessRegistry | ||
from openeo_pg_parser_networkx.process_registry import Process | ||
|
||
from .implementations import ( | ||
clip, | ||
linear_scale_range, | ||
normalized_difference, | ||
save_result, | ||
) | ||
from .implementations.core import process | ||
|
||
json_path = Path(__file__).parent / "specs" | ||
process_json_paths = [pg_path for pg_path in (json_path).glob("*.json")] # noqa: C416 | ||
PROCESS_SPECIFICATIONS = {f.stem: json.load(open(f)) for f in process_json_paths} | ||
json_path = Path(__file__).parent / "data" | ||
PROCESS_SPECIFICATIONS = {} | ||
for f in (json_path).glob("*.json"): | ||
spec_json = json.load(open(f)) | ||
process_name = spec_json["id"] | ||
# Make sure we don't overwrite any builtins (e.g min -> _min) | ||
if spec_json["id"] in dir(builtins) or keyword.iskeyword(spec_json["id"]): | ||
process_name = "_" + spec_json["id"] | ||
|
||
PROCESS_SPECIFICATIONS[process_name] = spec_json | ||
|
||
PROCESS_IMPLEMENTATIONS = [ | ||
func | ||
for _, func in inspect.getmembers( | ||
importlib.import_module("titiler.openeo.processes.implementations"), | ||
inspect.isfunction, | ||
) | ||
] | ||
|
||
# `process` is wrapped around each registered implementation | ||
# Create Processes Registry | ||
process_registry = ProcessRegistry(wrap_funcs=[process]) | ||
process_registry["normalized_difference"] = Process( | ||
spec=PROCESS_SPECIFICATIONS["normalized_difference"], | ||
implementation=normalized_difference, | ||
) | ||
process_registry["clip"] = process_registry["clip"] = Process( | ||
spec=PROCESS_SPECIFICATIONS["clip"], implementation=clip | ||
) | ||
process_registry["linear_scale_range"] = process_registry["linear_scale_range"] = ( | ||
Process( | ||
spec=PROCESS_SPECIFICATIONS["linear_scale_range"], | ||
implementation=linear_scale_range, | ||
|
||
for func in PROCESS_IMPLEMENTATIONS: | ||
process_registry[func.__name__] = Process( | ||
spec=PROCESS_SPECIFICATIONS[func.__name__], implementation=func | ||
) | ||
) | ||
process_registry["save_result"] = process_registry["save_result"] = Process( | ||
spec=PROCESS_SPECIFICATIONS["save_result"], implementation=save_result | ||
) | ||
|
||
# Import these pre-defined processes from openeo_processes_dask and register them into registry | ||
# processes_from_module = [ | ||
# func | ||
# for _, func in inspect.getmembers( | ||
# importlib.import_module("openeo_processes_dask.process_implementations"), | ||
# inspect.isfunction, | ||
# ) | ||
# ] | ||
|
||
# specs_module = importlib.import_module("openeo_processes_dask.specs") | ||
# specs = { | ||
# func.__name__: getattr(specs_module, func.__name__) | ||
# for func in processes_from_module | ||
# } | ||
|
||
# for func in processes_from_module: | ||
# process_registry[func.__name__] = Process( | ||
# spec=specs[func.__name__], implementation=func | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"id": "absolute", | ||
"summary": "Absolute value", | ||
"description": "Computes the absolute value of a real number `x`, which is the \"unsigned\" portion of x and often denoted as *|x|*.\n\nThe no-data value `null` is passed through and therefore gets propagated.", | ||
"categories": [ | ||
"math" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "x", | ||
"description": "A number.", | ||
"schema": { | ||
"type": [ | ||
"number", | ||
"null" | ||
] | ||
} | ||
} | ||
], | ||
"returns": { | ||
"description": "The computed absolute value.", | ||
"schema": { | ||
"type": [ | ||
"number", | ||
"null" | ||
], | ||
"minimum": 0 | ||
} | ||
}, | ||
"examples": [ | ||
{ | ||
"arguments": { | ||
"x": 0 | ||
}, | ||
"returns": 0 | ||
}, | ||
{ | ||
"arguments": { | ||
"x": 3.5 | ||
}, | ||
"returns": 3.5 | ||
}, | ||
{ | ||
"arguments": { | ||
"x": -0.4 | ||
}, | ||
"returns": 0.4 | ||
}, | ||
{ | ||
"arguments": { | ||
"x": -3.5 | ||
}, | ||
"returns": 3.5 | ||
} | ||
], | ||
"links": [ | ||
{ | ||
"rel": "about", | ||
"href": "http://mathworld.wolfram.com/AbsoluteValue.html", | ||
"title": "Absolute value explained by Wolfram MathWorld" | ||
} | ||
], | ||
"process_graph": { | ||
"lt": { | ||
"process_id": "lt", | ||
"arguments": { | ||
"x": { | ||
"from_parameter": "x" | ||
}, | ||
"y": 0 | ||
} | ||
}, | ||
"multiply": { | ||
"process_id": "multiply", | ||
"arguments": { | ||
"x": { | ||
"from_parameter": "x" | ||
}, | ||
"y": -1 | ||
} | ||
}, | ||
"if": { | ||
"process_id": "if", | ||
"arguments": { | ||
"value": { | ||
"from_node": "lt" | ||
}, | ||
"accept": { | ||
"from_node": "multiply" | ||
}, | ||
"reject": { | ||
"from_parameter": "x" | ||
} | ||
}, | ||
"result": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"id": "add", | ||
"summary": "Addition of two numbers", | ||
"description": "Sums up the two numbers `x` and `y` (*`x + y`*) and returns the computed sum.\n\nNo-data values are taken into account so that `null` is returned if any element is such a value.\n\nThe computations follow [IEEE Standard 754](https://ieeexplore.ieee.org/document/8766229) whenever the processing environment supports it.", | ||
"categories": [ | ||
"math" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "x", | ||
"description": "The first summand.", | ||
"schema": { | ||
"type": [ | ||
"number", | ||
"null" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "y", | ||
"description": "The second summand.", | ||
"schema": { | ||
"type": [ | ||
"number", | ||
"null" | ||
] | ||
} | ||
} | ||
], | ||
"returns": { | ||
"description": "The computed sum of the two numbers.", | ||
"schema": { | ||
"type": [ | ||
"number", | ||
"null" | ||
] | ||
} | ||
}, | ||
"examples": [ | ||
{ | ||
"arguments": { | ||
"x": 5, | ||
"y": 2.5 | ||
}, | ||
"returns": 7.5 | ||
}, | ||
{ | ||
"arguments": { | ||
"x": -2, | ||
"y": -4 | ||
}, | ||
"returns": -6 | ||
}, | ||
{ | ||
"arguments": { | ||
"x": 1, | ||
"y": null | ||
}, | ||
"returns": null | ||
} | ||
], | ||
"links": [ | ||
{ | ||
"rel": "about", | ||
"href": "http://mathworld.wolfram.com/Sum.html", | ||
"title": "Sum explained by Wolfram MathWorld" | ||
}, | ||
{ | ||
"rel": "about", | ||
"href": "https://ieeexplore.ieee.org/document/8766229", | ||
"title": "IEEE Standard 754-2019 for Floating-Point Arithmetic" | ||
} | ||
], | ||
"process_graph": { | ||
"sum": { | ||
"process_id": "sum", | ||
"arguments": { | ||
"data": [ | ||
{ | ||
"from_parameter": "x" | ||
}, | ||
{ | ||
"from_parameter": "y" | ||
} | ||
], | ||
"ignore_nodata": false | ||
}, | ||
"result": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.