Skip to content
Snippets Groups Projects
Commit 5f30dc8d authored by Vellekoop, Sam's avatar Vellekoop, Sam
Browse files

Add unittests for LandTypeMap and aggregate_row

parent f174a993
No related branches found
No related tags found
No related merge requests found
......@@ -40,12 +40,12 @@ bottleneck_rasters = True
[environmental_1]
name = gvg
raster = .\data\rasters\gvg.tif
raster = .\data\rasters\environmentals\gvg.tif
table = .\data\parameters\gvg_suitability_index.csv
[environmental_2]
name = ndep
raster = .\data\rasters\ndep.tif
raster = .\data\rasters\environmentals\ndep.tif
table = .\data\parameters\ndep_suitability_index.csv
[species_subselection_1]
......
File moved
File moved
import numpy as np
import pytest
from scipy.sparse import dok_array
from mnp.preparation.aggregate_land_type_map import aggregate_row, LandTypeMap
@pytest.fixture
def unaggregated_row():
return np.array(
[
[0, 0, 1, 0, 2, 2, 3, 3],
[0, 0, 0, 0, 0, 0, 3, 1],
]
).T.flatten()
class TestLandTypeMap:
@pytest.fixture
def land_type_map(self):
return LandTypeMap(
"./data/rasters/land_types.tif",
"./data/rasters/land_types.csv",
"./data/rasters/environmentals/",
)
def test_aggregate_multiprocess(self, land_type_map):
land_type_map.aggregate_multiprocess()
assert land_type_map.land_types[2][549, 0] == 1 # left border (lt 2)
assert land_type_map.land_types[2][388, 86] == 0 # (lt 1)
assert land_type_map.land_types[1][563, 161] == 0 # (no lt)
assert land_type_map.land_types[1][578, 639] == 1 # right border (lt 1)
def test_aggregate_row(unaggregated_row):
lt_dict = {
k: dok_array(
(
1,
4,
),
dtype=np.double,
)
for k in [1, 2, 3, 4]
}
unrecognized = set()
land_types, unrecognized_land_type_ids = aggregate_row(
unaggregated_row, 0, lt_dict, unrecognized, 2, nodata_array=np.zeros((2, 2))
)
np.testing.assert_array_equal(
land_types[1].todense(), np.array([[0, 0.25, 0, 0.25]])
)
np.testing.assert_array_equal(land_types[2].todense(), np.array([[0, 0, 0.5, 0]]))
np.testing.assert_array_equal(land_types[3].todense(), np.array([[0, 0, 0, 0.75]]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment