Skip to content

Commit

Permalink
Merge branch '361-update-get-metadata' into 'release_branch_1_6_0'
Browse files Browse the repository at this point in the history
fix: update get_metadata with classif and segm data_vars in output

See merge request 3d/PandoraBox/pandora!297
  • Loading branch information
lecontm committed Oct 18, 2023
2 parents 250ffeb + 56d86d5 commit 80cf4f4
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions pandora/img_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ def add_disparity(
return dataset


def add_classif(
dataset: xr.Dataset, classif: Union[str, None], window: Window, *, with_data: bool = True
) -> xr.Dataset:
def add_classif(dataset: xr.Dataset, classif: Union[str, None], window: Window) -> xr.Dataset:
"""
Add classification informations and image to datasaet
Expand All @@ -155,25 +153,21 @@ def add_classif(
:param window : Windowed reading with rasterio
:type window: Window
:param with_data : option to read classification and add it to dataset
:type with_data: bool
:return: dataset : updated dataset
:rtype: xr.Dataset
"""
if classif is not None:
classif_ds = rasterio_open(classif)
# Add extra dataset coordinate for classification bands with band names from image metadat
dataset.coords["band_classif"] = list(classif_ds.descriptions)
if with_data:
dataset["classif"] = xr.DataArray(
classif_ds.read(out_dtype=np.int16, window=window),
dims=["band_classif", "row", "col"],
)
dataset.attrs.update({"classif": True})
dataset["classif"] = xr.DataArray(
classif_ds.read(out_dtype=np.int16, window=window),
dims=["band_classif", "row", "col"],
)
return dataset


def add_segm(dataset: xr.Dataset, segm: Union[str, None], window: Window, *, with_data: bool = True) -> xr.Dataset:
def add_segm(dataset: xr.Dataset, segm: Union[str, None], window: Window) -> xr.Dataset:
"""
Add Segmentation informations and image to datasaet
Expand All @@ -184,18 +178,14 @@ def add_segm(dataset: xr.Dataset, segm: Union[str, None], window: Window, *, wit
:param window : Windowed reading with rasterio
:type window: Window
:param with_data : option to read segmentation and add it to dataset
:type with_data: bool
:return: dataset : updated dataset
:rtype: xr.Dataset
"""
if segm is not None:
if with_data:
dataset["segm"] = xr.DataArray(
rasterio_open(segm).read(1, out_dtype=np.int16, window=window),
dims=["row", "col"],
)
dataset.attrs.update({"segm": True})
dataset["segm"] = xr.DataArray(
rasterio_open(segm).read(1, out_dtype=np.int16, window=window),
dims=["row", "col"],
)
return dataset


Expand Down Expand Up @@ -399,8 +389,8 @@ def get_metadata(

return (
dataset.pipe(add_disparity, disparity=disparity, window=None)
.pipe(add_classif, classif, window=None, with_data=False)
.pipe(add_segm, segm, window=None, with_data=False)
.pipe(add_classif, classif, window=None)
.pipe(add_segm, segm, window=None)
)


Expand Down

0 comments on commit 80cf4f4

Please sign in to comment.