2
2
Plugin of Module A3 in LandCover PipeLine
3
3
"""
4
4
5
- from typing import Tuple , Optional , Dict , List
5
+ from typing import Tuple , Optional , List
6
6
7
7
import numpy as np
8
8
import xarray as xr
20
20
l4_surface ,
21
21
l4_bare_gradation ,
22
22
l4_water ,
23
+ utils ,
23
24
)
24
25
25
26
26
27
NODATA = 255
27
- water_frequency_nodata = - 999
28
+ WATER_FREQ_NODATA = - 999
28
29
29
30
30
31
class StatsLccsLevel4 (StatsPluginInterface ):
@@ -38,10 +39,6 @@ def __init__(
38
39
veg_threshold : Optional [List ] = None ,
39
40
bare_threshold : Optional [List ] = None ,
40
41
watper_threshold : Optional [List ] = None ,
41
- veg_mapping : Optional [Dict [int , int ]] = None ,
42
- bs_mapping : Optional [Dict [int , int ]] = None ,
43
- waterper_wat_mapping : Optional [Dict [int , int ]] = None ,
44
- l3_to_l4_mapping : Optional [Dict [int , int ]] = None ,
45
42
water_seasonality_threshold : int = None ,
46
43
** kwargs ,
47
44
):
@@ -58,14 +55,6 @@ def __init__(
58
55
water_seasonality_threshold if water_seasonality_threshold else 3
59
56
)
60
57
61
- # The mapping below are from the LC KH page
62
- # Map vegetation cover classes
63
- self .veg_mapping = {160 : 16 , 150 : 15 , 130 : 13 , 120 : 12 , 100 : 10 }
64
- # Map bare gradation classes
65
- self .bs_mapping = {100 : 10 , 120 : 12 , 150 : 15 }
66
- # Map values to the classes expected in water persistence in land cover Level-4 output
67
- self .waterper_wat_mapping = {100 : 1 , 70 : 7 , 80 : 8 , 90 : 9 }
68
-
69
58
@property
70
59
def measurements (self ) -> Tuple [str , ...]:
71
60
_measurements = ["level3" , "level4" ]
@@ -77,14 +66,13 @@ def native_transform(self, xx):
77
66
def fuser (self , xx ):
78
67
return xx
79
68
80
- @staticmethod
81
- def apply_mapping (data , class_mapping ):
82
- for o_val , n_val in class_mapping .items ():
83
- data = xr .where (data == o_val , n_val , data )
84
- return data
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
85
74
86
75
def define_life_form (self , xx : xr .Dataset ):
87
- lifeform = xx .woody_cover .data
88
76
89
77
# 113 ----> 1 woody
90
78
# 114 ----> 2 herbaceous
@@ -128,11 +116,11 @@ def define_water_seasonality(self, xx: xr.Dataset):
128
116
dtype = "uint8" ,
129
117
** {
130
118
"watseas_trh" : self .water_seasonality_threshold ,
131
- "watersea_nodata" : water_frequency_nodata ,
119
+ "watersea_nodata" : WATER_FREQ_NODATA ,
132
120
},
133
121
)
134
122
mapping = {100 : 1 , 200 : 2 }
135
- water_season_mask = self .apply_mapping (water_season_mask , mapping )
123
+ water_season_mask = utils .apply_mapping (water_season_mask , mapping )
136
124
137
125
return water_season_mask
138
126
@@ -142,53 +130,48 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
142
130
143
131
# Vegetation cover
144
132
veg_cover = l4_veg_cover .canopyco_veg_con (xx , self .veg_threshold )
145
- # Define mapping from current output to expected a3 output
146
- veg_cover = self .apply_mapping (veg_cover , self .veg_mapping )
133
+ # # Define mapping from current output to expected a3 output
134
+ # veg_cover = utils .apply_mapping(veg_cover, self.veg_mapping)
147
135
# Define life form
148
136
lifeform = self .define_life_form (xx )
149
137
150
138
# Apply cultivated Level-4 classes (1-18)
151
- l4_ctv = l4_cultivated .lc_l4_cultivated (
139
+ l4 = l4_cultivated .lc_l4_cultivated (
152
140
xx .classes_l3_l4 , level3 , lifeform , veg_cover
153
141
)
154
- print ( "***** CULATIVATED: " , np . unique ( l4_ctv . compute ()))
142
+
155
143
# Apply terrestrial vegetation classes [19-36]
156
- l4_ctv_ntv = l4_natural_veg .lc_l4_natural_veg (
157
- l4_ctv , level3 , lifeform , veg_cover
158
- )
159
- print ("***** CULATIVATED NTV : " , np .unique (l4_ctv_ntv .compute ()))
144
+ l4 = l4_natural_veg .lc_l4_natural_veg (l4 , level3 , lifeform , veg_cover )
160
145
161
146
# Bare gradation
162
147
bare_gradation = l4_bare_gradation .bare_gradation (
163
148
xx , self .bare_threshold , veg_cover
164
149
)
165
- # Apply bare gradation expected output classes
166
- bare_gradation = self .apply_mapping (bare_gradation , self .bs_mapping )
150
+ # # Apply bare gradation expected output classes
151
+ # bare_gradation = utils .apply_mapping(bare_gradation, self.bs_mapping)
167
152
168
153
# Water persistence
169
154
water_persistence = l4_water_persistence .water_persistence (
170
155
xx , self .watper_threshold
171
156
)
172
- # Apply water persistence expcted classes
173
- water_persistence = self .apply_mapping (
174
- water_persistence , self .waterper_wat_mapping
175
- )
157
+ # # Apply water persistence expcted classes
158
+ # water_persistence = utils .apply_mapping(
159
+ # water_persistence, self.waterper_wat_mapping
160
+ # )
176
161
177
162
water_seasonality = self .define_water_seasonality (xx )
178
163
179
- l4_ctv_ntv_nav = l4_natural_aquatic .natural_auquatic_veg (
180
- l4_ctv_ntv , lifeform , veg_cover , water_seasonality
164
+ l4 = l4_natural_aquatic .natural_auquatic_veg (
165
+ l4 , lifeform , veg_cover , water_seasonality
181
166
)
182
- print ("***** NAV : " , np .unique (l4_ctv_ntv_nav .compute ()))
183
- l4_ctv_ntv_nav_surface = l4_surface .lc_l4_surface (
184
- l4_ctv_ntv_nav , level3 , bare_gradation
185
- )
186
- print ("***** SURFACE : " , np .unique (l4_ctv_ntv_nav_surface .compute ()))
167
+
168
+ l4 = l4_surface .lc_l4_surface (l4 , level3 , bare_gradation )
169
+
187
170
# #TODO WATER (99-104)
188
171
level4 = l4_water .water_classification (
189
- l4_ctv_ntv_nav_surface , level3 , intertidal_mask , water_persistence
172
+ l4 , level3 , intertidal_mask , water_persistence
190
173
)
191
- print ( "***** LEVEL3:" , np . unique ( level3 . compute ()))
174
+
192
175
attrs = xx .attrs .copy ()
193
176
attrs ["nodata" ] = NODATA
194
177
# l3 = level3.squeeze(dim=["spec"])
@@ -206,7 +189,6 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
206
189
207
190
coords = dict ((dim , xx .coords [dim ]) for dim in dims )
208
191
209
- print (xr .Dataset (data_vars = data_vars , coords = coords , attrs = xx .attrs ))
210
192
return xr .Dataset (data_vars = data_vars , coords = coords , attrs = xx .attrs )
211
193
212
194
0 commit comments