Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttk
spam
Commits
02434791
Commit
02434791
authored
Oct 12, 2020
by
Edward Andò
Browse files
attempt to move coverage from unittest to pytest
parent
41138062
Pipeline
#50731
passed with stages
in 23 minutes and 39 seconds
Changes
25
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.coveragerc
View file @
02434791
...
...
@@ -19,10 +19,11 @@ omit =
*/_*
*/plotting/*
*optionsParser.py
*viewer*
*Viewer*
*/visual/*
source = spam
source =
spam
#concurrency = multiprocessing
[html]
directory = coverage
.gitlab-ci.yml
View file @
02434791
...
...
@@ -38,7 +38,7 @@ pages:
-
python setup.py build_sphinx
-
mkdir public
-
mv build/sphinx/html/* public
-
coverage run
setup.
py
test
-
coverage run
-m
pytest
-
coverage report
-
coverage html
-
mv coverage public
...
...
setup.py
View file @
02434791
...
...
@@ -10,10 +10,9 @@ TTK_modules. C/C++ code must be in the src directory of the package.
*swig*
If you use swig numpy.i, please symlink it from tools/swig directory.
"""
from
setuptools
import
setup
from
setuptools
import
setup
,
Command
from
distutils.extension
import
Extension
import
os
import
sys
...
...
@@ -79,6 +78,22 @@ class get_pybind_include(object):
import
pybind11
return
pybind11
.
get_include
(
self
.
user
)
# This is what is suggested in https://docs.pytest.org/en/2.7.3/goodpractises.html
class
PyTest
(
Command
):
user_options
=
[]
def
initialize_options
(
self
):
pass
def
finalize_options
(
self
):
pass
def
run
(
self
):
import
subprocess
import
sys
errno
=
subprocess
.
call
([
'pytest'
])
raise
SystemExit
(
errno
)
name
=
'spam'
description
=
'Software for the Practical Analysis of Materials'
...
...
@@ -195,6 +210,7 @@ class Build_ext(_build_ext):
cmdclass
=
{
'install'
:
Install
,
'build_ext'
:
Build_ext
,
'test'
:
PyTest
,
}
try
:
...
...
@@ -261,7 +277,7 @@ metadata = dict(
'version'
:
(
'setup.py'
,
version
),
'release'
:
(
'setup.py'
,
version
),
'copyright'
:
(
'setup.py'
,
copyright
)}},
test_suite
=
"tests"
,
#
test_suite="tests",
data_files
=
[(
'share/img'
,
[
'docs/source/images/icon.png'
,
'docs/source/images/logo.png'
])]
)
...
...
tools/label/label.py
View file @
02434791
...
...
@@ -381,37 +381,6 @@ def makeLabelsSequential(lab):
return
lab
def
_checkSlice
(
topOfSlice
,
botOfSlice
,
topLimit
,
botLimit
):
# Do we have any negative positions? Set all negative numbers to zero and see if there was any difference
topOfSliceLimited
=
topOfSlice
.
copy
()
if
topOfSliceLimited
[
0
]
<
topLimit
[
0
]:
topOfSliceLimited
[
0
]
=
topLimit
[
0
]
if
topOfSliceLimited
[
1
]
<
topLimit
[
1
]:
topOfSliceLimited
[
1
]
=
topLimit
[
1
]
if
topOfSliceLimited
[
2
]
<
topLimit
[
2
]:
topOfSliceLimited
[
2
]
=
topLimit
[
2
]
topOfSliceOffset
=
topOfSliceLimited
-
topOfSlice
botOfSliceLimited
=
botOfSlice
.
copy
()
if
botOfSliceLimited
[
0
]
>
botLimit
[
0
]:
botOfSliceLimited
[
0
]
=
botLimit
[
0
]
if
botOfSliceLimited
[
1
]
>
botLimit
[
1
]:
botOfSliceLimited
[
1
]
=
botLimit
[
1
]
if
botOfSliceLimited
[
2
]
>
botLimit
[
2
]:
botOfSliceLimited
[
2
]
=
botLimit
[
2
]
botOfSliceOffset
=
botOfSliceLimited
-
botOfSlice
returnSliceLimited
=
(
slice
(
int
(
topOfSliceLimited
[
0
]),
int
(
botOfSliceLimited
[
0
])),
slice
(
int
(
topOfSliceLimited
[
1
]),
int
(
botOfSliceLimited
[
1
])),
slice
(
int
(
topOfSliceLimited
[
2
]),
int
(
botOfSliceLimited
[
2
])))
returnSliceOffset
=
(
slice
(
int
(
topOfSliceOffset
[
0
]),
int
(
topOfSliceOffset
[
0
]
+
botOfSliceLimited
[
0
]
-
topOfSliceLimited
[
0
])),
slice
(
int
(
topOfSliceOffset
[
1
]),
int
(
topOfSliceOffset
[
1
]
+
botOfSliceLimited
[
1
]
-
topOfSliceLimited
[
1
])),
slice
(
int
(
topOfSliceOffset
[
2
]),
int
(
topOfSliceOffset
[
2
]
+
botOfSliceLimited
[
2
]
-
topOfSliceLimited
[
2
])))
return
returnSliceLimited
,
returnSliceOffset
def
getLabel
(
labelledVolume
,
label
,
boundingBoxes
=
None
,
centresOfMass
=
None
,
margin
=
0
,
extractCube
=
False
,
extractCubeSize
=
None
,
maskOtherLabels
=
True
,
labelDilate
=
0
,
labelDilateMaskOtherLabels
=
False
):
"""
Helper function to extract labels from a labelled image/volume.
...
...
tools/tests/__init__.py
0 → 100644
View file @
02434791
tests/test_DIC.py
→
tools/
tests/test_DIC.py
View file @
02434791
File moved
tests/test_DVCglobal.py
→
tools/
tests/test_DVCglobal.py
View file @
02434791
File moved
tools/tests/test_ITKwatershed.py
0 → 100644
View file @
02434791
# -*- coding: utf-8 -*-
import
unittest
import
os
import
tifffile
import
numpy
import
spam.label
import
spam.kalisphera
VERBOSE
=
True
class
TestFunctionITKWatershed
(
unittest
.
TestCase
):
# def tearDown(self):
# try:
# pass
# except OSError:
# pass
def
test_ITKwatershed
(
self
):
# First try without markers
im
=
numpy
.
zeros
([
50
,
50
,
50
],
dtype
=
'<f8'
)
# Generate and binarise two touching balls on the z-plane
centres
=
[[
25
,
25
,
15
],
[
25
,
25
,
35
]]
radii
=
[
10
,
10
]
spam
.
kalisphera
.
makeSphere
(
im
,
centres
,
radii
)
# Threshold at 0.5
im
[
im
>
0.5
]
=
1.0
im
[
im
<=
0.5
]
=
0.0
# Watershed
lab
=
spam
.
label
.
watershed
(
im
)
self
.
assertEqual
(
lab
.
max
(),
2
)
equivRadii
=
spam
.
label
.
equivalentRadii
(
lab
)
self
.
assertAlmostEqual
(
equivRadii
[
1
],
radii
[
0
],
places
=
1
)
self
.
assertAlmostEqual
(
equivRadii
[
2
],
radii
[
1
],
places
=
1
)
# Let's compute markers
m1
=
numpy
.
zeros
([
50
,
50
,
50
],
dtype
=
'<f8'
)
m2
=
numpy
.
zeros
([
50
,
50
,
50
],
dtype
=
'<f8'
)
# Generate and binarise two small internal balls
spam
.
kalisphera
.
makeSphere
(
m1
,
[
25
,
25
,
15
],
3
)
spam
.
kalisphera
.
makeSphere
(
m2
,
[
25
,
25
,
35
],
3
)
# Threshold at 0.5
m1
[
m1
>
0.5
]
=
1.0
m1
[
m1
<=
0.5
]
=
0.0
m2
[
m2
>
0.5
]
=
2.0
m2
[
m2
<=
0.5
]
=
0.0
markers
=
m1
+
m2
# Watershed with markers
lab
=
spam
.
label
.
watershed
(
im
,
markers
=
markers
)
self
.
assertEqual
(
lab
.
max
(),
2
)
equivRadii
=
spam
.
label
.
equivalentRadii
(
lab
)
self
.
assertAlmostEqual
(
equivRadii
[
1
],
radii
[
0
],
places
=
1
)
self
.
assertAlmostEqual
(
equivRadii
[
2
],
radii
[
1
],
places
=
1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
tests/test_binning.py
→
tools/
tests/test_binning.py
View file @
02434791
File moved
tests/test_contacts.py
→
tools/
tests/test_contacts.py
View file @
02434791
File moved
tests/test_correlateGM.py
→
tools/
tests/test_correlateGM.py
View file @
02434791
File moved
tests/test_covariance.py
→
tools/
tests/test_covariance.py
View file @
02434791
File moved
tests/test_deformation.py
→
tools/
tests/test_deformation.py
View file @
02434791
File moved
tests/test_excursions.py
→
tools/
tests/test_excursions.py
View file @
02434791
File moved
tests/test_filters.py
→
tools/
tests/test_filters.py
View file @
02434791
File moved
tests/test_globalDescriptor.py
→
tools/
tests/test_globalDescriptor.py
View file @
02434791
File moved
tests/test_histogramTools.py
→
tools/
tests/test_histogramTools.py
View file @
02434791
File moved
tests/test_imageManipulation.py
→
tools/
tests/test_imageManipulation.py
View file @
02434791
File moved
tests/test_kalisphera.py
→
tools/
tests/test_kalisphera.py
View file @
02434791
File moved
tests/test_label.py
→
tools/
tests/test_label.py
View file @
02434791
...
...
@@ -501,53 +501,53 @@ class TestFunctionLabel(unittest.TestCase):
res
=
spam
.
label
.
label
.
Spheroid
(
10
,
20
,
dim
=
3
).
digitize
()
self
.
assertIsNotNone
(
res
)
#
def test_FixUnderSegmentation(self):
#Generate two prolate grains (rice-like)
#
grain1 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
#
grain2 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
#Create the bigger labelled image
#
grainIm = numpy.concatenate((grain1,grain2))
#
grainIm = numpy.zeros(grainIm.shape)
#Add the grains to the bigger image
#
grainIm[:grain1.shape[0]-1,:,:] = grain1[:grain1.shape[0]-1,:,:]
#
grainIm[grain2.shape[0]-5:-5,:,:] = grainIm[grain2.shape[0]-5:-5,:,:] + grain1[:,:,:]
#Set all the labels to 1
#
grainIm = numpy.where(grainIm >= 1, 3, grainIm)
#Pad a border
#
grainIm = numpy.pad(grainIm, pad_width=10, mode='constant', constant_values = 0)
#Create the 'greyScale' image
#
greyIm = numpy.where(grainIm == 3, 30000, 10000)
#Check that the greyscale image is normalized
#
res1 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.5, 20*0.5)
#
self.assertEqual(res1, None)
#Check that a or c is valid
#
res2 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], numpy.nan, numpy.nan)
#
self.assertEqual(res2, None)
#Check that a or c are positive
#
res3 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], -1, 10)
#
self.assertEqual(res3, None)
#Run fixUnderSegmentation
#
greyIm = numpy.where(grainIm == 3, 0.75, 0.25)
#
res4 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
#Check that there are two grains
#
self.assertEqual(numpy.max(numpy.unique(res4)), 2)
#Check that it runs even if the label does not exist
#
res5 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
#
self.assertIsNotNone(res5)
#Check for a vect that is not a list
#
res6 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = (0,1,0))
#
self.assertIsNone(res6)
#Check that it works without the input vect
#
res7 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1)
#
self.assertIsNotNone(res7)
#Check that it works with verbose = True
#
res8 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1, verbose = True)
#
self.assertIsNotNone(res8)
#Check that it works even for a non-existing label
#
res9 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [5], 10*0.8, 20*0.8, numVect = 1)
#
self.assertIsNotNone(res9)
def
_
test_FixUnderSegmentation
(
self
):
#
Generate two prolate grains (rice-like)
grain1
=
spam
.
label
.
label
.
Spheroid
(
10
,
20
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
grain2
=
spam
.
label
.
label
.
Spheroid
(
10
,
20
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
#
Create the bigger labelled image
grainIm
=
numpy
.
concatenate
((
grain1
,
grain2
))
grainIm
=
numpy
.
zeros
(
grainIm
.
shape
)
#
Add the grains to the bigger image
grainIm
[:
grain1
.
shape
[
0
]
-
1
,:,:]
=
grain1
[:
grain1
.
shape
[
0
]
-
1
,:,:]
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
=
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
+
grain1
[:,:,:]
#
Set all the labels to 1
grainIm
=
numpy
.
where
(
grainIm
>=
1
,
3
,
grainIm
)
#
Pad a border
grainIm
=
numpy
.
pad
(
grainIm
,
pad_width
=
10
,
mode
=
'constant'
,
constant_values
=
0
)
#
Create the 'greyScale' image
greyIm
=
numpy
.
where
(
grainIm
==
3
,
30000
,
10000
)
#
Check that the greyscale image is normalized
res1
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.5
,
20
*
0.5
)
self
.
assertEqual
(
res1
,
None
)
#
Check that a or c is valid
res2
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
numpy
.
nan
,
numpy
.
nan
)
self
.
assertEqual
(
res2
,
None
)
#
Check that a or c are positive
res3
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
-
1
,
10
)
self
.
assertEqual
(
res3
,
None
)
#
Run fixUnderSegmentation
greyIm
=
numpy
.
where
(
grainIm
==
3
,
0.75
,
0.25
)
res4
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.8
,
20
*
0.8
,
vect
=
[[
0
,
1
,
0
]])
#
Check that there are two grains
self
.
assertEqual
(
numpy
.
max
(
numpy
.
unique
(
res4
)),
2
)
#
Check that it runs even if the label does not exist
res5
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.8
,
20
*
0.8
,
vect
=
[[
0
,
1
,
0
]])
self
.
assertIsNotNone
(
res5
)
#
Check for a vect that is not a list
res6
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.8
,
20
*
0.8
,
vect
=
(
0
,
1
,
0
))
self
.
assertIsNone
(
res6
)
#
Check that it works without the input vect
res7
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.8
,
20
*
0.8
,
numVect
=
1
)
self
.
assertIsNotNone
(
res7
)
#
Check that it works with verbose = True
res8
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
3
],
10
*
0.8
,
20
*
0.8
,
numVect
=
1
,
verbose
=
True
)
self
.
assertIsNotNone
(
res8
)
#
Check that it works even for a non-existing label
res9
=
spam
.
label
.
label
.
fixUndersegmentation
(
grainIm
,
greyIm
,
[
5
],
10
*
0.8
,
20
*
0.8
,
numVect
=
1
)
self
.
assertIsNotNone
(
res9
)
def
test_contactOrientations
(
self
):
...
...
@@ -709,32 +709,6 @@ class TestFunctionLabel(unittest.TestCase):
imLab2
=
spam
.
label
.
moveLabels
(
imLab
,
PhiField
,
boundingBoxes
=
boundingBoxes
,
centresOfMass
=
centresOfMass
)
self
.
assertIsNotNone
(
imLab2
)
# Test 7 -> Check that it runs for more than one grain....
# Create two grains
grain1
=
spam
.
label
.
label
.
Spheroid
(
15
,
15
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
grain1
=
numpy
.
pad
(
grain1
,
(
5
),
'constant'
,
constant_values
=
(
0
))
grain1
=
numpy
.
where
(
grain1
,
1
,
0
)
grain2
=
spam
.
label
.
label
.
Spheroid
(
15
,
15
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
grain2
=
numpy
.
pad
(
grain2
,
(
5
),
'constant'
,
constant_values
=
(
0
))
grain2
=
numpy
.
where
(
grain2
,
2
,
0
)
grainIm
=
numpy
.
concatenate
((
grain1
,
grain2
))
grainIm
=
numpy
.
zeros
(
grainIm
.
shape
)
grainIm
[:
grain1
.
shape
[
0
]
-
1
,:,:]
=
grain1
[:
grain1
.
shape
[
0
]
-
1
,:,:]
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
=
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
+
grain2
[:,:,:]
grainIm
=
grainIm
.
astype
(
int
)
# Create empty PhiField
PhiField
=
numpy
.
zeros
((
3
,
4
,
4
))
# Compute initial volume & COM
COM
=
spam
.
label
.
centresOfMass
(
grainIm
)
iniVol
=
spam
.
label
.
volumes
(
grainIm
)
# Apply a displacement
transformation
=
{
't'
:
[
1
,
1
,
1
]}
PhiField
[
1
]
=
spam
.
deformation
.
computePhi
(
transformation
)
transformation
=
{
't'
:
[
-
1
,
-
1
,
-
1
]}
PhiField
[
2
]
=
spam
.
deformation
.
computePhi
(
transformation
)
imLab2
=
spam
.
label
.
moveLabels
(
grainIm
,
PhiField
)
self
.
assertIsNotNone
(
imLab2
)
def
test_erodeLabels
(
self
):
# Create the sphere
imLab
=
skimage
.
morphology
.
ball
(
20
)
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment