Skip to content

Commit

Permalink
feat: first test with renaming bands
Browse files Browse the repository at this point in the history
  • Loading branch information
JanssenBrm committed Mar 13, 2024
1 parent b4c83ab commit 6ac55c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/fusets/openeo/mogpr_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Dict

from openeo.metadata import CollectionMetadata
from openeo.metadata import Band, CollectionMetadata
from openeo.udf import XarrayDataCube, inspect


Expand Down Expand Up @@ -42,10 +42,18 @@ def write_gpy_cfg():


def apply_metadata(metadata: CollectionMetadata, context: dict) -> CollectionMetadata:
# extra_bands = [Band(f"{x}_STD", None, None) for x in metadata.bands]
# inspect(data=metadata, message="MOGPR metadata")
# for band in extra_bands:
# metadata = metadata.append_band(band)
include_uncertainties = context.get("include_uncertainties", False)
include_raw_inputs = context.get("include_raw_inputs", False)
extra_bands = []

if include_uncertainties:
extra_bands += [Band(f"{x.name}_STD", None, None) for x in metadata.bands]
if include_raw_inputs:
extra_bands += [Band(f"{x.name}_RAW", None, None) for x in metadata.bands]
for band in extra_bands:
metadata = metadata.append_band(band)
inspect(data=metadata, message="MOGPR metadata")

return metadata


Expand Down Expand Up @@ -77,7 +85,7 @@ def apply_datacube(cube: XarrayDataCube, context: Dict) -> XarrayDataCube:
include_uncertainties=include_uncertainties,
include_raw_inputs=include_raw_inputs,
)
result_dc = XarrayDataCube(result.to_array(dim="bands").transpose(*dims))
result_dc = XarrayDataCube(result.to_array(dim="bands").transpose(*dims).astype("float32"))
inspect(data=result_dc, message="MOGPR result")
set_home(home)
return result_dc
Expand Down
2 changes: 1 addition & 1 deletion src/fusets/openeo/services/publish_mogpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generate_mogpr_cube(
input_cube,
lambda data: data.run_udf(
udf=load_mogpr_udf(),
runtime="Python",
runtime="Python-Jep",
context={
"include_uncertainties": get_context_value(include_uncertainties),
"include_raw_inputs": get_context_value(include_raw_inputs),
Expand Down
7 changes: 3 additions & 4 deletions src/fusets/openeo/services/publish_mogpr_s1_s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from openeo.api.process import Parameter
from openeo.processes import eq, if_, merge_cubes, process

from fusets.openeo.services.dummies import DummyConnection
from fusets.openeo.services.helpers import DATE_SCHEMA, GEOJSON_SCHEMA, publish_service, read_description
from fusets.openeo.services.publish_mogpr import generate_mogpr_cube

Expand All @@ -14,7 +13,7 @@


def execute_udf():
connection = openeo.connect("openeo.vito.be").authenticate_oidc()
connection = openeo.connect("openeo-dev.vito.be").authenticate_oidc()
spat_ext = {
"type": "Polygon",
"coordinates": [
Expand Down Expand Up @@ -356,5 +355,5 @@ def generate_mogpr_s1_s2_udp(connection):
if __name__ == "__main__":
# Using the dummy connection as otherwise Datatype errors are generated when creating the input datacubes
# where bands are selected.
generate_mogpr_s1_s2_udp(connection=DummyConnection())
# execute_udf()
# generate_mogpr_s1_s2_udp(connection=DummyConnection())
execute_udf()

0 comments on commit 6ac55c2

Please sign in to comment.