|
12 | 12 | import logging |
13 | 13 | import pathlib |
14 | 14 | import typing |
| 15 | +from builtins import staticmethod |
15 | 16 | from typing import List, Dict, Union, Tuple |
16 | 17 |
|
| 18 | +import numpy |
17 | 19 | import numpy as np |
18 | 20 | import shapely.geometry |
19 | 21 | import shapely.geometry.base |
|
29 | 31 | from openeo.rest import BandMathException, OperatorException, OpenEoClientException |
30 | 32 | from openeo.rest.job import RESTJob |
31 | 33 | from openeo.rest.udp import RESTUserDefinedProcess |
32 | | -from openeo.util import get_temporal_extent, dict_no_none |
| 34 | +from openeo.util import get_temporal_extent, dict_no_none, legacy_alias |
33 | 35 | from openeo.vectorcube import VectorCube |
34 | | -import numpy |
35 | | -from builtins import staticmethod |
36 | 36 |
|
37 | 37 | if hasattr(typing, 'TYPE_CHECKING') and typing.TYPE_CHECKING: |
38 | 38 | # Only import this for type hinting purposes. Runtime import causes circular dependency issues. |
@@ -100,8 +100,7 @@ def process(self, process_id: str, arguments: dict = None, metadata: CollectionM |
100 | 100 | arguments=arguments, |
101 | 101 | ), metadata=metadata) |
102 | 102 |
|
103 | | - # Legacy `graph_add_node` method |
104 | | - graph_add_node = deprecated(reason="just use `process()`")(process) |
| 103 | + graph_add_node = legacy_alias(process, "graph_add_node") |
105 | 104 |
|
106 | 105 | def process_with_node(self, pg: PGNode, metadata: CollectionMetadata = None) -> 'DataCube': |
107 | 106 | """ |
@@ -162,10 +161,7 @@ def load_collection( |
162 | 161 | metadata = metadata.filter_bands(bands) |
163 | 162 | return cls(graph=pg, connection=connection, metadata=metadata) |
164 | 163 |
|
165 | | - @classmethod |
166 | | - @deprecated("use load_collection instead") |
167 | | - def create_collection(cls, *args, **kwargs): |
168 | | - return cls.load_collection(*args, **kwargs) |
| 164 | + create_collection = legacy_alias(load_collection, name="create_collection") |
169 | 165 |
|
170 | 166 | @classmethod |
171 | 167 | def load_disk_collection(cls, connection: 'openeo.Connection', file_format: str, glob_pattern: str, |
@@ -230,9 +226,7 @@ def filter_bands(self, bands: Union[List[Union[str, int]], str]) -> 'DataCube': |
230 | 226 | cube.metadata = cube.metadata.filter_bands(bands) |
231 | 227 | return cube |
232 | 228 |
|
233 | | - @deprecated("use `filter_bands()` instead") |
234 | | - def band_filter(self, bands) -> 'DataCube': |
235 | | - return self.filter_bands(bands) |
| 229 | + band_filter = legacy_alias(filter_bands, "band_filter") |
236 | 230 |
|
237 | 231 | def band(self, band: Union[str, int]) -> 'DataCube': |
238 | 232 | """Filter the imagery by the given bands |
@@ -682,22 +676,15 @@ def _create_run_udf(self, code, runtime, version) -> PGNode: |
682 | 676 | def reduce_temporal_udf(self, code: str, runtime="Python", version="latest"): |
683 | 677 | """ |
684 | 678 | Apply reduce (`reduce_dimension`) process with given UDF along temporal dimension. |
685 | | - """ |
686 | | - # TODO EP-3555: unify better with UDF(PGNode) class and avoid doing same UDF code-runtime-version argument stuff in each method |
687 | | - return self._reduce_temporal(reducer=self._create_run_udf(code, runtime, version)) |
688 | | - |
689 | | - @deprecated("use `reduce_temporal_udf` instead") |
690 | | - def reduce_tiles_over_time(self, code: str, runtime="Python", version="latest"): |
691 | | - """ |
692 | | - Applies a user defined function to a timeseries of tiles. The size of the tile is backend specific, and can be limited to one pixel. |
693 | | - The function should reduce the given timeseries into a single (multiband) tile. |
694 | 679 |
|
695 | 680 | :param code: The UDF code, compatible with the given runtime and version |
696 | 681 | :param runtime: The UDF runtime |
697 | 682 | :param version: The UDF runtime version |
698 | | - :return: |
699 | 683 | """ |
700 | | - return self.reduce_temporal_udf(code=code, runtime=runtime, version=version) |
| 684 | + # TODO EP-3555: unify better with UDF(PGNode) class and avoid doing same UDF code-runtime-version argument stuff in each method |
| 685 | + return self._reduce_temporal(reducer=self._create_run_udf(code, runtime, version)) |
| 686 | + |
| 687 | + reduce_tiles_over_time = legacy_alias(reduce_temporal_udf, name="reduce_tiles_over_time") |
701 | 688 |
|
702 | 689 | def apply_neighborhood( |
703 | 690 | self, process: [str, PGNode, typing.Callable], |
@@ -999,8 +986,7 @@ def merge_cubes( |
999 | 986 | # TODO: set metadata of reduced cube? |
1000 | 987 | return self.process(process_id="merge_cubes", arguments=arguments) |
1001 | 988 |
|
1002 | | - # Legacy alias |
1003 | | - merge = merge_cubes |
| 989 | + merge = legacy_alias(merge_cubes, name="merge") |
1004 | 990 |
|
1005 | 991 | def apply_kernel(self, kernel: Union[np.ndarray, List[List[float]]], factor=1.0, border = 0, replace_invalid=0) -> 'DataCube': |
1006 | 992 | """ |
|
0 commit comments