Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD 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
Evan Edmond
fslpy
Commits
3a0eea53
Commit
3a0eea53
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Updates to gifti/mesh tests
parent
d93c4e65
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_gifti.py
+59
-32
59 additions, 32 deletions
tests/test_gifti.py
tests/test_mesh.py
+29
-3
29 additions, 3 deletions
tests/test_mesh.py
with
88 additions
and
35 deletions
tests/test_gifti.py
+
59
−
32
View file @
3a0eea53
...
...
@@ -6,6 +6,7 @@
#
import
shutil
import
glob
import
os.path
as
op
...
...
@@ -13,37 +14,63 @@ import numpy as np
import
nibabel
as
nib
import
pytest
import
tests
import
fsl.data.gifti
as
gifti
from
.
import
tempdir
def
test_GiftiSurface
():
def
test_GiftiMesh_create
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
testfile
=
op
.
join
(
testdir
,
'
example.surf.gii
'
)
surf
=
gifti
.
Gifti
Surface
(
testfile
)
surf
=
gifti
.
Gifti
Mesh
(
testfile
)
minbounds
=
np
.
array
([
59.50759888
,
88.43039703
,
72.10890198
])
maxbounds
=
np
.
array
([
77.72619629
,
128.40600586
,
94.82050323
])
minb
,
maxb
=
surf
.
getBounds
()
minb
,
maxb
=
surf
.
getBounds
()
assert
surf
.
name
==
'
example
'
assert
surf
.
dataSource
==
testfile
assert
tuple
(
surf
.
vertices
.
shape
)
==
(
642
,
3
)
assert
tuple
(
surf
.
indices
.
shape
)
==
(
1280
,
3
)
assert
isinstance
(
surf
.
surfImg
,
nib
.
gifti
.
GiftiImage
)
assert
isinstance
(
surf
.
getMeta
(
testfile
)
,
nib
.
gifti
.
GiftiImage
)
assert
np
.
all
(
np
.
isclose
(
minbounds
,
minb
))
assert
np
.
all
(
np
.
isclose
(
maxbounds
,
maxb
))
def
test_loadGiftiSurface
():
def
test_GiftiMesh_create_loadAll
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
testfile
=
op
.
join
(
testdir
,
'
example.surf.gii
'
)
with
tempdir
()
as
td
:
vertSets
=
[
op
.
join
(
td
,
'
prefix.1.surf.gii
'
),
op
.
join
(
td
,
'
prefix.2.surf.gii
'
),
op
.
join
(
td
,
'
prefix.3.surf.gii
'
)]
for
vs
in
vertSets
:
shutil
.
copy
(
testfile
,
vs
)
mesh
=
gifti
.
GiftiMesh
(
vertSets
[
0
],
loadAll
=
True
)
assert
mesh
.
selectedVertices
()
==
vertSets
[
0
]
mesh
.
vertices
=
vertSets
[
1
]
assert
mesh
.
selectedVertices
()
==
vertSets
[
1
]
mesh
.
vertices
=
vertSets
[
2
]
assert
mesh
.
selectedVertices
()
==
vertSets
[
2
]
def
test_loadGiftiMesh
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
testfile
=
op
.
join
(
testdir
,
'
example.surf.gii
'
)
gimg
,
verts
,
idxs
=
gifti
.
loadGifti
Surface
(
testfile
)
gimg
,
verts
,
idxs
=
gifti
.
loadGifti
Mesh
(
testfile
)
assert
isinstance
(
gimg
,
nib
.
gifti
.
GiftiImage
)
assert
tuple
(
verts
.
shape
)
==
(
642
,
3
)
...
...
@@ -56,33 +83,33 @@ def test_loadGiftiSurface():
gifti
.
loadGiftiSurface
(
bf
)
def
test_Gifti
Surface_loadGifti
VertexData
():
def
test_Gifti
Mesh_load
VertexData
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
surffile
=
op
.
join
(
testdir
,
'
example.surf.gii
'
)
shapefile
=
op
.
join
(
testdir
,
'
example.shape.gii
'
)
txtfile
=
op
.
join
(
testdir
,
'
test_mesh_data.txt
'
)
memdata
=
np
.
random
.
randint
(
1
,
10
,
642
)
# load from .gii file
surf
=
gifti
.
Gifti
Surface
(
surffile
)
assert
surf
.
loadVertexData
(
shapefile
).
shape
==
(
642
,)
surf
=
gifti
.
Gifti
Mesh
(
surffile
)
assert
surf
.
loadVertexData
(
shapefile
).
shape
==
(
642
,
1
)
# load from .txt file
assert
surf
.
loadVertexData
(
txtfile
).
shape
==
(
642
,
)
assert
surf
.
loadVertexData
(
txtfile
).
shape
==
(
642
,
1
)
#
lo
ad from memory
assert
np
.
all
(
surf
.
lo
adVertexData
(
'
inmemdata
'
,
memdata
)
==
memdata
)
# a
d
d from memory
surf
.
a
d
dVertexData
(
'
inmemdata
'
,
memdata
)
# check cached
assert
surf
.
getVertexData
(
shapefile
)
.
shape
==
(
642
,)
assert
surf
.
getVertexData
(
txtfile
)
.
shape
==
(
642
,)
assert
surf
.
getVertexData
(
'
inmemdata
'
).
shape
==
(
642
,)
assert
surf
.
getVertexData
(
shapefile
)
.
shape
==
(
642
,
1
)
assert
surf
.
getVertexData
(
txtfile
)
.
shape
==
(
642
,
1
)
assert
surf
.
getVertexData
(
'
inmemdata
'
).
shape
==
(
642
,
1
)
def
test_loadGiftiVertexData
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
surffiles
=
glob
.
glob
(
op
.
join
(
testdir
,
'
example*surf.gii
'
))
for
sf
in
surffiles
:
...
...
@@ -95,15 +122,15 @@ def test_loadGiftiVertexData():
gimg
,
data
=
gifti
.
loadGiftiVertexData
(
ex3Dfile
)
assert
isinstance
(
gimg
,
nib
.
gifti
.
GiftiImage
)
assert
tuple
(
data
.
shape
)
==
(
642
,)
assert
tuple
(
data
.
shape
)
==
(
642
,
1
)
gimg
,
data
=
gifti
.
loadGiftiVertexData
(
ex4Dfile
)
assert
isinstance
(
gimg
,
nib
.
gifti
.
GiftiImage
)
assert
tuple
(
data
.
shape
)
==
(
642
,
10
)
gimg
,
data
=
gifti
.
loadGiftiVertexData
(
ex4D2file
)
assert
isinstance
(
gimg
,
nib
.
gifti
.
GiftiImage
)
assert
tuple
(
data
.
shape
)
==
(
642
,
10
)
assert
tuple
(
data
.
shape
)
==
(
642
,
10
)
def
test_relatedFiles
():
...
...
@@ -158,33 +185,33 @@ def test_relatedFiles():
l
.
endswith
(
'
surf.gii
'
))]
lrelated
=
[
l
for
l
in
listing
if
(
l
.
startswith
(
'
subject.L
'
)
and
not
l
.
endswith
(
'
surf.gii
'
))]
rsurfaces
=
[
l
for
l
in
listing
if
(
l
.
startswith
(
'
subject.R
'
)
and
l
.
endswith
(
'
surf.gii
'
))]
rrelated
=
[
l
for
l
in
listing
if
(
l
.
startswith
(
'
subject.R
'
)
and
not
l
.
endswith
(
'
surf.gii
'
))]
with
te
sts
.
test
dir
()
as
t
estdir
:
with
te
mp
dir
()
as
t
d
:
for
l
in
listing
:
with
open
(
op
.
join
(
t
estdir
,
l
),
'
wt
'
)
as
f
:
with
open
(
op
.
join
(
t
d
,
l
),
'
wt
'
)
as
f
:
f
.
write
(
l
)
with
pytest
.
raises
(
Exception
):
gifti
.
relatedFiles
(
'
nonexistent
'
)
badname
=
op
.
join
(
op
.
join
(
t
estdir
,
'
badly-formed-filename
'
))
badname
=
op
.
join
(
op
.
join
(
t
d
,
'
badly-formed-filename
'
))
assert
len
(
gifti
.
relatedFiles
(
badname
))
==
0
lsurfaces
=
[
op
.
join
(
t
estdir
,
f
)
for
f
in
lsurfaces
]
rsurfaces
=
[
op
.
join
(
t
estdir
,
f
)
for
f
in
rsurfaces
]
lrelated
=
[
op
.
join
(
t
estdir
,
f
)
for
f
in
lrelated
]
rrelated
=
[
op
.
join
(
t
estdir
,
f
)
for
f
in
rrelated
]
lsurfaces
=
[
op
.
join
(
t
d
,
f
)
for
f
in
lsurfaces
]
rsurfaces
=
[
op
.
join
(
t
d
,
f
)
for
f
in
rsurfaces
]
lrelated
=
[
op
.
join
(
t
d
,
f
)
for
f
in
lrelated
]
rrelated
=
[
op
.
join
(
t
d
,
f
)
for
f
in
rrelated
]
for
s
in
lsurfaces
:
result
=
gifti
.
relatedFiles
(
s
)
assert
sorted
(
lrelated
)
==
sorted
(
result
)
for
s
in
rsurfaces
:
result
=
gifti
.
relatedFiles
(
s
)
assert
sorted
(
rrelated
)
==
sorted
(
result
)
assert
sorted
(
rrelated
)
==
sorted
(
result
)
This diff is collapsed.
Click to expand it.
tests/test_mesh.py
+
29
−
3
View file @
3a0eea53
...
...
@@ -6,6 +6,7 @@
#
import
os.path
as
op
import
numpy
as
np
import
mock
import
pytest
...
...
@@ -13,6 +14,8 @@ import pytest
import
fsl.utils.transform
as
transform
import
fsl.data.mesh
as
fslmesh
from
.
import
tempdir
# vertices of a cube
CUBE_VERTICES
=
np
.
array
([
...
...
@@ -86,16 +89,19 @@ def test_mesh_addVertices():
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
assert
mesh
.
selectedVertices
()
==
'
default
'
assert
mesh
.
vertexKeys
()
==
[
'
default
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts
))
mesh
.
addVertices
(
verts2
,
'
twotimes
'
)
assert
mesh
.
selectedVertices
()
==
'
twotimes
'
assert
mesh
.
vertexKeys
()
==
[
'
default
'
,
'
twotimes
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts2
))
mesh
.
addVertices
(
verts3
,
'
threetimes
'
,
select
=
False
)
assert
mesh
.
selectedVertices
()
==
'
twotimes
'
assert
mesh
.
vertexKeys
()
==
[
'
default
'
,
'
twotimes
'
,
'
threetimes
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts2
))
mesh
.
vertices
=
'
threetimes
'
...
...
@@ -114,6 +120,7 @@ def test_mesh_addVertexData():
data3D
=
np
.
random
.
randint
(
1
,
100
,
nverts
)
data3_1D
=
np
.
random
.
randint
(
1
,
100
,
(
nverts
,
1
))
data4D
=
np
.
random
.
randint
(
1
,
100
,
(
nverts
,
20
))
dataBad
=
np
.
random
.
randint
(
1
,
100
,
(
nverts
-
1
,
20
))
mesh
.
addVertexData
(
'
3d
'
,
data3D
)
mesh
.
addVertexData
(
'
3_1d
'
,
data3_1D
)
...
...
@@ -129,9 +136,28 @@ def test_mesh_addVertexData():
mesh
.
clearVertexData
()
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
3d
'
)
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
3_1d
'
)
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
4d
'
)
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
3d
'
)
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
3_1d
'
)
with
pytest
.
raises
(
KeyError
):
mesh
.
getVertexData
(
'
4d
'
)
with
pytest
.
raises
(
ValueError
):
mesh
.
addVertexData
(
'
bad
'
,
dataBad
)
def
test_loadVertexData
():
verts
=
np
.
array
(
CUBE_VERTICES
)
tris
=
np
.
array
(
CUBE_TRIANGLES_CCW
)
vdata
=
np
.
random
.
randint
(
1
,
100
,
verts
.
shape
[
0
]).
reshape
(
-
1
,
1
)
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
with
tempdir
():
np
.
savetxt
(
'
vdata.txt
'
,
vdata
)
key
=
op
.
abspath
(
'
vdata.txt
'
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertexData
(
key
),
vdata
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
getVertexData
(
key
),
vdata
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertexData
(
key
,
'
vdkey
'
),
vdata
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
getVertexData
(
'
vdkey
'
),
vdata
))
def
test_normals
():
...
...
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