Skip to content

Commit

Permalink
address too many warnings from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Ai committed Nov 12, 2024
1 parent 1786738 commit d8f9ecf
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 50 deletions.
2 changes: 1 addition & 1 deletion odc/stats/plugins/lc_ml_treelite.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:

res = self.aggregate_results_from_group(res)
attrs = xx.attrs.copy()
dims = list(xx.dims.keys())[:2]
dims = list(xx.sizes.keys())[:2]
data_vars = {"predict_output": xr.DataArray(res, dims=dims, attrs=attrs)}
coords = {dim: xx.coords[dim] for dim in dims}
return xr.Dataset(data_vars=data_vars, coords=coords, attrs=attrs)
15 changes: 1 addition & 14 deletions tests/test_fc_percentiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def dataset():
coords = {
"x": np.linspace(10, 20, band_1.shape[2]),
"y": np.linspace(0, 5, band_1.shape[1]),
"spec": index,
}

data_vars = {
Expand All @@ -57,6 +56,7 @@ def dataset():
"ue": xr.DataArray(band_3, dims=("spec", "y", "x")),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))

return xx

Expand Down Expand Up @@ -110,10 +110,6 @@ def test_native_transform(dataset, bits):
def test_fusing(dataset):
stats_fcp = StatsFCP()
xx = stats_fcp.native_transform(dataset)
for dim in xx.dims:
if isinstance(xx.get_index(dim), pd.MultiIndex):
xx = xx.reset_index(dim)
xx = xx.set_xindex("solar_day")
xx = xx.groupby("solar_day").map(partial(StatsFCP.fuser, None))
assert xx["band_1"].attrs["test_attr"] == 57

Expand Down Expand Up @@ -142,11 +138,6 @@ def test_fusing(dataset):
# Test fusing with UE filter and sum 120 limit
stats_fcp_ue30_sum120 = StatsFCP(ue_threshold=30, max_sum_limit=120)
xx_ue30_sum120 = stats_fcp_ue30_sum120.native_transform(dataset)
for dim in xx_ue30_sum120.dims:
if isinstance(xx_ue30_sum120.get_index(dim), pd.MultiIndex):
xx_ue30_sum120 = xx_ue30_sum120.reset_index(dim)
xx_ue30_sum120 = xx_ue30_sum120.set_xindex("solar_day")

xx_ue30_sum120 = xx_ue30_sum120.groupby("solar_day").map(
partial(StatsFCP.fuser, None)
)
Expand All @@ -164,10 +155,6 @@ def test_fusing(dataset):
def test_reduce(dataset):
stats_fcp = StatsFCP(count_valid=True)
xx = stats_fcp.native_transform(dataset)
for dim in xx.dims:
if isinstance(xx.get_index(dim), pd.MultiIndex):
xx = xx.reset_index(dim)
xx = xx.set_xindex("solar_day")
xx = xx.groupby("solar_day").map(partial(StatsFCP.fuser, None))
xx = xx.compute()
xx = stats_fcp.reduce(xx)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gm_ls_bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def dataset(usgs_ls8_sr_definition):
coords = {
"x": np.linspace(10, 20, band_red.shape[2]),
"y": np.linspace(0, 5, band_pq.shape[1]),
"spec": index,
}
pq_flags_definition = {}
for measurement in usgs_ls8_sr_definition["measurements"]:
Expand All @@ -55,6 +54,7 @@ def dataset(usgs_ls8_sr_definition):
"QA_PIXEL": (("spec", "y", "x"), band_pq, attrs),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
xx["band_red"].attrs["nodata"] = 0
return xx

Expand Down
4 changes: 2 additions & 2 deletions tests/test_landcover_plugin_a0.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def dataset_md():
coords = {
"x": np.linspace(10, 20, band_1.shape[2]),
"y": np.linspace(0, 5, band_1.shape[1]),
"spec": index,
}
data_vars = {
"band_1": xr.DataArray(
band_1, dims=("spec", "y", "x"), attrs={"nodata": np.nan}
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down Expand Up @@ -301,7 +301,6 @@ def fc_wo_dataset():
coords = {
"x": np.linspace(10, 20, water.shape[2]),
"y": np.linspace(0, 5, water.shape[1]),
"spec": index,
}
data_vars = {
"water": xr.DataArray(water, dims=("spec", "y", "x"), attrs={"nodata": 1}),
Expand All @@ -311,6 +310,7 @@ def fc_wo_dataset():
"bs": xr.DataArray(bs, dims=("spec", "y", "x"), attrs={"nodata": 255}),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))

return xx

Expand Down
2 changes: 1 addition & 1 deletion tests/test_landcover_plugin_a1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def dataset():
coords = {
"x": np.linspace(10, 20, wo_fq.shape[2]),
"y": np.linspace(0, 5, wo_fq.shape[1]),
"spec": index,
}
data_vars = {
"frequency": xr.DataArray(
Expand All @@ -122,6 +121,7 @@ def dataset():
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


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 @@ -103,7 +103,6 @@ def image_groups():
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -145,6 +144,7 @@ def image_groups():
}

xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_l4_ctv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50):
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -55,6 +54,7 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50):
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_l4_natural_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def image_groups(l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_freque
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -74,6 +73,7 @@ def image_groups(l34, urban, woody, bs_pc_50, pv_pc_50, cultivated, water_freque
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
26 changes: 13 additions & 13 deletions tests/test_lc_l4_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency):
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -67,6 +66,7 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50, water_frequency):
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down Expand Up @@ -238,10 +238,10 @@ def test_ntv_veg_cover():
water_frequency = np.array(
[
[
[-999, -999, -999],
[-999, -999, -999],
[-999, -999, -999],
[-999, -999, -999],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
]
],
dtype="uint8",
Expand Down Expand Up @@ -339,10 +339,10 @@ def test_ntv_woody_veg_cover():
water_frequency = np.array(
[
[
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
]
],
dtype="uint8",
Expand Down Expand Up @@ -638,10 +638,10 @@ def test_ntv_herbaceous_veg_cover():
water_frequency = np.array(
[
[
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[-9999, -9999, -9999],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
]
],
dtype="uint8",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_l4_ntv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50):
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -59,6 +58,7 @@ def image_groups(l34, urban, cultivated, woody, pv_pc_50):
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_l4_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def image_groups(l34, urban, cultivated, woody, bs_pc_50, pv_pc_50, water_freque
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand Down Expand Up @@ -70,6 +69,7 @@ def image_groups(l34, urban, cultivated, woody, bs_pc_50, pv_pc_50, water_freque
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lc_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def image_groups():
coords = {
"x": np.linspace(10, 20, l34.shape[2]),
"y": np.linspace(0, 5, l34.shape[1]),
"spec": index,
}

data_vars = {
Expand All @@ -82,6 +81,7 @@ def image_groups():
),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
return xx


Expand Down
2 changes: 1 addition & 1 deletion tests/test_pq_bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def dataset(usgs_ls8_sr_definition):
coords = {
"x": np.linspace(10, 20, band_red.shape[2]),
"y": np.linspace(0, 5, band_pq.shape[1]),
"spec": index,
}
pq_flags_definition = {}
for measurement in usgs_ls8_sr_definition["measurements"]:
Expand All @@ -55,6 +54,7 @@ def dataset(usgs_ls8_sr_definition):
"QA_PIXEL": (("spec", "y", "x"), band_pq, attrs),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords, attrs=attrs)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))
xx["band_red"].attrs["nodata"] = 0
return xx

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rf_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def test_cultivated_reduce(
).all()

with pytest.raises(SystemExit) as excinfo:
cultivated.reduce(input_datasets.drop("classes_l3_l4"))
cultivated.reduce(input_datasets.drop_vars("classes_l3_l4"))
assert excinfo.value.code == 0


Expand Down
11 changes: 1 addition & 10 deletions tests/test_wofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def dataset():
coords = {
"x": np.linspace(10, 20, band_1.shape[2]),
"y": np.linspace(0, 5, band_1.shape[1]),
"spec": index,
}

data_vars = {
"water": xr.DataArray(band_1, dims=("spec", "y", "x"), attrs={"nodata": 0}),
}
xx = xr.Dataset(data_vars=data_vars, coords=coords)
xx = xx.assign_coords(xr.Coordinates.from_pandas_multiindex(index, "spec"))

return xx

Expand Down Expand Up @@ -78,10 +78,6 @@ def test_native_transform(dataset):
def test_fusing(dataset):
stats_wofs = StatsWofs()
out_xx = stats_wofs.native_transform(dataset)
for dim in out_xx.dims:
if isinstance(out_xx.get_index(dim), pd.MultiIndex):
out_xx = out_xx.reset_index(dim)
out_xx = out_xx.set_xindex("solar_day")

out_xx = out_xx.groupby("solar_day").map(partial(stats_wofs.fuser))
out_xx.load()
Expand Down Expand Up @@ -113,11 +109,6 @@ def test_fusing(dataset):
def test_reduce(dataset):
stats_wofs = StatsWofs()
out_xx = stats_wofs.native_transform(dataset)
for dim in out_xx.dims:
if isinstance(out_xx.get_index(dim), pd.MultiIndex):
out_xx = out_xx.reset_index(dim)
out_xx = out_xx.set_xindex("solar_day")

out_xx = out_xx.groupby("solar_day").map(partial(stats_wofs.fuser))
out_xx = stats_wofs.reduce(out_xx)
assert out_xx.count_wet.attrs.get("nodata", 0) == -999
Expand Down

0 comments on commit d8f9ecf

Please sign in to comment.