Skip to content

Commit

Permalink
output labels for UDF results are now dynamic and can access the inpu…
Browse files Browse the repository at this point in the history
…t parameters
  • Loading branch information
GriffinBabe committed Mar 11, 2024
1 parent e7c31be commit 86bd7c4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/openeo_gfmap/features/feature_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,16 @@ def apply_feature_extractor(
default, the feature extractor expects to receive S1 and S2 data stored in
uint16 with the harmonized naming as implemented in the fetching module.
"""
feature_extractor = feature_extractor_class()
feature_extractor._parameters = parameters
output_labels = feature_extractor.output_labels()

udf_code = generate_udf_code(feature_extractor_class)

udf = openeo.UDF(code=udf_code, context=parameters)

cube = cube.apply_neighborhood(process=udf, size=size, overlap=overlap)
return cube.rename_labels(dimension="bands", target=feature_extractor_class().output_labels())
return cube.rename_labels(dimension="bands", target=output_labels)


def apply_feature_extractor_local(
Expand All @@ -246,9 +249,11 @@ def apply_feature_extractor_local(
excepts for the cube parameter which expects a `xarray.DataArray` instead of
a `openeo.rest.datacube.DataCube` object.
"""
udf_code = generate_udf_code(feature_extractor_class)
feature_extractor = feature_extractor_class()
feature_extractor._parameters = parameters
output_labels = feature_extractor.output_labels()

print(udf_code)
udf_code = generate_udf_code(feature_extractor_class)

udf = openeo.UDF(code=udf_code, context=parameters)

Expand All @@ -260,8 +265,4 @@ def apply_feature_extractor_local(

assert len(output_cubes) == 1, "UDF should have only a single output cube."

return (
output_cubes[0]
.get_array()
.assign_coords({"bands": feature_extractor_class().output_labels()})
)
return output_cubes[0].get_array().assign_coords({"bands": output_labels})

0 comments on commit 86bd7c4

Please sign in to comment.