Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MNP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Model for Nature Policy 🌿🦋🦆
MNP
Commits
0ae935b5
Commit
0ae935b5
authored
2 months ago
by
Vellekoop, Sam
Browse files
Options
Downloads
Patches
Plain Diff
Add unittests for ClusterLocal
parent
e70d187c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_clustering.py
+43
-0
43 additions, 0 deletions
tests/test_clustering.py
with
43 additions
and
0 deletions
tests/test_clustering.py
0 → 100644
+
43
−
0
View file @
0ae935b5
from
pathlib
import
Path
from
unittest.mock
import
Mock
import
numpy
as
np
import
pandas
as
pd
import
pytest
import
rasterio
as
rio
import
scipy
from
mnp.species_models.clustering
import
ClusterLocal
@pytest.fixture
def
parameters
():
params
=
Mock
()
params
.
geospatial_profile
=
{
"
transform
"
:
Mock
(
a
=
25.0
)}
params
.
folders
=
{
"
clustering
"
:
"
.
"
}
params
.
species_traits
=
pd
.
read_csv
(
"
./data/parameters/species_traits.csv
"
,
index_col
=
0
)
return
params
@pytest.fixture
def
hsi
():
with
rio
.
open
(
Path
(
"
./data/rasters/hsi_60002.tif
"
))
as
src
:
return
scipy
.
sparse
.
csr_array
(
src
.
read
(
1
))
@pytest.fixture
def
expected_clustering
():
with
rio
.
open
(
Path
(
"
./data/rasters/clustering_60002.tif
"
))
as
src
:
return
scipy
.
sparse
.
csr_array
(
src
.
read
(
1
))
class
TestClusterLocal
:
def
test_run
(
self
,
parameters
,
hsi
,
expected_clustering
):
clustering
=
ClusterLocal
(
parameters
,
60002
)
clustering
.
run
(
hsi
)
assert
clustering
.
array
.
sum
()
>
0
np
.
testing
.
assert_array_equal
(
clustering
.
array
.
todense
(),
expected_clustering
.
todense
()
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment