Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
kmap
xsocs
Commits
7c08836e
Commit
7c08836e
authored
Jul 04, 2019
by
Thomas Vincent
Browse files
make tests download resources work with silx v0.11
parent
52f0dd96
Changes
4
Hide whitespace changes
Inline
Side-by-side
xsocs/process/test/test_fitter.py
View file @
7c08836e
...
...
@@ -50,17 +50,14 @@ from xsocs.io.QSpaceH5 import QSpaceH5
class
TestPeakFitter
(
ParametricTestCase
):
"""Unit tests of the qspace converter class."""
_QSPACE_FILES
=
'qspace_1.h5'
,
'qspace_2.h5'
,
'qspace_3.h5'
,
'qspace_4.h5'
_GAUSSIAN_FILES
=
(
'gaussian_1.h5'
,
'gaussian_2.h5'
,
'gaussian_3.h5'
,
'gaussian_4.h5'
)
@
classmethod
def
setUpClass
(
cls
):
config
.
DEFAULT_PROCESS_NUMBER
=
2
# Limit number of processes
test_resources
.
getdir
(
'qspace.zip'
)
test_resources
.
getdir
(
'fit_2018_12.zip'
)
cls
.
_qspace_resources
=
sorted
(
f
for
f
in
test_resources
.
getdir
(
'qspace.zip'
)
if
f
.
endswith
(
'.h5'
))
cls
.
_fit_resources
=
sorted
(
f
for
f
in
test_resources
.
getdir
(
'fit_2018_12.zip'
)
if
f
.
endswith
(
'.h5'
))
def
setUp
(
self
):
self
.
_tmpTestDir
=
tempfile
.
mkdtemp
()
...
...
@@ -82,11 +79,11 @@ class TestPeakFitter(ParametricTestCase):
def
test_gaussian
(
self
):
"""Test gaussian fit"""
for
fit_f
,
qspace_f
in
zip
(
self
.
_
GAUSSIAN_FILES
,
self
.
_QSPACE_FILES
):
for
fit_f
,
qspace_f
in
zip
(
self
.
_
fit_resources
,
self
.
_qspace_resources
):
with
self
.
subTest
(
fit_f
=
fit_f
,
qspace_f
=
qspace_f
):
# Configure fitting
fitter
=
PeakFitter
(
qspace_f
=
test_resources
.
getfile
(
'qspace/'
+
qspace_f
)
,
qspace_f
=
qspace_f
,
fit_type
=
FitTypes
.
GAUSSIAN
,
background
=
BackgroundTypes
.
NONE
)
self
.
assertEqual
(
fitter
.
status
,
fitter
.
READY
)
...
...
@@ -96,20 +93,20 @@ class TestPeakFitter(ParametricTestCase):
self
.
assertEqual
(
fitter
.
status
,
fitter
.
DONE
)
# Compare results
ref
=
FitResult
.
from_fit_h5
(
test_resources
.
getfile
(
'fit_2018_12/'
+
fit_f
))
ref
=
FitResult
.
from_fit_h5
(
fit_f
)
self
.
_assertResultAlmostEqual
(
ref
,
fitter
.
results
)
# Save as HDF5 and compare
fit_out
=
os
.
path
.
join
(
self
.
_tmpTestDir
,
fit_f
)
fit_filename
=
os
.
path
.
basename
(
fit_f
)
fit_out
=
os
.
path
.
join
(
self
.
_tmpTestDir
,
fit_filename
)
fitter
.
results
.
to_fit_h5
(
fit_out
)
self
.
_assertResultAlmostEqual
(
ref
,
FitResult
.
from_fit_h5
(
fit_out
))
def
test_com
(
self
):
"""Test Center-of-mass and Max reduction"""
for
qspace_f
ile
in
self
.
_
QSPACE_FILES
:
qspace_f
=
test_resources
.
getfile
(
'qspace/'
+
qspace_f
ile
)
for
qspace_f
in
self
.
_
qspace_resources
:
filename
=
os
.
path
.
basename
(
qspace_f
)
# Configure reduction
fitter
=
PeakFitter
(
...
...
@@ -125,7 +122,7 @@ class TestPeakFitter(ParametricTestCase):
# Test results with reference implementation
for
key
,
ref
in
self
.
_qspace_com_result
(
qspace_f
).
items
():
for
dim
in
range
(
3
):
with
self
.
subTest
(
qspace_file
=
qspace_fil
e
,
with
self
.
subTest
(
qspace_file
=
filenam
e
,
dimension
=
dim
,
parameter
=
key
):
self
.
assertTrue
(
numpy
.
array_equal
(
...
...
@@ -133,7 +130,7 @@ class TestPeakFitter(ParametricTestCase):
# Save as HDF5 and check saved result
fit_out
=
os
.
path
.
join
(
self
.
_tmpTestDir
,
'com_result_'
+
qspace_fil
e
+
'.h5'
)
self
.
_tmpTestDir
,
'com_result_'
+
filenam
e
+
'.h5'
)
fitter
.
results
.
to_fit_h5
(
fit_out
)
self
.
assertEqual
(
fitter
.
results
,
FitResult
.
from_fit_h5
(
fit_out
))
...
...
xsocs/process/test/test_merger.py
View file @
7c08836e
...
...
@@ -82,10 +82,10 @@ class TestMerger(unittest.TestCase):
cls
.
_tmpdir
=
tempfile
.
mkdtemp
()
cls
.
_spec_h5
=
os
.
path
.
join
(
cls
.
_tmpdir
,
'spec_h5.h5'
)
test_resources
.
getdir
(
'spec.zip'
)
spec_f
=
test_resources
.
getfile
(
'spec/
spec/test.spec'
)
spec_resources
=
test_resources
.
getdir
(
'spec.zip'
)
spec_f
=
[
f
for
f
in
spec_resources
if
f
.
endswith
(
'
spec/test.spec'
)
][
0
]
img_dir
=
os
.
path
.
dirname
(
test_resources
.
getfile
(
'spec/
img/test_340800_0000.edf.gz'
))
[
f
for
f
in
spec_resources
if
f
.
endswith
(
'
img/test_340800_0000.edf.gz'
)
][
0
]
)
parser
=
cls
.
_parser
=
KmapSpecParser
(
spec_f
,
cls
.
_spec_h5
,
...
...
xsocs/process/test/test_parser.py
View file @
7c08836e
...
...
@@ -74,10 +74,10 @@ class TestParser(unittest.TestCase):
def
test_nominal
(
self
):
"""
"""
test_resources
.
getdir
(
'spec.zip'
)
spec_f
=
test_resources
.
getfile
(
'spec/
spec/test.spec'
)
spec_resources
=
test_resources
.
getdir
(
'spec.zip'
)
spec_f
=
[
f
for
f
in
spec_resources
if
f
.
endswith
(
'
spec/test.spec'
)
][
0
]
img_dir
=
os
.
path
.
dirname
(
test_resources
.
getfile
(
'spec/
img/test_340800_0000.edf.gz'
))
[
f
for
f
in
spec_resources
if
f
.
endswith
(
'
img/test_340800_0000.edf.gz'
)
][
0
]
)
spec_h5
=
os
.
path
.
join
(
self
.
_tmpTestDir
,
'spec.h5'
)
...
...
xsocs/process/test/test_qspace.py
View file @
7c08836e
...
...
@@ -55,8 +55,9 @@ class TestQSpace(ParametricTestCase):
cls
.
_tmpdir
=
tempfile
.
mkdtemp
()
test_resources
.
getdir
(
'merged.zip'
)
test_resources
.
getdir
(
'qspace.zip'
)
cls
.
_resources
=
{
'merged'
:
test_resources
.
getdir
(
'merged.zip'
),
'qspace'
:
test_resources
.
getdir
(
'qspace.zip'
)}
@
classmethod
def
tearDownClass
(
cls
):
...
...
@@ -65,6 +66,17 @@ class TestQSpace(ParametricTestCase):
shutil
.
rmtree
(
tmpdir
)
cls
.
_tmpdir
=
None
def
_get_resource
(
self
,
namespace
,
filename
):
"""Returns the filename of a resource
:param str namespace: Either 'merged' or 'qspace'
:param str filename: The filename to get
:rtype: str
"""
for
f
in
self
.
_resources
[
namespace
]:
if
f
.
endswith
(
filename
):
return
f
def
setUp
(
self
):
self
.
_tmpTestDir
=
tempfile
.
mkdtemp
()
...
...
@@ -74,7 +86,7 @@ class TestQSpace(ParametricTestCase):
def
test_nominal
(
self
):
"""Test of QSpaceConverter"""
master_f
=
tes
t_resource
s
.
getfile
(
'merged
/
test.h5'
)
master_f
=
self
.
_ge
t_resource
(
'merged
'
,
'
test.h5'
)
keys
=
[
'output_f'
,
'medfilt_dims'
,
'mask'
]
parameters
=
[
...
...
@@ -96,7 +108,8 @@ class TestQSpace(ParametricTestCase):
maskFilename
=
params
[
'mask'
]
if
maskFilename
is
not
None
:
# Load mask
mask
=
np
.
load
(
test_resources
.
getfile
(
'qspace/'
+
maskFilename
))
filename
=
self
.
_get_resource
(
'qspace'
,
maskFilename
)
mask
=
np
.
load
(
filename
)
converter
.
mask
=
mask
converter
.
convert
()
...
...
@@ -105,8 +118,7 @@ class TestQSpace(ParametricTestCase):
converter
.
DONE
,
msg
=
converter
.
status_msg
)
q_ref
=
test_resources
.
getfile
(
'qspace/{0}'
.
format
(
params
[
'output_f'
]))
q_ref
=
self
.
_get_resource
(
'qspace'
,
params
[
'output_f'
])
q_out
=
converter
.
results
q_ref_h5
=
QSpaceH5
(
q_ref
)
...
...
@@ -121,7 +133,7 @@ class TestQSpace(ParametricTestCase):
def
test_normalization
(
self
):
"""Test QSpaceConverter with normalization"""
output_f
=
os
.
path
.
join
(
self
.
_tmpTestDir
,
'qspace_normalization.h5'
)
master_f
=
tes
t_resource
s
.
getfile
(
'merged
/
test.h5'
)
master_f
=
self
.
_ge
t_resource
(
'merged
'
,
'
test.h5'
)
normalizer
=
'ccdint1'
master_h5
=
XsocsH5
(
master_f
)
...
...
Write
Preview
Markdown
is supported
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