Skip to content

Commit

Permalink
make output band name an option for landcover final
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Ai committed Nov 12, 2024
1 parent f792ffa commit e1ef96e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions odc/stats/plugins/lc_level34.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Plugin of Module A3 in LandCover PipeLine
"""

from typing import Tuple, Optional, List
from typing import Optional, List

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -55,11 +55,6 @@ def __init__(
water_seasonality_threshold if water_seasonality_threshold else 3
)

@property
def measurements(self) -> Tuple[str, ...]:
_measurements = ["level3", "level4"]
return _measurements

def native_transform(self, xx):
return xx

Expand Down Expand Up @@ -114,10 +109,9 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
attrs = xx.attrs.copy()
attrs["nodata"] = NODATA
dims = xx.classes_l3_l4.dims[1:]

data_vars = {
"level3": xr.DataArray(level3.squeeze(), dims=dims, attrs=attrs),
"level4": xr.DataArray(level4.squeeze(), dims=dims, attrs=attrs),
k: xr.DataArray(v, dims=dims, attrs=attrs)
for k, v in zip(self.measurements, [level3.squeeze(), level4.squeeze()])
}

coords = dict((dim, xx.coords[dim]) for dim in dims)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_l34.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_l4_classes(image_groups):
expected_l3 = [[216, 216, 215], [216, 216, 216], [215, 215, 215], [215, 215, 215]]

expected_l4 = [[95, 97, 93], [97, 96, 96], [93, 93, 93], [93, 93, 93]]
stats_l4 = StatsLccsLevel4()
stats_l4 = StatsLccsLevel4(measurements=["level3", "level4"])
ds = stats_l4.reduce(image_groups)

assert (ds.level3.compute() == expected_l3).all()
Expand Down

0 comments on commit e1ef96e

Please sign in to comment.