Skip to content

Commit

Permalink
dry_run should implement correct metadata handling for ndvi function
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Aug 7, 2023
1 parent 1665a49 commit 1726a78
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion openeo_driver/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from shapely.geometry import Point, Polygon, MultiPolygon, GeometryCollection
from shapely.geometry.base import BaseGeometry

from openeo.metadata import CollectionMetadata, DimensionAlreadyExistsException
from openeo.metadata import CollectionMetadata, DimensionAlreadyExistsException, Band
from openeo_driver import filter_properties
from openeo_driver.datacube import DriverDataCube, DriverVectorCube
from openeo_driver.datastructs import SarBackscatterArgs, ResolutionMergeArgs
Expand Down Expand Up @@ -576,6 +576,14 @@ def reduce_dimension(

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

def ndvi(self, nir: str = "nir", red: str = "red", target_band: str = None) -> 'DriverDataCube':
if target_band == None and self.metadata.has_band_dimension():
return self._process_metadata(self.metadata.reduce_dimension(dimension_name=self.metadata.band_dimension.name))
elif target_band is not None and self.metadata.has_band_dimension():
return self._process_metadata(self.metadata.append_band(Band(name=target_band, common_name=target_band, wavelength_um=None)))
else:
return self

def chunk_polygon(
self, reducer, chunks: MultiPolygon, mask_value: float, env: EvalEnv, context: Optional[dict] = None
) -> "DryRunDataCube":
Expand Down

0 comments on commit 1726a78

Please sign in to comment.