Skip to content
Snippets Groups Projects
Commit 3c2cd7f7 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Adjusted atlas unit tests

parent 3e4fe718
No related branches found
No related tags found
No related merge requests found
[pytest]
testpaths = tests
addopts = -s -v --niters=50 --cov=fsl --cov-report=html --html=report.html --cov-append
...@@ -2,4 +2,8 @@ ...@@ -2,4 +2,8 @@
test=pytest test=pytest
[bdist_wheel] [bdist_wheel]
universal=1 universal=1
\ No newline at end of file
[tool:pytest]
testpaths = tests
addopts = -s -v --niters=50 --cov=fsl
\ No newline at end of file
...@@ -156,7 +156,10 @@ def test_add_remove_atlas(): ...@@ -156,7 +156,10 @@ def test_add_remove_atlas():
assert val.atlasID == 'mla' assert val.atlasID == 'mla'
removed[0] = True removed[0] = True
xmlfile = _make_dummy_atlas(testdir, 'My Little Atlas', 'MLA', 'MyLittleAtlas') xmlfile = _make_dummy_atlas(testdir,
'My Little Atlas',
'MLA',
'MyLittleAtlas')
reg.register('added', atlas_added, topic='add') reg.register('added', atlas_added, topic='add')
reg.register('removed', atlas_removed, topic='remove') reg.register('removed', atlas_removed, topic='remove')
...@@ -180,8 +183,10 @@ def test_extra_atlases(): ...@@ -180,8 +183,10 @@ def test_extra_atlases():
with tests.testdir() as testdir: with tests.testdir() as testdir:
atlas1spec = _make_dummy_atlas(testdir, 'My atlas 1', 'myatlas1', 'MyAtlas1') atlas1spec = _make_dummy_atlas(
atlas2spec = _make_dummy_atlas(testdir, 'My atlas 2', 'myatlas2', 'MyAtlas2') testdir, 'My atlas 1', 'myatlas1', 'MyAtlas1')
atlas2spec = _make_dummy_atlas(
testdir, 'My atlas 2', 'myatlas2', 'MyAtlas2')
badspec = op.join(testdir, 'badSpec.xml') badspec = op.join(testdir, 'badSpec.xml')
with open(badspec, 'wt') as f: with open(badspec, 'wt') as f:
...@@ -194,8 +199,10 @@ def test_extra_atlases(): ...@@ -194,8 +199,10 @@ def test_extra_atlases():
'badatlas2={}'.format(badspec) 'badatlas2={}'.format(badspec)
]) ])
with mock.patch('fsl.data.atlases.fslsettings.read', return_value=extraAtlases), \ with mock.patch('fsl.data.atlases.fslsettings.read',
mock.patch('fsl.data.atlases.fslsettings.write', return_value=None): return_value=extraAtlases), \
mock.patch('fsl.data.atlases.fslsettings.write',
return_value=None):
reg = atlases.registry reg = atlases.registry
reg.rescanAtlases() reg.rescanAtlases()
...@@ -245,11 +252,11 @@ def test_label_atlas_coord(): ...@@ -245,11 +252,11 @@ def test_label_atlas_coord():
# Summary atlas (a thresholded probabilistic atlas) # Summary atlas (a thresholded probabilistic atlas)
atlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True) atlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True)
hoctests = [ hoctests = [
([-23, 58, 20], 0), ([-23, 58, 20], 1),
([-23, 27, -20], 32), ([-23, 27, -20], 33),
([-37, -75, 29], 21), ([-37, -75, 29], 22),
([ -1, 37, 6], 28), ([ -1, 37, 6], 29),
([ 54, -44, -27], 15)] ([ 54, -44, -27], 16)]
for coords, expected in hoctests: for coords, expected in hoctests:
assert atlas.label( coords) == expected assert atlas.label( coords) == expected
...@@ -307,17 +314,20 @@ def test_prob_atlas_mask(): ...@@ -307,17 +314,20 @@ def test_prob_atlas_mask():
atlas = reg.loadAtlas('harvardoxford-cortical', resolution=res) atlas = reg.loadAtlas('harvardoxford-cortical', resolution=res)
mask = fslimage.Image(maskfile) mask = fslimage.Image(maskfile)
labels, props = atlas.maskProportions(mask) props = atlas.maskProportions(mask)
labels2, props2 = atlas.proportions(mask) props2 = atlas.proportions(mask)
expected = np.loadtxt(resultsfile) expected = np.loadtxt(resultsfile)
explabels = expected[:, 0] expvols = list(expected[:, 0])
expprops = expected[:, 1] expprops = list(expected[:, 1])
assert np.all(np.isclose(labels, labels2))
assert np.all(np.isclose(props, props2)) assert np.all(np.isclose(props, props2))
assert np.all(np.isclose(labels, explabels)) for i in range(len(props)):
assert np.all(np.isclose(props, expprops)) try:
expi = expvols.index(i)
assert np.isclose(props[i], expprops[expi])
except ValueError:
assert np.isclose(props[i], 0)
def test_label_atlas_mask(): def test_label_atlas_mask():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment