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
Model registry
Operate
Environments
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
FSL
fslpy
Commits
dbeda417
Commit
dbeda417
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New test case for overlapping writes. One more test case to go.
parent
b3648b7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_imagewrapper.py
+30
-77
30 additions, 77 deletions
test/test_imagewrapper.py
with
30 additions
and
77 deletions
test/test_imagewrapper.py
+
30
−
77
View file @
dbeda417
...
@@ -663,11 +663,11 @@ def test_ImageWrapper_write_out(niters=150):
...
@@ -663,11 +663,11 @@ def test_ImageWrapper_write_out(niters=150):
assert
np
.
isclose
(
newHi
,
expHi
)
assert
np
.
isclose
(
newHi
,
expHi
)
print
'
--------------
'
print
'
--------------
'
def
test_ImageWrapper_write_in_overlap
(
niters
=
150
):
# This is HORRIBLE
# Generate an image with just two volumes. We're only
def
best_ImageWrapper_write_in_overlap
():
# Generate an image with only two volumes. We're only
# testing within-volume modifications here.
# testing within-volume modifications here.
ndims
=
random
.
choice
((
2
,
3
,
4
))
-
1
ndims
=
random
.
choice
((
2
,
3
,
4
))
-
1
shape
=
np
.
random
.
randint
(
5
,
60
,
size
=
ndims
+
1
)
shape
=
np
.
random
.
randint
(
5
,
60
,
size
=
ndims
+
1
)
...
@@ -683,27 +683,22 @@ def best_ImageWrapper_write_in_overlap():
...
@@ -683,27 +683,22 @@ def best_ImageWrapper_write_in_overlap():
data
[...,
i
]
=
data
[...,
0
]
*
(
i
+
1
)
data
[...,
i
]
=
data
[...,
0
]
*
(
i
+
1
)
# Generate a bunch of random coverages
# Generate a bunch of random coverages
for
i
in
range
(
1
):
for
i
in
range
(
niters
):
# Generate a random coverage
# Generate a random coverage
cov
=
random_coverage
(
shape
,
vol_limit
=
1
)
cov
=
random_coverage
(
shape
,
vol_limit
=
1
)
print
'
This is the coverage: {}
'
.
format
(
cov
)
img
=
nib
.
Nifti1Image
(
data
,
np
.
eye
(
4
))
wrapper
=
imagewrap
.
ImageWrapper
(
img
)
applyCoverage
(
wrapper
,
cov
)
clo
,
chi
=
wrapper
.
dataRange
# Now, we'll simulate some writes
# Now, we'll simulate some writes
# outside of the coverage area.
# which are contained within, or
for
i
in
range
(
5
):
# overlap with, the initial coverage
for
i
in
range
(
niters
):
# Generate some slices inside/overlapping
# Generate some slices outside
# with the coverage area, making sure that
# of the coverage area, making
# the slice covers at least two elements
# sure that the slice covers
# at least two elements
while
True
:
while
True
:
slices
=
random_slices
(
cov
,
shape
,
np
.
random
.
choice
((
'
in
'
,
'
overlap
'
)))
slices
=
random_slices
(
cov
,
shape
,
random
.
choice
((
'
in
'
,
'
overlap
'
)))
slices
[
-
1
]
=
[
0
,
1
]
slices
[
-
1
]
=
[
0
,
1
]
sliceshape
=
[
hi
-
lo
for
lo
,
hi
in
slices
]
sliceshape
=
[
hi
-
lo
for
lo
,
hi
in
slices
]
...
@@ -715,82 +710,40 @@ def best_ImageWrapper_write_in_overlap():
...
@@ -715,82 +710,40 @@ def best_ImageWrapper_write_in_overlap():
sliceshape
=
sliceshape
[:
-
1
]
sliceshape
=
sliceshape
[:
-
1
]
break
break
print
'
---------------
'
print
'
Slice {}
'
.
format
(
slices
)
# Expected wrapper coverage after the write
# Expected wrapper coverage after the write
expCov
=
imagewrap
.
adjustCoverage
(
cov
[...,
0
],
slices
)
# The write will invalidate the current
# known data range and coverage, so the
#
Figure out the data
ra
n
ge
of the
#
expected cove
rage
after the write will
#
expanded coverage (
the
o
ri
ginal
#
be the area covered by
the
w
ri
te slice
# coverage expanded to include this
nullCov
=
np
.
zeros
(
cov
.
shape
)
# slice).
nullCov
[:]
=
np
.
nan
e
lo
,
ehi
=
coverageDataRange
(
data
,
cov
,
slices
)
e
xpCov
=
imagewrap
.
adjustCoverage
(
nullCov
[...,
0
]
,
slices
)
# Test all data range possibilities:
for
i
in
range
(
10
):
# - inside the existing range (clo < rlo < rhi < chi)
# - encompassing the existing range (rlo < clo < chi < rhi)
# - Overlapping the existing range (rlo < clo < rhi < chi)
# (clo < rlo < chi < rhi)
# - Outside of the existing range (clo < chi < rlo < rhi)
# (rlo < rhi < clo < chi)
loRanges
=
[
rfloat
(
clo
,
chi
),
rfloat
(
elo
-
100
,
elo
),
rfloat
(
elo
-
100
,
elo
),
rfloat
(
clo
,
chi
),
rfloat
(
ehi
,
ehi
+
100
),
rfloat
(
elo
-
100
,
elo
)]
hiRanges
=
[
rfloat
(
loRanges
[
0
],
chi
),
rlo
=
rfloat
(
data
.
min
()
-
100
,
data
.
max
()
+
100
)
rfloat
(
ehi
,
ehi
+
100
),
rhi
=
rfloat
(
rlo
,
data
.
max
()
+
100
)
rfloat
(
clo
,
chi
),
rfloat
(
ehi
,
ehi
+
100
),
rfloat
(
loRanges
[
4
],
ehi
+
100
),
rfloat
(
loRanges
[
5
],
elo
)]
for
rlo
,
rhi
in
zip
(
loRanges
,
hiRanges
):
img
=
nib
.
Nifti1Image
(
np
.
copy
(
data
),
np
.
eye
(
4
))
img
=
nib
.
Nifti1Image
(
np
.
copy
(
data
),
np
.
eye
(
4
))
wrapper
=
imagewrap
.
ImageWrapper
(
img
)
wrapper
=
imagewrap
.
ImageWrapper
(
img
)
applyCoverage
(
wrapper
,
cov
)
applyCoverage
(
wrapper
,
cov
)
print
'
ndims
'
,
ndims
print
'
sliceshape
'
,
sliceshape
print
'
sliceobjs
'
,
sliceobjs
newData
=
np
.
linspace
(
rlo
,
rhi
,
np
.
prod
(
sliceshape
))
newData
=
np
.
linspace
(
rlo
,
rhi
,
np
.
prod
(
sliceshape
))
newData
=
newData
.
reshape
(
sliceshape
)
newData
=
newData
.
reshape
(
sliceshape
)
# Make sure that the expected low/high values
# are present in the data being written
print
'
Writing data (shape: {})
'
.
format
(
newData
.
shape
)
print
'
Old range: {} - {}
'
.
format
(
*
wrapper
.
dataRange
)
oldCov
=
wrapper
.
coverage
(
0
)
wrapper
[
tuple
(
sliceobjs
)]
=
newData
wrapper
[
tuple
(
sliceobjs
)]
=
newData
expLo
,
expHi
=
coverageDataRange
(
img
.
get_data
(),
cov
,
slices
)
newCov
=
wrapper
.
coverage
(
0
)
newLo
,
newHi
=
wrapper
.
dataRange
newLo
,
newHi
=
wrapper
.
dataRange
print
'
Old range: {} - {}
'
.
format
(
clo
,
chi
)
print
'
Expected range: {} - {}
'
.
format
(
rlo
,
rhi
)
print
'
Sim range: {} - {}
'
.
format
(
rlo
,
rhi
)
print
'
New range: {} - {}
'
.
format
(
newLo
,
newHi
)
print
'
Exp range: {} - {}
'
.
format
(
expLo
,
expHi
)
print
'
NewDat range: {} - {}
'
.
format
(
newData
.
min
(),
newData
.
max
())
print
'
Data range: {} - {}
'
.
format
(
data
.
min
(),
data
.
max
())
print
'
Expand range: {} - {}
'
.
format
(
elo
,
ehi
)
print
'
New range: {} - {}
'
.
format
(
newLo
,
newHi
)
newCov
=
wrapper
.
coverage
(
0
)
print
'
Old coverage: {}
'
.
format
(
oldCov
)
print
'
New coverage: {}
'
.
format
(
newCov
)
print
'
Expected coverage: {}
'
.
format
(
expCov
)
print
print
assert
np
.
all
(
newCov
==
expCov
)
assert
np
.
all
(
newCov
==
expCov
)
assert
np
.
isclose
(
newLo
,
expLo
)
assert
np
.
isclose
(
newLo
,
rlo
)
assert
np
.
isclose
(
newHi
,
expHi
)
assert
np
.
isclose
(
newHi
,
rhi
)
print
'
--------------
'
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