7
7
import numpy as np
8
8
import xarray as xr
9
9
10
- from odc .stats ._algebra import expr_eval
11
10
from ._registry import StatsPluginInterface , register
12
11
13
12
from .l34_utils import (
14
13
l4_water_persistence ,
14
+ lc_water_seasonality ,
15
15
l4_veg_cover ,
16
16
lc_level3 ,
17
17
l4_cultivated ,
20
20
l4_surface ,
21
21
l4_bare_gradation ,
22
22
l4_water ,
23
- utils ,
23
+ lc_lifeform ,
24
24
)
25
25
26
26
27
27
NODATA = 255
28
- WATER_FREQ_NODATA = - 999
29
28
30
29
31
30
class StatsLccsLevel4 (StatsPluginInterface ):
@@ -66,74 +65,15 @@ def native_transform(self, xx):
66
65
def fuser (self , xx ):
67
66
return xx
68
67
69
- # @staticmethod
70
- # def apply_mapping(data, class_mapping):
71
- # for o_val, n_val in class_mapping.items():
72
- # data = xr.where(data == o_val, n_val, data)
73
- # return data
74
-
75
- def define_life_form (self , xx : xr .Dataset ):
76
-
77
- # 113 ----> 1 woody
78
- # 114 ----> 2 herbaceous
79
- lifeform_mask = expr_eval (
80
- "where(a==113, 1, a)" ,
81
- {"a" : xx .woody_cover .data },
82
- name = "mark_lifeform" ,
83
- dtype = "uint8" ,
84
- )
85
- lifeform_mask = expr_eval (
86
- "where(a==114, 2, a)" ,
87
- {"a" : lifeform_mask },
88
- name = "mark_lifeform" ,
89
- dtype = "uint8" ,
90
- )
91
-
92
- return lifeform_mask
93
-
94
- def define_water_seasonality (self , xx : xr .Dataset ):
95
- # >= 3 months ----> 1 Semi-permanent or permanent
96
- # < 3 months ----> 2 Temporary or seasonal
97
-
98
- water_season_mask = expr_eval (
99
- "where((a>watseas_trh)&(a<=12), 100, a)" ,
100
- {"a" : xx .water_frequency .data },
101
- name = "mark_water_season" ,
102
- dtype = "uint8" ,
103
- ** {"watseas_trh" : self .water_seasonality_threshold },
104
- )
105
- water_season_mask = expr_eval (
106
- "where((a<=watseas_trh)&(a<=12), 200, a)" ,
107
- {"a" : water_season_mask },
108
- name = "mark_water_season" ,
109
- dtype = "uint8" ,
110
- ** {"watseas_trh" : self .water_seasonality_threshold },
111
- )
112
- water_season_mask = expr_eval (
113
- "where((a==watersea_nodata), 255, a)" ,
114
- {"a" : water_season_mask },
115
- name = "mark_water_season" ,
116
- dtype = "uint8" ,
117
- ** {
118
- "watseas_trh" : self .water_seasonality_threshold ,
119
- "watersea_nodata" : WATER_FREQ_NODATA ,
120
- },
121
- )
122
- mapping = {100 : 1 , 200 : 2 }
123
- water_season_mask = utils .apply_mapping (water_season_mask , mapping )
124
-
125
- return water_season_mask
126
-
127
68
def reduce (self , xx : xr .Dataset ) -> xr .Dataset :
128
69
129
70
intertidal_mask , level3 = lc_level3 .lc_level3 (xx )
130
71
131
72
# Vegetation cover
132
73
veg_cover = l4_veg_cover .canopyco_veg_con (xx , self .veg_threshold )
133
- # # Define mapping from current output to expected a3 output
134
- # veg_cover = utils.apply_mapping(veg_cover, self.veg_mapping)
74
+
135
75
# Define life form
136
- lifeform = self . define_life_form (xx )
76
+ lifeform = lc_lifeform . lifeform (xx )
137
77
138
78
# Apply cultivated Level-4 classes (1-18)
139
79
l4 = l4_cultivated .lc_l4_cultivated (
@@ -147,19 +87,13 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
147
87
bare_gradation = l4_bare_gradation .bare_gradation (
148
88
xx , self .bare_threshold , veg_cover
149
89
)
150
- # # Apply bare gradation expected output classes
151
- # bare_gradation = utils.apply_mapping(bare_gradation, self.bs_mapping)
152
90
153
91
# Water persistence
154
92
water_persistence = l4_water_persistence .water_persistence (
155
93
xx , self .watper_threshold
156
94
)
157
- # # Apply water persistence expcted classes
158
- # water_persistence = utils.apply_mapping(
159
- # water_persistence, self.waterper_wat_mapping
160
- # )
161
95
162
- water_seasonality = self . define_water_seasonality (xx )
96
+ water_seasonality = lc_water_seasonality . water_seasonality (xx )
163
97
164
98
l4 = l4_natural_aquatic .natural_auquatic_veg (
165
99
l4 , lifeform , veg_cover , water_seasonality
0 commit comments