Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review 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
mantidproject
mantid
Commits
a3aba424
Commit
a3aba424
authored
9 years ago
by
Elliot Oram
Browse files
Options
Downloads
Patches
Plain Diff
Ensure test only runs on supported f2py platforms
Refs #13826
parent
1dc7b58b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py
+181
-184
181 additions, 184 deletions
...thonInterface/test/python/plugins/algorithms/QLRunTest.py
with
181 additions
and
184 deletions
Framework/PythonInterface/test/python/plugins/algorithms/QLRunTest.py
+
181
−
184
View file @
a3aba424
import
unittest
from
mantid.simpleapi
import
*
from
IndirectImport
import
*
from
mantid.api
import
MatrixWorkspace
,
WorkspaceGroup
class
QLRunTest
(
unittest
.
TestCase
):
_res_ws
=
None
_sample_ws
=
None
_num_bins
=
None
_num_hists
=
None
def
setUp
(
self
):
self
.
_res_ws
=
Load
(
Filename
=
'
irs26173_graphite002_res.nxs
'
,
OutputWorkspace
=
'
__QLRunTest_Resolution
'
)
self
.
_sample_ws
=
Load
(
Filename
=
'
irs26176_graphite002_red.nxs
'
,
OutputWorkspace
=
'
__QLRunTest_Sample
'
)
self
.
_num_bins
=
self
.
_sample_ws
.
blocksize
()
self
.
_num_hists
=
self
.
_sample_ws
.
getNumberHistograms
()
def
_validate_QLr_shape
(
self
,
result
,
probability
,
group
):
"""
Validates that the output workspaces are of the correct type, units and shape.
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test size/shape of result
self
.
assertTrue
(
isinstance
(
result
,
MatrixWorkspace
))
self
.
assertEquals
(
result
.
getNumberHistograms
(),
21
)
self
.
assertEquals
(
result
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of probability
self
.
assertTrue
(
isinstance
(
probability
,
MatrixWorkspace
))
self
.
assertEquals
(
probability
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
probability
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of group fitting workspaces
self
.
assertTrue
(
isinstance
(
group
,
WorkspaceGroup
))
self
.
assertEquals
(
group
.
getNumberOfEntries
(),
self
.
_sample_ws
.
getNumberHistograms
())
# Test sub workspaces
for
i
in
range
(
group
.
getNumberOfEntries
()):
sub_ws
=
group
.
getItem
(
i
)
self
.
assertTrue
(
isinstance
(
sub_ws
,
MatrixWorkspace
))
self
.
assertEqual
(
sub_ws
.
getNumberHistograms
(),
5
)
self
.
assertEquals
(
sub_ws
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
DeltaE
'
)
def
_validate_Qlr_value
(
self
,
result
,
probability
,
group
):
"""
Validates that the output workspaces have expected values
with values from the last known correct version
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test values of result
result_y
=
result
.
dataY
(
0
)
self
.
assertEquals
(
round
(
result
.
dataY
(
0
)[
0
],
5
),
6.06105
)
self
.
assertEquals
(
round
(
result
.
dataY
(
1
)[
0
],
4
),
68.5744
)
self
.
assertEquals
(
round
(
result
.
dataY
(
2
)[
0
],
7
),
0.0589315
)
self
.
assertEquals
(
round
(
result
.
dataY
(
3
)[
0
],
7
),
0.0812087
)
# Test values of probability
prob_y
=
probability
.
dataY
(
0
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
0
)[
0
],
1
),
-
74176.1
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
1
)[
0
],
3
),
-
404.884
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
2
)[
0
],
6
),
-
0.222565
)
# Test values of group
sub_ws
=
group
.
getItem
(
0
)
sub_y
=
sub_ws
.
dataY
(
0
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
0
)[
0
],
5
),
0.02540
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
1
)[
0
],
5
),
0.01903
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
2
)[
0
],
5
),
-
0.00638
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
3
)[
0
],
5
),
0.01614
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
4
)[
0
],
5
),
-
0.00926
)
def
_validate_QSe_shape
(
self
,
result
,
group
):
"""
Validates that the output workspaces are of the correct type, units and shape.
with values from the last known correct version
@param result Result workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test size/shape of result
self
.
assertTrue
(
isinstance
(
result
,
MatrixWorkspace
))
self
.
assertEquals
(
result
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
result
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of group fitting workspaces
self
.
assertTrue
(
isinstance
(
group
,
WorkspaceGroup
))
self
.
assertEquals
(
group
.
getNumberOfEntries
(),
self
.
_sample_ws
.
getNumberHistograms
())
# Test sub workspaces
for
i
in
range
(
group
.
getNumberOfEntries
()):
sub_ws
=
group
.
getItem
(
i
)
self
.
assertTrue
(
isinstance
(
sub_ws
,
MatrixWorkspace
))
self
.
assertEqual
(
sub_ws
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
sub_ws
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
DeltaE
'
)
def
_validate_QSe_value
(
self
,
result
,
group
):
"""
Validates that the output workspaces have expected values
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test values of result
result_y
=
result
.
dataY
(
0
)
self
.
assertEquals
(
round
(
result
.
dataY
(
0
)[
0
],
5
),
81.12644
)
self
.
assertEquals
(
round
(
result
.
dataY
(
1
)[
0
],
7
),
0.0319747
)
self
.
assertEquals
(
round
(
result
.
dataY
(
2
)[
0
],
5
),
0.77168
)
# Test values of group
sub_ws
=
group
.
getItem
(
0
)
sub_y
=
sub_ws
.
dataY
(
0
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
0
)[
0
],
5
),
0.02540
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
1
)[
0
],
5
),
0.01632
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
2
)[
0
],
5
),
-
0.00908
)
def
test_QLr_Run
(
self
):
"""
Test Lorentzian fit for QLRun
"""
fit_group
,
result
,
prob
=
QLRun
(
Program
=
'
QL
'
,
SampleWorkspace
=
self
.
_sample_ws
,
ResolutionWorkspace
=
self
.
_res_ws
,
MinRange
=-
0.547607
,
MaxRange
=
0.543216
,
SampleBins
=
1
,
ResolutionBins
=
1
,
Elastic
=
False
,
Background
=
'
Sloping
'
,
FixedWidth
=
False
,
UseResNorm
=
False
,
WidthFile
=
''
,
Loop
=
True
,
Save
=
False
,
Plot
=
'
None
'
)
self
.
_validate_QLr_shape
(
result
,
prob
,
fit_group
)
self
.
_validate_Qlr_value
(
result
,
prob
,
fit_group
)
def
test_QSe_Run
(
self
):
"""
Test Stretched Exponential fit for QLRun
"""
fit_group
,
result
=
QLRun
(
Program
=
'
QSe
'
,
SampleWorkspace
=
self
.
_sample_ws
,
ResolutionWorkspace
=
self
.
_res_ws
,
MinRange
=-
0.547607
,
MaxRange
=
0.543216
,
SampleBins
=
1
,
ResolutionBins
=
1
,
Elastic
=
False
,
Background
=
'
Sloping
'
,
FixedWidth
=
False
,
UseResNorm
=
False
,
WidthFile
=
''
,
Loop
=
True
,
Save
=
False
,
Plot
=
'
None
'
)
self
.
_validate_QSe_shape
(
result
,
fit_group
)
self
.
_validate_QSe_value
(
result
,
fit_group
)
if
__name__
==
"
__main__
"
:
unittest
.
main
()
\ No newline at end of file
if
is_supported_f2py_platform
():
class
QLRunTest
(
unittest
.
TestCase
):
_res_ws
=
None
_sample_ws
=
None
_num_bins
=
None
_num_hists
=
None
def
setUp
(
self
):
self
.
_res_ws
=
Load
(
Filename
=
'
irs26173_graphite002_res.nxs
'
,
OutputWorkspace
=
'
__QLRunTest_Resolution
'
)
self
.
_sample_ws
=
Load
(
Filename
=
'
irs26176_graphite002_red.nxs
'
,
OutputWorkspace
=
'
__QLRunTest_Sample
'
)
self
.
_num_bins
=
self
.
_sample_ws
.
blocksize
()
self
.
_num_hists
=
self
.
_sample_ws
.
getNumberHistograms
()
def
_validate_QLr_shape
(
self
,
result
,
probability
,
group
):
"""
Validates that the output workspaces are of the correct type, units and shape.
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test size/shape of result
self
.
assertTrue
(
isinstance
(
result
,
MatrixWorkspace
))
self
.
assertEquals
(
result
.
getNumberHistograms
(),
21
)
self
.
assertEquals
(
result
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of probability
self
.
assertTrue
(
isinstance
(
probability
,
MatrixWorkspace
))
self
.
assertEquals
(
probability
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
probability
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of group fitting workspaces
self
.
assertTrue
(
isinstance
(
group
,
WorkspaceGroup
))
self
.
assertEquals
(
group
.
getNumberOfEntries
(),
self
.
_sample_ws
.
getNumberHistograms
())
# Test sub workspaces
for
i
in
range
(
group
.
getNumberOfEntries
()):
sub_ws
=
group
.
getItem
(
i
)
self
.
assertTrue
(
isinstance
(
sub_ws
,
MatrixWorkspace
))
self
.
assertEqual
(
sub_ws
.
getNumberHistograms
(),
5
)
self
.
assertEquals
(
sub_ws
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
DeltaE
'
)
def
_validate_Qlr_value
(
self
,
result
,
probability
,
group
):
"""
Validates that the output workspaces have expected values
with values from the last known correct version
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test values of result
result_y
=
result
.
dataY
(
0
)
self
.
assertEquals
(
round
(
result
.
dataY
(
0
)[
0
],
5
),
6.06105
)
self
.
assertEquals
(
round
(
result
.
dataY
(
1
)[
0
],
4
),
68.5744
)
self
.
assertEquals
(
round
(
result
.
dataY
(
2
)[
0
],
7
),
0.0589315
)
self
.
assertEquals
(
round
(
result
.
dataY
(
3
)[
0
],
7
),
0.0812087
)
# Test values of probability
prob_y
=
probability
.
dataY
(
0
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
0
)[
0
],
1
),
-
74176.1
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
1
)[
0
],
3
),
-
404.884
)
self
.
assertEquals
(
round
(
probability
.
dataY
(
2
)[
0
],
6
),
-
0.222565
)
# Test values of group
sub_ws
=
group
.
getItem
(
0
)
sub_y
=
sub_ws
.
dataY
(
0
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
0
)[
0
],
5
),
0.02540
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
1
)[
0
],
5
),
0.01903
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
2
)[
0
],
5
),
-
0.00638
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
3
)[
0
],
5
),
0.01614
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
4
)[
0
],
5
),
-
0.00926
)
def
_validate_QSe_shape
(
self
,
result
,
group
):
"""
Validates that the output workspaces are of the correct type, units and shape.
with values from the last known correct version
@param result Result workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test size/shape of result
self
.
assertTrue
(
isinstance
(
result
,
MatrixWorkspace
))
self
.
assertEquals
(
result
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
result
.
blocksize
(),
self
.
_num_hists
)
self
.
assertEquals
(
result
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
MomentumTransfer
'
)
# Test size/shape of group fitting workspaces
self
.
assertTrue
(
isinstance
(
group
,
WorkspaceGroup
))
self
.
assertEquals
(
group
.
getNumberOfEntries
(),
self
.
_sample_ws
.
getNumberHistograms
())
# Test sub workspaces
for
i
in
range
(
group
.
getNumberOfEntries
()):
sub_ws
=
group
.
getItem
(
i
)
self
.
assertTrue
(
isinstance
(
sub_ws
,
MatrixWorkspace
))
self
.
assertEqual
(
sub_ws
.
getNumberHistograms
(),
3
)
self
.
assertEquals
(
sub_ws
.
getAxis
(
0
).
getUnit
().
unitID
(),
'
DeltaE
'
)
def
_validate_QSe_value
(
self
,
result
,
group
):
"""
Validates that the output workspaces have expected values
@param result Result workspace from QLRun
@param prob Probability workspace from QLRun
@param group Group workspace of fitted spectra from QLRun
"""
# Test values of result
result_y
=
result
.
dataY
(
0
)
self
.
assertEquals
(
round
(
result
.
dataY
(
0
)[
0
],
5
),
81.12644
)
self
.
assertEquals
(
round
(
result
.
dataY
(
1
)[
0
],
7
),
0.0319747
)
self
.
assertEquals
(
round
(
result
.
dataY
(
2
)[
0
],
5
),
0.77168
)
# Test values of group
sub_ws
=
group
.
getItem
(
0
)
sub_y
=
sub_ws
.
dataY
(
0
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
0
)[
0
],
5
),
0.02540
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
1
)[
0
],
5
),
0.01632
)
self
.
assertEquals
(
round
(
sub_ws
.
dataY
(
2
)[
0
],
5
),
-
0.00908
)
def
test_QLr_Run
(
self
):
"""
Test Lorentzian fit for QLRun
"""
fit_group
,
result
,
prob
=
QLRun
(
Program
=
'
QL
'
,
SampleWorkspace
=
self
.
_sample_ws
,
ResolutionWorkspace
=
self
.
_res_ws
,
MinRange
=-
0.547607
,
MaxRange
=
0.543216
,
SampleBins
=
1
,
ResolutionBins
=
1
,
Elastic
=
False
,
Background
=
'
Sloping
'
,
FixedWidth
=
False
,
UseResNorm
=
False
,
WidthFile
=
''
,
Loop
=
True
,
Save
=
False
,
Plot
=
'
None
'
)
self
.
_validate_QLr_shape
(
result
,
prob
,
fit_group
)
self
.
_validate_Qlr_value
(
result
,
prob
,
fit_group
)
def
test_QSe_Run
(
self
):
"""
Test Stretched Exponential fit for QLRun
"""
fit_group
,
result
=
QLRun
(
Program
=
'
QSe
'
,
SampleWorkspace
=
self
.
_sample_ws
,
ResolutionWorkspace
=
self
.
_res_ws
,
MinRange
=-
0.547607
,
MaxRange
=
0.543216
,
SampleBins
=
1
,
ResolutionBins
=
1
,
Elastic
=
False
,
Background
=
'
Sloping
'
,
FixedWidth
=
False
,
UseResNorm
=
False
,
WidthFile
=
''
,
Loop
=
True
,
Save
=
False
,
Plot
=
'
None
'
)
self
.
_validate_QSe_shape
(
result
,
fit_group
)
self
.
_validate_QSe_value
(
result
,
fit_group
)
if
__name__
==
"
__main__
"
:
unittest
.
main
()
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