Skip to content

Commit

Permalink
Add better default values and progress reporting to annulus
Browse files Browse the repository at this point in the history
Refs #10897
  • Loading branch information
DanNixon committed Feb 5, 2015
1 parent 4fe20b2 commit a175763
Showing 1 changed file with 26 additions and 14 deletions.
@@ -1,5 +1,5 @@
from mantid.simpleapi import *
from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, PropertyMode
from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, PropertyMode, Progress
from mantid.kernel import StringMandatoryValidator, Direction, logger


Expand All @@ -26,10 +26,10 @@ def PyInit(self):
self.declareProperty(name='ChemicalFormula', defaultValue='', validator=StringMandatoryValidator(),
doc='Chemical formula')

self.declareProperty(name='CanInnerRadius', defaultValue=0.0, doc='Sample radius')
self.declareProperty(name='SampleInnerRadius', defaultValue=0.0, doc='Sample radius')
self.declareProperty(name='SampleOuterRadius', defaultValue=0.0, doc='Sample radius')
self.declareProperty(name='CanOuterRadius', defaultValue=0.0, doc='Sample radius')
self.declareProperty(name='CanInnerRadius', defaultValue=0.2, doc='Sample radius')
self.declareProperty(name='SampleInnerRadius', defaultValue=0.15, doc='Sample radius')
self.declareProperty(name='SampleOuterRadius', defaultValue=0.16, doc='Sample radius')
self.declareProperty(name='CanOuterRadius', defaultValue=0.22, doc='Sample radius')
self.declareProperty(name='SampleNumberDensity', defaultValue=0.1, doc='Sample number density')
self.declareProperty(name='Events', defaultValue=5000, doc='Number of neutron events')
self.declareProperty(name='Plot', defaultValue=False, doc='Plot options')
Expand All @@ -47,6 +47,13 @@ def PyExec(self):

self._setup()

# Set up progress reporting
n_prog_reports = 4
if self._can_ws is not None:
n_prog_reports += 2
prog_reporter = Progress(self, 0.0, 1.0, n_prog_reports)

prog_reporter.report('Processing sample')
efixed = getEfixed(self._sample_ws_name)

sample_wave_ws = '__sam_wave'
Expand All @@ -55,6 +62,7 @@ def PyExec(self):

sample_thickness = self._sample_outer_radius - self._sample_inner_radius

prog_reporter.report('Calculating sample corrections')
AnnularRingAbsorption(InputWorkspace=sample_wave_ws,
OutputWorkspace=self._ass_ws,
SampleHeight=3.0,
Expand All @@ -68,25 +76,29 @@ def PyExec(self):

plot_list = [self._output_ws, self._sample_ws_name]

if self._can_ws_name is not None:
if self._can_ws is not None:
prog_reporter.report('Processing can')
can_wave_ws = '__can_wave'
ConvertUnits(InputWorkspace=self._can_ws_name, OutputWorkspace=can_wave_ws,
ConvertUnits(InputWorkspace=self._can_ws, OutputWorkspace=can_wave_ws,
Target='Wavelength', EMode='Indirect', EFixed=efixed)

if self._can_scale != 1.0:
logger.information('Scaling can by: ' + str(self._can_scale))
Scale(InputWorkspace=can_wave_ws, OutputWorkspace=can_wave_ws, Factor=self._can_scale, Operation='Multiply')

prog_reporter.report('Applying can corrections')
Minus(LHSWorkspace=sample_wave_ws, RHSWorkspace=can_wave_ws, OutputWorkspace=sample_wave_ws)
DeleteWorkspace(can_wave_ws)

plot_list.append(self._can_ws_name)
plot_list.append(self._can_ws)

prog_reporter.report('Applying corrections')
Divide(LHSWorkspace=sample_wave_ws, RHSWorkspace=self._ass_ws, OutputWorkspace=sample_wave_ws)
ConvertUnits(InputWorkspace=sample_wave_ws, OutputWorkspace=self._output_ws, Target='DeltaE',
EMode='Indirect', EFixed=efixed)
DeleteWorkspace(sample_wave_ws)

prog_reporter.report('Recording sample logs')
sample_logs = {'sample_shape': 'annulus',
'sample_filename': self._sample_ws_name,
'sample_inner': self._sample_inner_radius,
Expand All @@ -96,9 +108,9 @@ def PyExec(self):
addSampleLogs(self._ass_ws, sample_logs)
addSampleLogs(self._output_ws, sample_logs)

if self._can_ws_name is not None:
AddSampleLog(Workspace=self._ass_ws, LogName='can_filename', LogType='String', LogText=str(self._can_ws_name))
AddSampleLog(Workspace=self._output_ws, LogName='can_filename', LogType='String', LogText=str(self._can_ws_name))
if self._can_ws is not None:
AddSampleLog(Workspace=self._ass_ws, LogName='can_filename', LogType='String', LogText=str(self._can_ws))
AddSampleLog(Workspace=self._output_ws, LogName='can_filename', LogType='String', LogText=str(self._can_ws))
AddSampleLog(Workspace=self._ass_ws, LogName='can_scale', LogType='String', LogText=str(self._can_scale))
AddSampleLog(Workspace=self._output_ws, LogName='can_scale', LogType='String', LogText=str(self._can_scale))

Expand Down Expand Up @@ -137,9 +149,9 @@ def _setup(self):
if self._ass_ws == '':
self._ass_ws = '__ass'

self._can_ws_name = self.getPropertyValue('CanWorkspace')
if self._can_ws_name == '':
self._can_ws_name = None
self._can_ws = self.getPropertyValue('CanWorkspace')
if self._can_ws == '':
self._can_ws = None


# Register algorithm with Mantid
Expand Down

0 comments on commit a175763

Please sign in to comment.