Skip to content

Commit c6bc1c9

Browse files
committed
Initial finetuning of apply_metadata docs #769
1 parent ee18290 commit c6bc1c9

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

docs/examples/udf/udf_modify_spatial.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
def apply_metadata(input_metadata: CollectionMetadata, context: dict) -> CollectionMetadata:
10-
1110
xstep = input_metadata.get("x", "step")
1211
ystep = input_metadata.get("y", "step")
1312
new_metadata = {
@@ -24,8 +23,6 @@ def fancy_upsample_function(array: np.array, factor: int = 2) -> np.array:
2423

2524

2625
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
27-
array: xarray.DataArray = cube.get_array()
28-
2926
cubearray: xarray.DataArray = cube.get_array().copy() + 60
3027

3128
# We make prediction and transform numpy array back to datacube
@@ -37,7 +34,7 @@ def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
3734
if cubearray.data.ndim == 4 and cubearray.data.shape[0] == 1:
3835
cubearray = cubearray[0]
3936
predicted_array = fancy_upsample_function(cubearray.data, 2)
40-
inspect(predicted_array, "test message")
37+
inspect(data=predicted_array, message="predicted array")
4138
coord_x = np.linspace(
4239
start=cube.get_array().coords["x"].min(),
4340
stop=cube.get_array().coords["x"].max() + init_pixel_size_x,
@@ -50,6 +47,10 @@ def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
5047
num=predicted_array.shape[-1],
5148
endpoint=False,
5249
)
53-
predicted_cube = xarray.DataArray(predicted_array, dims=["bands", "x", "y"], coords=dict(x=coord_x, y=coord_y))
50+
predicted_cube = xarray.DataArray(
51+
predicted_array,
52+
dims=["bands", "x", "y"],
53+
coords=dict(x=coord_x, y=coord_y),
54+
)
5455

5556
return XarrayDataCube(predicted_cube)

docs/udf.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ instead of the original digital number range (thousands):
294294

295295
UDF's that transform cube metadata
296296
==================================
297-
This is a new/experimental feature so may still be subject to change.
297+
298+
.. warning::
299+
This is a new/experimental feature so may still be subject to change.
298300

299301
In some cases, a UDF can have impact on the metadata of a cube, but this can not always
300302
be easily inferred by process graph evaluation logic without running the actual
@@ -314,9 +316,9 @@ To invoke a UDF like this, the apply_neighborhood method is most suitable:
314316

315317
.. code-block:: python
316318
317-
udf_code = Path("udf_modify_spatial.py").read_text()
319+
udf = openeo.UDF.from_file("udf_modify_spatial.py", runtime="Python-Jep")
318320
cube_updated = cube.apply_neighborhood(
319-
lambda data: data.run_udf(udf=udf_code, runtime="Python-Jep", context=dict()),
321+
udf,
320322
size=[
321323
{"dimension": "x", "value": 128, "unit": "px"},
322324
{"dimension": "y", "value": 128, "unit": "px"},

0 commit comments

Comments
 (0)