Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
29e686cb
Commit
29e686cb
authored
Aug 05, 2021
by
David Fairbrother
Committed by
Gemma Guest
Sep 22, 2021
Browse files
Add monitor handling in PreProcess
Return monitors when loading in the preprocess algorithm. Re #32125
parent
ec80631a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ReflectometryISISPreprocess.py
View file @
29e686cb
...
...
@@ -5,7 +5,8 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from
mantid.api
import
(
AlgorithmFactory
,
DataProcessorAlgorithm
,
MatrixWorkspaceProperty
,
MatrixWorkspace
,
WorkspaceGroup
)
from
mantid.api
import
(
AlgorithmFactory
,
DataProcessorAlgorithm
,
MatrixWorkspaceProperty
,
MatrixWorkspace
,
PropertyMode
,
WorkspaceGroup
)
from
mantid.kernel
import
(
CompositeValidator
,
StringArrayLengthValidator
,
StringArrayMandatoryValidator
,
StringArrayProperty
,
Direction
)
...
...
@@ -14,6 +15,7 @@ class ReflectometryISISPreprocess(DataProcessorAlgorithm):
_RUNS
=
'InputRunList'
_GROUP_TOF
=
'GroupTOFWorkspaces'
_OUTPUT_WS
=
'OutputWorkspace'
_MONITOR_WS
=
'MonitorWorkspace'
_EVENT_MODE
=
"EventMode"
def
__init__
(
self
):
...
...
@@ -46,10 +48,15 @@ class ReflectometryISISPreprocess(DataProcessorAlgorithm):
MatrixWorkspaceProperty
(
self
.
_OUTPUT_WS
,
''
,
direction
=
Direction
.
Output
),
doc
=
'The preprocessed output workspace. If multiple input runs are specified '
'they will be summed into a single output workspace.'
)
self
.
declareProperty
(
MatrixWorkspaceProperty
(
self
.
_MONITOR_WS
,
''
,
direction
=
Direction
.
Output
,
optional
=
PropertyMode
.
Optional
),
doc
=
'The loaded monitors workspace. This is only output in event mode.'
)
def
PyExec
(
self
):
workspace
=
self
.
_loadRun
(
self
.
getPropertyValue
(
self
.
_RUNS
))
workspace
,
monitor_ws
=
self
.
_loadRun
(
self
.
getPropertyValue
(
self
.
_RUNS
))
self
.
setProperty
(
self
.
_OUTPUT_WS
,
workspace
)
if
monitor_ws
:
self
.
setProperty
(
self
.
_MONITOR_WS
,
monitor_ws
)
@
staticmethod
def
_get_input_runs_validator
():
...
...
@@ -64,12 +71,12 @@ class ReflectometryISISPreprocess(DataProcessorAlgorithm):
"""Load a run as an event workspace if slicing is requested, or a histogram
workspace otherwise. Transmission runs are always loaded as histogram workspaces."""
event_mode
=
self
.
getProperty
(
self
.
_EVENT_MODE
).
value
monitor_ws
=
None
if
event_mode
:
alg
=
self
.
createChildAlgorithm
(
'LoadEventNexus'
,
Filename
=
run
,
LoadMonitors
=
True
)
alg
.
execute
()
ws
=
alg
.
getProperty
(
'OutputWorkspace'
).
value
# TODO
# monitors = alg.MonitorWorkspace
monitor_ws
=
alg
.
getProperty
(
'MonitorWorkspace'
).
value
self
.
_validate_event_ws
(
ws
)
self
.
log
().
information
(
'Loaded event workspace'
)
else
:
...
...
@@ -77,7 +84,7 @@ class ReflectometryISISPreprocess(DataProcessorAlgorithm):
alg
.
execute
()
ws
=
alg
.
getProperty
(
'OutputWorkspace'
).
value
self
.
log
().
information
(
'Loaded workspace '
)
return
ws
return
ws
,
monitor_ws
@
staticmethod
def
_validate_event_ws
(
workspace
):
...
...
Framework/PythonInterface/test/python/plugins/algorithms/WorkflowAlgorithms/ReflectometryISISPreprocessTest.py
View file @
29e686cb
...
...
@@ -47,12 +47,33 @@ class ReflectometryISISPreprocessTest(unittest.TestCase):
with
self
.
assertRaisesRegex
(
RuntimeError
,
"Workspace Groups"
):
ReflectometryISISPreprocess
.
_validate_event_ws
(
ws
)
def
_run_test
(
self
,
args
):
def
test_monitors_are_not_loaded_in_histo_mode
(
self
):
args
=
{
'InputRunList'
:
'13460'
,
"EventMode"
:
False
,
"OutputWorkspace"
:
"ws"
}
output_ws
,
monitor_ws
=
self
.
_run_test_with_monitors
(
args
)
self
.
assertIsInstance
(
output_ws
,
MatrixWorkspace
)
self
.
assertIsNone
(
monitor_ws
)
def
test_monitors_are_loaded_in_event_mode
(
self
):
args
=
{
'InputRunList'
:
'13460'
,
"EventMode"
:
True
,
"OutputWorkspace"
:
"ws"
}
output_ws
,
monitor_ws
=
self
.
_run_test_with_monitors
(
args
)
self
.
assertIsInstance
(
output_ws
,
IEventWorkspace
)
self
.
assertIsInstance
(
monitor_ws
,
MatrixWorkspace
)
def
_run_test_with_monitors
(
self
,
args
):
alg
=
create_algorithm
(
'ReflectometryISISPreprocess'
,
**
args
)
alg
.
setChild
(
True
)
alg
.
setRethrows
(
True
)
alg
.
execute
()
output_ws
=
alg
.
getProperty
(
'OutputWorkspace'
).
value
monitor_ws
=
alg
.
getProperty
(
'MonitorWorkspace'
).
value
return
output_ws
,
monitor_ws
def
_run_test
(
self
,
args
):
output_ws
,
_
=
self
.
_run_test_with_monitors
(
args
)
return
output_ws
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment