Commit f3898989 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Unit tests and data for atlas mask query

parent 8bf574fa
......@@ -236,7 +236,8 @@ def test_label_atlas_coord():
([ 6, -78, 50], 862)]
for coords, expected in taltests:
assert atlas.label(coords) == expected
assert atlas.label( coords) == expected
assert atlas.coordLabel(coords) == expected
assert atlas.label([ 999, 999, 999]) is None
assert atlas.label([-999, -999, -999]) is None
......@@ -251,7 +252,8 @@ def test_label_atlas_coord():
([ 54, -44, -27], 15)]
for coords, expected in hoctests:
assert atlas.label(coords) == expected
assert atlas.label( coords) == expected
assert atlas.coordLabel(coords) == expected
assert atlas.label([ 999, 999, 999]) is None
assert atlas.label([-999, -999, -999]) is None
......@@ -318,3 +320,31 @@ def test_prob_atlas_mask():
assert np.all(np.isclose(props, expprops))
def test_label_atlas_mask():
# Test the maskLabel function
reg = atlases.registry
reg.rescanAtlases()
taltests = [
'test_atlases_tal_mask_1mm',
'test_atlases_tal_mask_2mm'
]
resolutions = [1, 2]
for prefix, res in it.product(taltests, resolutions):
maskfile = op.join(datadir, '{}.nii.gz' .format(prefix))
resultsfile = op.join(datadir, '{}_res{}.txt'.format(prefix, res))
atlas = reg.loadAtlas('talairach', resolution=res)
mask = fslimage.Image(maskfile)
labels, props = atlas.maskLabel(mask)
labels2, props2 = atlas.label(mask)
expected = np.loadtxt(resultsfile)
explabels = expected[:, 0]
expprops = expected[:, 1]
assert np.all(np.isclose(labels, labels2))
assert np.all(np.isclose(props, props2))
assert np.all(np.isclose(labels, explabels))
assert np.all(np.isclose(props, expprops))
9 10.618844985962
11 0.050189394504
18 12.913825988770
19 3.973958253860
42 16.665719985962
45 19.200757980347
9 12.238636016846
11 0.109848484397
18 10.132575988770
19 4.818181991577
42 14.375000000000
45 18.333333969116
107 1.132015306122
151 0.860969387755
154 0.573979591837
155 20.551658163265
156 14.381377551020
223 1.307397959184
224 1.482780612245
230 14.205994897959
231 12.356505102041
610 4.607780612245
612 6.058673469388
942 0.510204081633
946 0.111607142857
1009 2.423469387755
1011 3.204719387755
1033 3.252551020408
1034 3.140943877551
1035 2.726403061224
1036 2.040816326531
1059 0.143494897959
1077 2.024872448980
1078 2.901785714268
107 0.892857142857
151 0.765306122449
154 1.275510204082
155 24.617346938776
156 16.709183673469
223 0.382653061224
224 0.765306122449
230 11.479591836735
231 9.566326530612
610 4.591836734694
612 5.484693877551
942 0.127551020408
1009 1.785714285714
1011 3.061224489796
1033 3.061224489796
1034 3.188775510204
1035 3.826530612245
1036 3.316326530612
1059 0.255102040816
1077 2.040816326531
1078 2.806122448980
107 0.800220750552
151 0.303532008830
155 11.699779249448
156 8.747240618102
223 1.600441501104
224 0.579470198675
230 23.040838852097
231 20.722958057395
610 7.809050772627
612 9.023178807947
942 0.717439293598
946 0.193156732892
1009 3.118101545254
1011 3.283664459161
1033 4.635761589404
1034 1.352097130243
1035 1.131346578366
1036 0.220750551876
1077 0.165562913907
1078 0.855408388521
151 0.220750551876
155 17.880794701987
156 13.245033112583
224 0.441501103753
230 18.763796909492
231 16.335540838852
610 7.947019867550
612 7.947019867550
942 0.220750551876
1009 2.428256070640
1011 3.532008830022
1033 4.415011037528
1034 1.766004415011
1035 2.428256070640
1036 0.883002207506
1077 0.220750551876
1078 1.324503311258
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment