Skip to content

Commit

Permalink
Swap usage in calibration and resolution algorithms
Browse files Browse the repository at this point in the history
Refs #10854
  • Loading branch information
DanNixon committed Jan 20, 2015
1 parent 756973e commit 72373bf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 47 deletions.
Expand Up @@ -10,33 +10,37 @@ class CreateCalibrationWorkspace(DataProcessorAlgorithm):
def category(self):
return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic'


def summary(self):
return 'Creates a calibration workspace from a White-Beam Vanadium run.'


def PyInit(self):
self.declareProperty(StringArrayProperty(name='InputFiles'),
doc='Comma separated list of input files')

self.declareProperty(WorkspaceProperty('OutputWorkspace', '',
direction=Direction.Output),
doc='Output workspace for calibration data')
doc='Comma separated list of input files.')

self.declareProperty(IntArrayProperty(name='DetectorRange', values=[0, 1],
validator=IntArrayMandatoryValidator()),
doc='Range of detectors')
doc='Range of detectors.')

self.declareProperty(FloatArrayProperty(name='PeakRange', values=[0.0, 100.0],
validator=FloatArrayMandatoryValidator()),
doc='')
doc='Time of flight range over the peak.')

self.declareProperty(FloatArrayProperty(name='BackgroundRange', values=[0.0, 1000.0],
validator=FloatArrayMandatoryValidator()),
doc='')
doc='Time of flight range over the background.')

self.declareProperty(name='ScaleFactor', defaultValue=1.0,
doc='')
doc='Factor by which to scale the result.')

self.declareProperty(name='Plot', defaultValue=False,
doc='Plot the calibration data as a spectra plot.')

self.declareProperty(WorkspaceProperty('OutputWorkspace', '',
direction=Direction.Output),
doc='Output workspace for calibration data.')

self.declareProperty(name='Plot', defaultValue=False, doc='Plot the calibration data')

def validateInputs(self):
"""
Expand All @@ -50,6 +54,7 @@ def validateInputs(self):

return issues


def _validate_range(self, property_name):
"""
Validates a range property.
Expand All @@ -67,12 +72,11 @@ def _validate_range(self, property_name):

return None


def PyExec(self):
from mantid import logger
from IndirectCommon import StartTime, EndTime

self._setup()
StartTime('CreateCalibrationWorkspace')

runs = []
for in_file in self._input_files:
Expand All @@ -97,6 +101,7 @@ def PyExec(self):
CalculateFlatBackground(InputWorkspace=calib_ws_name, OutputWorkspace=calib_ws_name,
StartX=self._back_range[0], EndX=self._back_range[1], Mode='Mean')

# TODO: Replace
from inelastic_indirect_reduction_steps import NormaliseToUnityStep
ntu = NormaliseToUnityStep()
ntu.set_factor(self._intensity_scale)
Expand All @@ -113,7 +118,6 @@ def PyExec(self):
self.setProperty('OutputWorkspace', self._out_ws)
self._post_process()

EndTime('CreateCalibrationWorkspace')

def _setup(self):
"""
Expand All @@ -133,6 +137,7 @@ def _setup(self):

self._plot = self.getProperty('Plot').value


def _post_process(self):
"""
Handles adding logs and plotting.
Expand All @@ -150,5 +155,6 @@ def _post_process(self):
from mantidplot import plotBin
plotBin(mtd[self._out_ws], 0)


# Register algorithm with Mantid
AlgorithmFactory.subscribe(CreateCalibrationWorkspace)
Expand Up @@ -255,6 +255,12 @@ def _setup(self):
self._plot_type = self.getPropertyValue('Plot')
self._output_ws = self.getPropertyValue('OutputWorkspace')

# Disable sum files if there is only one file
if len(self._data_files) == 1:
if self._sum_files:
logger.warning('SumFiles disabled when only one input file is provided.')
self._sum_files = False

# Get the IPF filename
self._ipf_filename = os.path.join(config['instrumentDefinition.directory'],
self._instrument_name + '_' + self._analyser + '_' + self._reflection + '_Parameters.xml')
Expand Down
Expand Up @@ -9,62 +9,56 @@ class IndirectResolution(DataProcessorAlgorithm):
def category(self):
return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic'


def summary(self):
return 'Creates a resolution workspace'
return 'Creates a resolution workspace for an indirect inelastic instrument.'


def PyInit(self):
self.declareProperty(StringArrayProperty(name='InputFiles'),
doc='Comma seperated list if input files')

self.declareProperty(WorkspaceProperty('OutputWorkspace', '',
optional=PropertyMode.Optional,
direction=Direction.Output),
doc='Output resolution workspace (if left blank a name will be gernerated automatically)')
doc='Comma seperated list of input files.')

self.declareProperty(name='Instrument', defaultValue='',
validator=StringListValidator(['IRIS', 'OSIRIS', 'TOSCA']),
doc='Instrument used during run')
doc='Instrument used during run.')
self.declareProperty(name='Analyser', defaultValue='',
validator=StringListValidator(['graphite', 'mica', 'fmica']),
doc='Analyser used during run')
doc='Analyser used during run.')
self.declareProperty(name='Reflection', defaultValue='',
validator=StringListValidator(['002', '004', '006']),
doc='Reflection used during run')
doc='Reflection used during run.')

self.declareProperty(IntArrayProperty(name='DetectorRange', values=[0, 1]),
doc='Range of detetcors to use in resolution calculation')
doc='Range of detetcors to use in resolution calculation.')
self.declareProperty(FloatArrayProperty(name='BackgroundRange', values=[0.0, 0.0]),
doc='Energy range to use as background')
doc='Energy range to use as background.')

self.declareProperty(name='RebinParam', defaultValue='', doc='Rebinning parameters (min,width,max)')
self.declareProperty(name='ScaleFactor', defaultValue=1.0, doc='Factor to scale resolution curve by')
self.declareProperty(name='Smooth', defaultValue=False, doc='Apply WienerSmooth to resolution')
self.declareProperty(name='RebinParam', defaultValue='', doc='Rebinning parameters.')
self.declareProperty(name='ScaleFactor', defaultValue=1.0, doc='Factor to scale resolution curve by.')
self.declareProperty(name='Smooth', defaultValue=False, doc='Apply WienerSmooth to resolution.')

self.declareProperty(name='Verbose', defaultValue=False, doc='Print more information to results log')
self.declareProperty(name='Plot', defaultValue=False, doc='Plot resolution curve')
self.declareProperty(name='Save', defaultValue=False, doc='Save resolution workspace as a Nexus file')
self.declareProperty(name='Verbose', defaultValue=False, doc='Print more information to results log.')
self.declareProperty(name='Plot', defaultValue=False, doc='Plot resolution curve.')
self.declareProperty(name='Save', defaultValue=False, doc='Save resolution workspace as a Nexus file.')

self.declareProperty(WorkspaceProperty('OutputWorkspace', '',
direction=Direction.Output),
doc='Output resolution workspace.')

def PyExec(self):
from IndirectCommon import StartTime, EndTime, getWSprefix
import inelastic_indirect_reducer

StartTime('IndirectResolution')
def PyExec(self):
self._setup()

InelasticIndirectReduction(Instrument=self._instrument,
ISISIndirectEnergyTransfer(Instrument=self._instrument,
Analyser=self._analyser,
Reflection=self._reflection,
Grouping='All',
GroupingMethod='All',
SumFiles=True,
InputFiles=self._input_files,
DetectorRange=self._detector_range,
OutputWorkspace='__icon_ws_group')
SpectraRange=self._detector_range,
OutputWorkspace='__et_ws_group')

icon_ws = mtd['__icon_ws_group'].getItem(0).getName()

if self._out_ws == "":
self._out_ws = getWSprefix(icon_ws) + 'res'
icon_ws = mtd['__et_ws_group'].getItem(0).getName()

if self._scale_factor != 1.0:
Scale(InputWorkspace=icon_ws, OutputWorkspace=icon_ws, Factor=self._scale_factor)
Expand All @@ -83,8 +77,6 @@ def PyExec(self):
self._post_process()
self.setProperty('OutputWorkspace', self._out_ws)

EndTime('IndirectResolution')


def _setup(self):
"""
Expand Down
Expand Up @@ -207,7 +207,7 @@ namespace CustomInterfaces
QString scale = m_uiForm.cal_leIntensityScaleMultiplier->text();
if(scale.isEmpty())
scale = "1.0";
calibrationAlg->setProperty("ScaleFactor", scale.toStdString());
calibrationAlg->setProperty("ScaleFactor", scale.toDouble());
}

m_batchAlgoRunner->addAlgorithm(calibrationAlg);
Expand Down Expand Up @@ -259,12 +259,19 @@ namespace CustomInterfaces
resAlg->setProperty("RebinParam", rebinString.toStdString());
resAlg->setProperty("DetectorRange", resDetectorRange.toStdString());
resAlg->setProperty("BackgroundRange", background.toStdString());
resAlg->setProperty("ScaleFactor", m_uiForm.cal_leIntensityScaleMultiplier->text().toDouble());
resAlg->setProperty("Smooth", m_uiForm.cal_ckSmooth->isChecked());
resAlg->setProperty("Verbose", m_uiForm.cal_ckVerbose->isChecked());
resAlg->setProperty("Plot", m_uiForm.cal_ckPlotResult->isChecked());
resAlg->setProperty("Save", m_uiForm.cal_ckSave->isChecked());

if(m_uiForm.cal_ckResScale->isChecked())
{
QString scale = m_uiForm.cal_leResScale->text();
if(scale.isEmpty())
scale = "1.0";
resAlg->setProperty("ScaleFactor", scale.toDouble());
}

m_batchAlgoRunner->addAlgorithm(resAlg);

// When creating resolution file take the resolution workspace as the result
Expand Down

0 comments on commit 72373bf

Please sign in to comment.