Skip to content

Commit

Permalink
Merge pull request #195 from geo-engine/fix-output-band-serialization
Browse files Browse the repository at this point in the history
bugfix: output band serialization
  • Loading branch information
michaelmattig authored Aug 30, 2024
2 parents d49549f + 554f655 commit 546e2af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 8 additions & 3 deletions geoengine/workflow_builder/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union, cast, Literal
import datetime
import geoengine_openapi_client
import numpy as np

from geoengine.datasets import DatasetName
Expand Down Expand Up @@ -673,7 +674,7 @@ def to_dict(self) -> Dict[str, Any]:
"mapNoData": self.map_no_data,
}
if self.output_band:
params["outputBand"] = self.output_band.to_api_dict()
params["outputBand"] = self.output_band.to_api_dict().to_dict()

return {
"type": self.name(),
Expand All @@ -689,8 +690,12 @@ def from_operator_dict(cls, operator_dict: Dict[str, Any]) -> 'Expression':
raise ValueError("Invalid operator type")

output_band = None
if "output_band" in operator_dict["params"]:
output_band = RasterBandDescriptor.from_response(operator_dict["params"]["outputBand"])
if "outputBand" in operator_dict["params"]:
output_band = RasterBandDescriptor.from_response(
geoengine_openapi_client.RasterBandDescriptor.from_dict(
operator_dict["params"]["outputBand"]
)
)

return Expression(
expression=operator_dict["params"]["expression"],
Expand Down
19 changes: 17 additions & 2 deletions tests/test_workflow_builder_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
from geoengine import workflow_builder as wb
from geoengine.types import ContinuousMeasurement, RasterBandDescriptor
from geoengine.workflow_builder.operators import ColumnNamesNames


Expand Down Expand Up @@ -256,15 +257,29 @@ def test_expression(self):
source=source_operator,
expression="x + 1",
output_type="U8",
output_band=RasterBandDescriptor(
"ndvi",
measurement=ContinuousMeasurement(
"vegetation",
unit=None,
),
)
)

self.assertEqual(workflow.to_dict(), {
'type': 'Expression',
'params': {
"expression": "x + 1",
"outputType": "U8",
"mapNoData": False

"mapNoData": False,
"outputBand": {
"name": "ndvi",
"measurement": {
"type": "continuous",
"measurement": "vegetation",
"unit": None,
},
},
},
'sources': {
'raster': {
Expand Down

0 comments on commit 546e2af

Please sign in to comment.