4
4
import dask .array as da
5
5
6
6
from odc .stats .plugins .l34_utils import lc_level3
7
+ from odc .stats .plugins ._utils import rasterize_vector_mask
8
+ from datacube .utils .geometry import GeoBox
9
+ from affine import Affine
10
+
7
11
import pytest
8
12
9
13
NODATA = 255
@@ -58,18 +62,22 @@ def image_groups():
58
62
(np .datetime64 ("2000-01-01T00" ), np .datetime64 ("2000-01-01" )),
59
63
]
60
64
index = pd .MultiIndex .from_tuples (tuples , names = ["time" , "solar_day" ])
61
- coords = {
62
- "x" : np .linspace (10 , 20 , l34 .shape [2 ]),
63
- "y" : np .linspace (0 , 5 , l34 .shape [1 ]),
64
- }
65
+
66
+ affine = Affine .translation (10 , 0 ) * Affine .scale (
67
+ (20 - 10 ) / l34 .shape [2 ], (5 - 0 ) / l34 .shape [1 ]
68
+ )
69
+ geobox = GeoBox (
70
+ crs = "epsg:3577" , affine = affine , width = l34 .shape [2 ], height = l34 .shape [1 ]
71
+ )
72
+ coords = geobox .xr_coords ()
65
73
66
74
data_vars = {
67
75
"classes_l3_l4" : xr .DataArray (
68
76
da .from_array (l34 , chunks = (1 , - 1 , - 1 )),
69
77
dims = ("spec" , "y" , "x" ),
70
78
attrs = {"nodata" : 255 },
71
79
),
72
- "urban_classes " : xr .DataArray (
80
+ "artificial_surface " : xr .DataArray (
73
81
da .from_array (urban , chunks = (1 , - 1 , - 1 )),
74
82
dims = ("spec" , "y" , "x" ),
75
83
attrs = {"nodata" : 255 },
@@ -85,7 +93,15 @@ def image_groups():
85
93
return xx
86
94
87
95
88
- def test_l3_classes (image_groups ):
96
+ def test_l3_classes (image_groups , urban_shape ):
97
+ filter_expression = "mock > 9"
98
+ urban_mask = rasterize_vector_mask (
99
+ urban_shape ,
100
+ image_groups .geobox .transform ,
101
+ image_groups .artificial_surface .shape ,
102
+ filter_expression = filter_expression ,
103
+ threshold = 0.3 ,
104
+ )
89
105
90
- level3_classes = lc_level3 .lc_level3 (image_groups )
106
+ level3_classes = lc_level3 .lc_level3 (image_groups , urban_mask )
91
107
assert (level3_classes == expected_l3_classes ).all ()
0 commit comments