openeo-gfmap 0.4.4__py3-none-any.whl → 0.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  of inference models on an UDF.
3
3
  """
4
4
 
5
+ import copy
5
6
  import functools
6
7
  import inspect
7
8
  import logging
@@ -16,6 +17,7 @@ import numpy as np
16
17
  import openeo
17
18
  import requests
18
19
  import xarray as xr
20
+ from openeo.metadata import CollectionMetadata
19
21
  from openeo.udf import XarrayDataCube
20
22
  from openeo.udf import inspect as udf_inspect
21
23
  from openeo.udf.udf_data import UdfData
@@ -123,6 +125,16 @@ class ModelInference(ABC):
123
125
  arr = self.execute(arr).transpose("bands", "y", "x")
124
126
  return XarrayDataCube(arr)
125
127
 
128
+ def _apply_metadata(
129
+ self, metadata: CollectionMetadata, parameters: dict
130
+ ) -> CollectionMetadata:
131
+ """Apply metadata to the output data. This method will be executed at the very end of the
132
+ process.
133
+ """
134
+ self._parameters = parameters
135
+
136
+ return metadata.rename_labels(dimension="bands", target=self.output_labels())
137
+
126
138
  @property
127
139
  def epsg(self) -> int:
128
140
  """EPSG code of the input data."""
@@ -211,14 +223,14 @@ class ONNXModelInference(ModelInference):
211
223
  )
212
224
 
213
225
 
214
- def apply_udf_data(udf_data: UdfData) -> XarrayDataCube:
226
+ def apply_udf_data(udf_data: UdfData) -> UdfData:
215
227
  model_inference_class = "<model_inference_class>"
216
228
 
217
229
  model_inference = model_inference_class()
218
230
 
219
231
  # User-defined, model inference class initialized here
220
232
  cube = udf_data.datacube_list[0]
221
- parameters = udf_data.user_context
233
+ parameters = copy.deepcopy(udf_data.user_context)
222
234
 
223
235
  proj = udf_data.proj
224
236
  if proj is not None:
@@ -233,6 +245,14 @@ def apply_udf_data(udf_data: UdfData) -> XarrayDataCube:
233
245
  return udf_data
234
246
 
235
247
 
248
+ def apply_metadata(metadata: CollectionMetadata, context: dict) -> CollectionMetadata:
249
+ model_inference_class = "<model_inference_class>"
250
+
251
+ model_inference = model_inference_class()
252
+
253
+ return model_inference._apply_metadata(metadata, parameters=copy.deepcopy(context))
254
+
255
+
236
256
  def _get_imports() -> str:
237
257
  with open(__file__, "r", encoding="UTF-8") as f:
238
258
  script_source = f.read()
@@ -260,6 +280,13 @@ def _get_apply_udf_data(model_inference: ModelInference) -> str:
260
280
  return source.replace('"<model_inference_class>"', model_inference.__name__)
261
281
 
262
282
 
283
+ def _get_apply_metadata(model_inference: ModelInference) -> str:
284
+ source_lines = inspect.getsource(apply_metadata)
285
+ source = "".join(source_lines)
286
+ # replace in the source function the `model_inference_class`
287
+ return source.replace('"<model_inference_class>"', model_inference.__name__)
288
+
289
+
263
290
  def _generate_udf_code(
264
291
  model_inference_class: ModelInference, dependencies: list
265
292
  ) -> openeo.UDF:
@@ -286,7 +313,9 @@ def _generate_udf_code(
286
313
  udf_code += _get_imports() + "\n\n"
287
314
  udf_code += f"{inspect.getsource(ModelInference)}\n\n"
288
315
  udf_code += f"{inspect.getsource(model_inference_class)}\n\n"
289
- udf_code += _get_apply_udf_data(model_inference_class)
316
+ udf_code += f"{_get_apply_udf_data(model_inference_class)}\n\n"
317
+ udf_code += _get_apply_metadata(model_inference_class)
318
+
290
319
  return udf_code
291
320
 
292
321
 
@@ -304,15 +333,13 @@ def apply_model_inference(
304
333
  """
305
334
  model_inference = model_inference_class()
306
335
  model_inference._parameters = parameters
307
- output_labels = model_inference.output_labels()
308
336
  dependencies = model_inference.dependencies()
309
337
 
310
338
  udf_code = _generate_udf_code(model_inference_class, dependencies)
311
339
 
312
340
  udf = openeo.UDF(code=udf_code, context=parameters)
313
341
 
314
- cube = cube.apply_neighborhood(process=udf, size=size, overlap=overlap)
315
- return cube.rename_labels(dimension="bands", target=output_labels)
342
+ return cube.apply_neighborhood(process=udf, size=size, overlap=overlap)
316
343
 
317
344
 
318
345
  def apply_model_inference_local(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openeo_gfmap
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: OpenEO General Framework for Mapping
5
5
  Project-URL: Homepage, https://github.com/Open-EO/openeo-gfmap
6
6
  Project-URL: Bug Tracker, https://github.com/Open-EO/openeo-gfmap/issues
@@ -12,7 +12,7 @@ openeo_gfmap/fetching/generic.py,sha256=ojSO52cnLsWpC6FAnLRoXxfQmTiC839DzFH8MAok
12
12
  openeo_gfmap/fetching/s1.py,sha256=Ek9Ek-GExyKdb-9Ijja6I-izOmVvPY2C9w9gyyGGjII,6360
13
13
  openeo_gfmap/fetching/s2.py,sha256=ytjrZiZIwXxrdiky2V0bAKLBU9Dpaa5b2XsHvI6jl1M,7718
14
14
  openeo_gfmap/inference/__init__.py,sha256=M6NnKGYCpHNYmRL9OkHi5GmfCtWoJ0wCNR6VXRuDgjE,165
15
- openeo_gfmap/inference/model_inference.py,sha256=0qPUgrjI1hy5ZnyGwuuvvw5oxnMGdgvvu9Go6-e9LZQ,12550
15
+ openeo_gfmap/inference/model_inference.py,sha256=aBxvjeqCJJATDx6zLYBAEASYs7nolIozOa01fI76Qvc,13511
16
16
  openeo_gfmap/manager/__init__.py,sha256=2bckkPiDQBgoBWD9spk1BKXy2UGkWKe50A3HmIwmqrA,795
17
17
  openeo_gfmap/manager/job_manager.py,sha256=-MZJBfF_wV94FejoYbFPNviEQx3jLmJXb6XLeHg7egE,27221
18
18
  openeo_gfmap/manager/job_splitters.py,sha256=kkGxgiudY3LrA40Ro_9q2eFW_Pjdm5a5VaNOXk2w5qo,10694
@@ -34,7 +34,7 @@ openeo_gfmap/utils/intervals.py,sha256=V6l3ofww50fN_pvWC4NuGQ2ZsyGdhAlTZTiRcC0fo
34
34
  openeo_gfmap/utils/netcdf.py,sha256=KkAAxnq-ZCMjDMd82638noYwxqNpMsnpiU04Q-qX26A,698
35
35
  openeo_gfmap/utils/split_stac.py,sha256=asjT0jx6ic8GJFqqAisaWxOvQ_suSRv4sxyFOyHFvpI,3895
36
36
  openeo_gfmap/utils/tile_processing.py,sha256=QZ9bi5tPmyTVyyNvFZgd26s5dSnMl1grTKq2veK1C90,2068
37
- openeo_gfmap-0.4.4.dist-info/METADATA,sha256=pdw_BlCH9bg9dOg40eabef7l_jjjSpQv7YUr2QqoqLk,4374
38
- openeo_gfmap-0.4.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
- openeo_gfmap-0.4.4.dist-info/licenses/LICENSE,sha256=aUuGpjieWiscTNtyLcSaeVsJ4pb6J9c4wUq1bR0e4t4,11349
40
- openeo_gfmap-0.4.4.dist-info/RECORD,,
37
+ openeo_gfmap-0.4.5.dist-info/METADATA,sha256=5jnfj1lXVeQDH5Kf8uXNzquF2r8f7pWFAQYQQi5NxNY,4374
38
+ openeo_gfmap-0.4.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
+ openeo_gfmap-0.4.5.dist-info/licenses/LICENSE,sha256=aUuGpjieWiscTNtyLcSaeVsJ4pb6J9c4wUq1bR0e4t4,11349
40
+ openeo_gfmap-0.4.5.dist-info/RECORD,,