Skip to content

Commit 1726a78

Browse files
committed
dry_run should implement correct metadata handling for ndvi function
1 parent 1665a49 commit 1726a78

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

openeo_driver/dry_run.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from shapely.geometry import Point, Polygon, MultiPolygon, GeometryCollection
4242
from shapely.geometry.base import BaseGeometry
4343

44-
from openeo.metadata import CollectionMetadata, DimensionAlreadyExistsException
44+
from openeo.metadata import CollectionMetadata, DimensionAlreadyExistsException, Band
4545
from openeo_driver import filter_properties
4646
from openeo_driver.datacube import DriverDataCube, DriverVectorCube
4747
from openeo_driver.datastructs import SarBackscatterArgs, ResolutionMergeArgs
@@ -576,6 +576,14 @@ def reduce_dimension(
576576

577577
return dc._process_metadata(self.metadata.reduce_dimension(dimension_name=dimension))._process("reduce_dimension", arguments={})
578578

579+
def ndvi(self, nir: str = "nir", red: str = "red", target_band: str = None) -> 'DriverDataCube':
580+
if target_band == None and self.metadata.has_band_dimension():
581+
return self._process_metadata(self.metadata.reduce_dimension(dimension_name=self.metadata.band_dimension.name))
582+
elif target_band is not None and self.metadata.has_band_dimension():
583+
return self._process_metadata(self.metadata.append_band(Band(name=target_band, common_name=target_band, wavelength_um=None)))
584+
else:
585+
return self
586+
579587
def chunk_polygon(
580588
self, reducer, chunks: MultiPolygon, mask_value: float, env: EvalEnv, context: Optional[dict] = None
581589
) -> "DryRunDataCube":

0 commit comments

Comments
 (0)