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
tomotools
tomoscan
Commits
ee4cbb03
Commit
ee4cbb03
authored
Aug 24, 2020
by
payno
Committed by
payno
Sep 03, 2020
Browse files
[test] add test for edf on flat field correction and and get_sinogram
parent
1dc31042
Changes
1
Hide whitespace changes
Inline
Side-by-side
tomoscan/esrf/test/test_edfscan.py
View file @
ee4cbb03
...
...
@@ -37,6 +37,7 @@ from tomoscan.esrf.mock import MockEDF
from
tomoscan.esrf.edfscan
import
EDFTomoScan
from
tomoscan.scanbase
import
TomoScanBase
from
tomoscan.scanfactory
import
ScanFactory
from
silx.io.utils
import
get_data
from
silx.io.url
import
DataUrl
import
collections
import
json
...
...
@@ -311,6 +312,103 @@ class TestProjections(unittest.TestCase):
self
.
assertTrue
(
360
not
in
proj_angle_dict
)
class
TestFlatFieldCorrection
(
unittest
.
TestCase
):
"""Test the flat field correction"""
def
setUp
(
self
)
->
None
:
self
.
folder
=
tempfile
.
mkdtemp
()
mock
=
MockEDF
(
scan_path
=
self
.
folder
,
n_radio
=
30
,
n_ini_radio
=
30
,
n_extra_radio
=
0
,
dim
=
20
)
mock
.
end_acquisition
()
self
.
scan
=
EDFTomoScan
(
scan
=
self
.
folder
)
def
tearDown
(
self
)
->
None
:
shutil
.
rmtree
(
self
.
folder
)
def
testFlatAndDarksSet
(
self
):
"""Test no error is log if `normed` dark and flat are provided"""
self
.
scan
.
set_normed_flats
(
{
1
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
)),
21
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
)),
}
)
self
.
scan
.
set_normed_darks
({
0
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
))})
projs
=
[]
proj_indexes
=
[]
for
proj_index
,
proj
in
self
.
scan
.
projections
.
items
():
projs
.
append
(
proj
)
proj_indexes
.
append
(
proj_index
)
normed_proj
=
self
.
scan
.
flat_field_correction
(
projs
=
projs
,
proj_indexes
=
proj_indexes
)
self
.
assertEqual
(
len
(
normed_proj
),
len
(
self
.
scan
.
projections
))
raw_data
=
get_data
(
projs
[
10
])
self
.
assertFalse
(
numpy
.
array_equal
(
raw_data
,
normed_proj
[
10
]))
def
testNoFlatOrDarkSet
(
self
):
"""Test an error is log if `normed` dark and flat aren't provided"""
projs
=
[]
proj_indexes
=
[]
for
proj_index
,
proj
in
self
.
scan
.
projections
.
items
():
projs
.
append
(
proj
)
proj_indexes
.
append
(
proj_index
)
with
self
.
assertLogs
(
"tomoscan"
,
level
=
"ERROR"
):
normed_proj
=
self
.
scan
.
flat_field_correction
(
projs
=
projs
,
proj_indexes
=
proj_indexes
)
self
.
assertEqual
(
len
(
normed_proj
),
len
(
self
.
scan
.
projections
))
raw_data
=
get_data
(
projs
[
10
])
self
.
assertTrue
(
numpy
.
array_equal
(
raw_data
,
normed_proj
[
10
]))
class
TestGetSinogram
(
unittest
.
TestCase
):
"""Test the get_sinogram function"""
def
setUp
(
self
)
->
None
:
self
.
folder
=
tempfile
.
mkdtemp
()
mock
=
MockEDF
(
scan_path
=
self
.
folder
,
n_radio
=
30
,
n_ini_radio
=
30
,
n_extra_radio
=
0
,
dim
=
20
)
mock
.
end_acquisition
()
self
.
scan
=
EDFTomoScan
(
scan
=
self
.
folder
)
self
.
scan
.
set_normed_flats
(
{
21
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
)),
1520
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
)),
}
)
self
.
scan
.
set_normed_darks
({
0
:
numpy
.
random
.
random
(
20
*
20
).
reshape
((
20
,
20
))})
def
tearDown
(
self
)
->
None
:
shutil
.
rmtree
(
self
.
folder
)
def
testGetSinogram1
(
self
):
sinogram
=
self
.
scan
.
get_sinogram
(
line
=
12
,
subsampling
=
1
)
self
.
assertEqual
(
sinogram
.
shape
,
(
30
,
20
))
def
testGetSinogram2
(
self
):
"""Test if subsampling is negative"""
with
self
.
assertRaises
(
ValueError
):
self
.
scan
.
get_sinogram
(
line
=
0
,
subsampling
=-
1
)
def
testGetSinogram3
(
self
):
sinogram
=
self
.
scan
.
get_sinogram
(
line
=
0
,
subsampling
=
3
)
self
.
assertEqual
(
sinogram
.
shape
,
(
10
,
20
))
def
testGetSinogram4
(
self
):
"""Test if line is not in the projection"""
with
self
.
assertRaises
(
ValueError
):
self
.
scan
.
get_sinogram
(
line
=-
1
,
subsampling
=
1
)
def
testGetSinogram5
(
self
):
"""Test if line is not in the projection"""
with
self
.
assertRaises
(
ValueError
):
self
.
scan
.
get_sinogram
(
line
=
35
,
subsampling
=
1
)
class
TestScanValidatorFindFiles
(
unittest
.
TestCase
):
"""Function testing the getReconstructionsPaths function is correctly
functioning"""
...
...
@@ -512,6 +610,8 @@ def suite():
TestProjections
,
TestTomoBaseHashable
,
TestOriDarksFlats
,
TestFlatFieldCorrection
,
TestGetSinogram
,
):
test_suite
.
addTest
(
unittest
.
defaultTestLoader
.
loadTestsFromTestCase
(
ui
))
return
test_suite
...
...
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