Skip to content
Snippets Groups Projects
Commit 5e8b7cec authored by Gagik Vardanyan's avatar Gagik Vardanyan
Browse files

Re #19880 progress reporting, use LoadAndMerge

parent 0b85b334
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ from __future__ import (absolute_import, division, print_function)
import os.path
from mantid.kernel import Direction, StringContainsValidator, PropertyManagerProperty
from mantid.api import AlgorithmFactory, AlgorithmManager, MultipleFileProperty, \
WorkspaceProperty, PythonAlgorithm, FileLoaderRegistry
WorkspaceProperty, PythonAlgorithm, FileLoaderRegistry, Progress
from mantid.simpleapi import MergeRuns, RenameWorkspace, DeleteWorkspace, GroupWorkspaces, mtd
......@@ -13,6 +13,7 @@ class LoadAndMerge(PythonAlgorithm):
_version = None
_loader_options = None
_prefix = ''
_progress = None
def name(self):
return "LoadMergeRuns"
......@@ -55,6 +56,7 @@ class LoadAndMerge(PythonAlgorithm):
@param run : the full file path
@param runnumber : the run number
"""
self._progress.report('Loading '+runnumber)
alg = self._create_fresh_loader()
alg.setPropertyValue('Filename', run)
alg.setPropertyValue('OutputWorkspace', runnumber)
......@@ -74,7 +76,9 @@ class LoadAndMerge(PythonAlgorithm):
# having an additional optional output workspace, but without requesting the optional output,
# it will still be produced with some hidden temporary name (__TMPx...).
# This is related to replaying the history, or might as well be a bug in Algorithm base class.
alg = AlgorithmManager.create(self._loader, self._version)
# alg = AlgorithmManager.create(self._loader, self._version)
alg = self.createChildAlgorithm(self._loader, self._version)
alg.setAlwaysStoreInADS(True)
alg.initialize()
for key in self._loader_options.keys():
alg.setPropertyValue(key, self._loader_options.getPropertyValue(key))
......@@ -82,6 +86,9 @@ class LoadAndMerge(PythonAlgorithm):
def PyExec(self):
runs = self.getProperty('Filename').value
runs_as_str = self.getPropertyValue('Filename')
number_runs = runs_as_str.count(',') + runs_as_str.count('+') + 1
self._progress = Progress(self, start=0.0, end=1.0, nreports=number_runs)
self._loader = self.getPropertyValue('LoaderName')
self._version = self.getProperty('LoaderVersion').value
self._loader_options = self.getProperty('LoaderOptions').value
......
......@@ -103,17 +103,23 @@ class PowderDiffILLReduction(PythonAlgorithm):
def PyExec(self):
self._progress = Progress(self, start=0.0, end=1.0, nreports=4)
self._configure()
temp_ws = self._hide('temp')
joined_ws = self._hide('joined')
mon_ws = self._hide('mon')
to_group = self._load()
GroupWorkspaces(InputWorkspaces=to_group, OutputWorkspace=temp_ws)
self._progress.report('Loading the data')
LoadAndMerge(Filename=self.getPropertyValue('Run'),
LoaderName='LoadILLDiffraction',
OutputWorkspace=temp_ws)
self._progress.report('Normalising and merging')
if self._normalise_option == 'Time':
for ws in to_group:
for ws in mtd[temp_ws]:
# normalise to time here, before joining, since the duration is in sample logs
duration = mtd[ws].getRun().getLogData('duration').value
duration = ws.getRun().getLogData('duration').value
Scale(InputWorkspace=ws,OutputWorkspace=ws,Factor=1./duration)
try:
......@@ -132,6 +138,7 @@ class PowderDiffILLReduction(PythonAlgorithm):
DeleteWorkspace(mon_ws)
self._progress.report('Applying calibration or ROC if needed')
if self._calibration_file:
calib_ws = self._hide('calib')
LoadNexusProcessed(Filename=self._calibration_file, OutputWorkspace=calib_ws)
......@@ -157,6 +164,7 @@ class PowderDiffILLReduction(PythonAlgorithm):
self.log().information('First positive 2theta at workspace index: ' + str(first_positive_theta))
CropWorkspace(InputWorkspace=joined_ws, OutputWorkspace=joined_ws, StartWorkspaceIndex=first_positive_theta)
self._progress.report('Treating the zero counting cells')
self._find_zero_cells(joined_ws)
if self._zero_counting_option == 'Crop':
......@@ -179,41 +187,6 @@ class PowderDiffILLReduction(PythonAlgorithm):
RenameWorkspace(InputWorkspace=joined_ws, OutputWorkspace=self._out_name)
self.setProperty('OutputWorkspace', self._out_name)
def _load(self):
"""
Loads the list of runs
If sum is requested, MergeRuns is called
@return : the list of the loaded ws names
"""
runs = self.getPropertyValue('Run')
to_group = []
self._progress = Progress(self, start=0.0, end=1.0, nreports=runs.count(',') + runs.count('+') + 1)
for runs_list in runs.split(','):
runs_sum = runs_list.split('+')
if len(runs_sum) == 1:
runnumber = os.path.basename(runs_sum[0]).split('.')[0]
run = self._hide_run(runnumber)
LoadILLDiffraction(Filename=runs_sum[0], OutputWorkspace=run)
self._progress.report('Loaded run #' + runnumber)
to_group.append(run)
else:
for i, run in enumerate(runs_sum):
runnumber = os.path.basename(run).split('.')[0]
if i == 0:
first = self._hide_run(runnumber + '_multiple')
LoadILLDiffraction(Filename=run, OutputWorkspace=first)
self._progress.report('Loaded run #' + runnumber)
to_group.append(first)
else:
run = self._hide_run(runnumber)
LoadILLDiffraction(Filename=run, OutputWorkspace=run)
self._progress.report('Loaded run #' + runnumber)
MergeRuns(InputWorkspaces=[first, run], OutputWorkspace=first)
DeleteWorkspace(Workspace=run)
return to_group
def _configure(self):
"""
Configures the input properties
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment