@@ -27,46 +27,31 @@ def setUp(self, constant=np.random.randint(1, 12)):
27
27
"time" : times ,
28
28
},
29
29
).rio .write_crs ("EPSG:4326" )
30
-
30
+ ds = ds . transpose ( 'time' , 'x' , 'y' )
31
31
# first pixel
32
32
geometry = [
33
- Polygon ([(0 , 0 ), (0 , 0.8 ), (0.8 , 0.8 ), (0.8 , 0 )]),
34
- Polygon ([(1 , 1 ), (9 , 1 ), (9 , 2.1 ), (1 , 1 )]),
33
+ Polygon ([(0 , 0 ), (0 , 1.2 ), (1.2 , 1.2 ), (1.2 , 0 )]),
34
+ Polygon ([(1 , 1 ), (9 , 1 ), (9 , 2.1 ), (1 , 1 )])
35
35
]
36
36
# out of bound geom # Polygon([(10,10), (10,11), (11,11), (11,10)])]
37
37
gdf = gpd .GeoDataFrame ({"geometry" : geometry }, crs = "EPSG:4326" )
38
38
self .gdf = gdf
39
39
self .datacube = ds
40
40
41
- def test_numpy (self ):
42
- zonalstats = earthdaily .earthdatastore .cube_utils .zonal_stats_numpy (
43
- self .datacube ,
44
- self .gdf ,
45
- all_touched = True ,
46
- operations = dict (
47
- mean = np .nanmean , max = np .nanmax , min = np .nanmin , mode = np .mode
48
- ),
49
- )
50
-
51
- for operation in ["min" , "max" , "mode" ]:
52
- self ._check_results (
53
- zonalstats ["first_var" ].sel (stats = operation ).values , operation = operation
54
- )
55
41
56
42
def test_basic (self ):
57
43
zonalstats = earthdaily .earthdatastore .cube_utils .zonal_stats (
58
- self .datacube , self .gdf , all_touched = True , operations = ["min" , "max" , "mode" ]
44
+ self .datacube , self .gdf , all_touched = True , operations = ["min" , "max" ]
59
45
)
60
- for operation in ["min" , "max" , "mode" ]:
46
+ for operation in ["min" , "max" ]:
61
47
self ._check_results (
62
48
zonalstats ["first_var" ].sel (stats = operation ).values , operation = operation
63
49
)
64
50
65
51
def _check_results (self , stats_values , operation = "min" ):
66
52
results = {
67
- "min" : np .asarray ([[0 , self .constant ], [9 , self .constant ]]),
68
- "max" : np .asarray ([[8 , self .constant ], [23 , self .constant ]]),
69
- "mode" : np .asarray ([[0 , self .constant ], [9 , self .constant ]]),
53
+ "min" : np .asarray ([[1 , self .constant ], [10 , self .constant ]]),
54
+ "max" : np .asarray ([[9 , self .constant ], [15 , self .constant ]])
70
55
}
71
56
self .assertTrue (np .all (stats_values == results [operation ]))
72
57
0 commit comments