From b27e60285f5dee8b1e208a34226e5f91c0440148 Mon Sep 17 00:00:00 2001
From: Dan Nixon <dan@dan-nixon.com>
Date: Wed, 18 Mar 2015 13:55:01 +0000
Subject: [PATCH] Passes unit, doc and some system tests

Refs #10854
---
 .../InelasticIndirectReduction.py             | 251 ------------------
 .../src/Indirect/ISISCalibration.cpp          |   4 +-
 .../src/Indirect/ISISEnergyTransfer.cpp       |   2 +-
 .../analysis/IndirectEnergyConversionTest.py  |  10 +-
 .../CreateCalibrationWorkspace-v1.rst         |  17 +-
 .../ISISIndirectEnergyTransfer-v1.rst         |  14 +-
 6 files changed, 19 insertions(+), 279 deletions(-)
 delete mode 100644 Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InelasticIndirectReduction.py

diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InelasticIndirectReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InelasticIndirectReduction.py
deleted file mode 100644
index aee835a8773..00000000000
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/InelasticIndirectReduction.py
+++ /dev/null
@@ -1,251 +0,0 @@
-#pylint: disable=no-init
-from mantid.kernel import *
-from mantid.api import *
-from mantid.simpleapi import *
-
-
-class InelasticIndirectReduction(DataProcessorAlgorithm):
-
-    _out_ws_group = None
-    _data_files = None
-    _instrument = None
-    _analyser = None
-    _reflection = None
-    _param_file = None
-    _detector_range = None
-    _background_range = None
-    _calib_ws_name = None
-    _detailed_balance = None
-    _rebin_string = None
-    _scale_factor = None
-    _sum_files = None
-    _map_file = None
-    _save_formats = None
-    _plot_type = None
-    _use_calib_ws = None
-    _use_detailed_balance = None
-    _use_scale_factor = None
-    _plot_ws = None
-
-    def category(self):
-        return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic'
-
-
-    def summary(self):
-        return 'Runs a reduction for an inelastic indirect geometry instrument.'
-
-
-    def PyInit(self):
-        self.declareProperty(StringArrayProperty(name='InputFiles'),
-                             doc='Comma separated list of input files')
-
-        self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '',\
-                             direction=Direction.Output),
-                             doc='Workspace group for the resulting workspaces')
-
-        self.declareProperty(name='SumFiles', defaultValue=False, doc='Toggle input file summing or sequential processing')
-        self.declareProperty(name='LoadLogs', defaultValue=False, doc='Load sample logs from input files')
-
-        self.declareProperty(name='Instrument', defaultValue='', doc='Instrument used during run',
-                             validator=StringListValidator(['IRIS', 'OSIRIS', 'TOSCA', 'TFXA', 'BASIS', 'VISION']))
-        self.declareProperty(name='Analyser', defaultValue='', doc='Analyser used during run',
-                             validator=StringListValidator(['graphite', 'mica', 'fmica', 'silicon']))
-        self.declareProperty(name='Reflection', defaultValue='', doc='Reflection used during run',
-                             validator=StringListValidator(['002', '004', '006', '111']))
-
-        self.declareProperty(WorkspaceProperty('CalibrationWorkspace', '',\
-                             direction=Direction.Input, optional=PropertyMode.Optional), doc='Workspace contining calibration data')
-
-        self.declareProperty(IntArrayProperty(name='DetectorRange', values=[0, 1],\
-                             validator=IntArrayMandatoryValidator()),
-                             doc='Comma separated range of detectors to use')
-        self.declareProperty(FloatArrayProperty(name='BackgroundRange'),
-                             doc='')
-
-        self.declareProperty(name='RebinString', defaultValue='', doc='Rebin string parameters')
-        self.declareProperty(name='DetailedBalance', defaultValue=-1.0, doc='')
-        self.declareProperty(name='ScaleFactor', defaultValue=1.0, doc='')
-        self.declareProperty(name='Grouping', defaultValue='',
-                             doc='Method used to group spectra, can be either: Individual, All, a .map filename or a group workspace name')
-        self.declareProperty(name='Fold', defaultValue=False, doc='')
-        self.declareProperty(name='SaveCM1', defaultValue=False, doc='')
-        self.declareProperty(StringArrayProperty(name='SaveFormats'), doc='Comma separated list of save formats')
-
-        self.declareProperty(name='Plot', defaultValue='none', doc='Type of plot to output after reduction',
-                             validator=StringListValidator(['none', 'spectra', 'contour']))
-
-
-    def PyExec(self):
-        from mantid import config, logger
-        from IndirectCommon import StartTime, EndTime
-        import inelastic_indirect_reducer
-
-        self._setup()
-
-        StartTime('InelasticIndirectReduction')
-
-        # Setup reducer
-        reducer = inelastic_indirect_reducer.IndirectReducer()
-
-        reducer.set_rename(True)
-
-        reducer.set_instrument_name(self._instrument)
-        reducer.set_parameter_file(self._param_file)
-        try:
-            reducer.set_output_path(config["defaultsave.directory"])
-        except RuntimeError:
-            pass # Use default
-
-        for data_file in self._data_files:
-            reducer.append_data_file(data_file)
-
-        reducer.set_sum_files(self._sum_files)
-
-        reducer.set_detector_range(int(self._detector_range[0]) - 1, int(self._detector_range[1]) - 1)
-
-        self._use_calib_ws = self._calib_ws_name != ''
-        if self._use_calib_ws:
-            logger.information('Using calibration workspace: %s' % self._calib_ws_name)
-            reducer.set_calibration_workspace(self._calib_ws_name)
-
-        if len(self._background_range) == 2:
-            logger.debug('Using background range: ' + str(self._background_range))
-            reducer.set_background(float(self._background_range[0]), float(self._background_range[1]))
-
-        # TODO: There should be a better way to do this
-        self._use_detailed_balance = self._detailed_balance != -1.0
-        if self._use_detailed_balance:
-            logger.debug('Using detailed balance: ' + str(self._detailed_balance))
-            reducer.set_detailed_balance(self._detailed_balance)
-
-        if self._rebin_string != '':
-            logger.debug('Using rebin string: ' + self._rebin_string)
-            reducer.set_rebin_string(self._rebin_string)
-
-        self._use_scale_factor = self._scale_factor != 1.0
-        if self._use_scale_factor:
-            logger.debug('Using scale factor: ' + str(self._scale_factor))
-            reducer.set_scale_factor(self._scale_factor)
-
-        if self._map_file != '':
-            logger.debug('Using mapping file: ' + str(self._map_file))
-            reducer.set_grouping_policy(self._map_file)
-
-        reducer.set_fold_multiple_frames(self.getProperty('Fold').value)
-        reducer.set_save_to_cm_1(self.getProperty('SaveCM1').value)
-        reducer.set_save_formats(self._save_formats)
-
-        # Do reduction and get result workspaces
-        reducer.reduce()
-        ws_list = reducer.get_result_workspaces()
-
-        self._plot_ws = ws_list[0]
-
-        if len(ws_list) < 1:
-            logger.error('Failed to complete reduction')
-            return
-
-        # Add sample logs to output workspace(s)
-        for workspace in ws_list:
-            self._add_ws_logs(workspace)
-
-        # Group output workspaces
-        GroupWorkspaces(InputWorkspaces=ws_list, OutputWorkspace=self._out_ws_group)
-        self.setProperty('OutputWorkspace', self._out_ws_group)
-
-        # Do plotting
-        if self._plot_type != 'none':
-            self._plot()
-
-        EndTime('InelasticIndirectReduction')
-
-
-    def validateInputs(self):
-        """
-        Validates algorithm properties.
-        """
-        issues = dict()
-
-        # Validate save format string
-        save_formats = self.getProperty('SaveFormats').value
-        valid_formats = ['nxs', 'spe', 'nxspe', 'ascii', 'aclimax', 'davegrp']
-        invalid_formats = list()
-        for save_format in save_formats:
-            if save_format not in valid_formats:
-                invalid_formats.append(save_format)
-        if len(invalid_formats) > 0:
-            issues['SaveFormats'] = 'The following save formats are not valid: ' + ','.join(invalid_formats)
-
-        return issues
-
-
-    def _setup(self):
-        """
-        Gets and algorithm properties.
-        """
-
-        # Get parameter values
-        self._out_ws_group = self.getPropertyValue('OutputWorkspace')
-        self._data_files = self.getProperty('InputFiles').value
-
-        self._instrument = self.getPropertyValue('Instrument')
-        self._analyser = self.getPropertyValue('Analyser')
-        self._reflection = self.getPropertyValue('Reflection')
-
-        self._param_file = config['instrumentDefinition.directory'] + self._instrument + '_' + self._analyser + '_' + self._reflection + '_Parameters.xml'
-
-        self._detector_range = self.getProperty('DetectorRange').value
-        self._background_range = self.getProperty('BackgroundRange').value
-
-        self._calib_ws_name = self.getPropertyValue('CalibrationWorkspace')
-
-        self._detailed_balance = self.getProperty('DetailedBalance').value
-        self._rebin_string = self.getPropertyValue('RebinString')
-        self._scale_factor = self.getProperty('ScaleFactor').value
-        self._sum_files = self.getProperty('SumFiles').value
-
-        self._map_file = self.getPropertyValue('Grouping')
-
-        self._save_formats = self.getProperty('SaveFormats').value
-        self._plot_type = self.getPropertyValue('Plot')
-
-
-    def _add_ws_logs(self, workspace_name):
-        """
-        Adds sample logs to a given output workspace.
-        """
-
-        AddSampleLog(Workspace=workspace_name, LogName='use_calib_wokspace', LogType='String', LogText=str(self._use_calib_ws))
-        if self._use_calib_ws:
-            AddSampleLog(Workspace=workspace_name, LogName='calib_workspace_name', LogType='String', LogText=str(self._calib_ws_name))
-
-        AddSampleLog(Workspace=workspace_name, LogName='use_detailed_balance', LogType='String', LogText=str(self._use_detailed_balance))
-        if self._use_detailed_balance:
-            AddSampleLog(Workspace=workspace_name, LogName='detailed_balance', LogType='Number', LogText=str(self._detailed_balance))
-
-        AddSampleLog(Workspace=workspace_name, LogName='use_scale_factor', LogType='String', LogText=str(self._use_scale_factor))
-        if self._use_scale_factor:
-            AddSampleLog(Workspace=workspace_name, LogName='scale_factor', LogType='Number', LogText=str(self._scale_factor))
-
-
-    def _plot(self):
-        """
-        Plots results.
-        """
-
-        if self._plot_type == 'spectra':
-            from mantidplot import plotSpectrum
-            num_spectra = mtd[self._plot_ws].getNumberHistograms()
-            try:
-                plotSpectrum(self._plot_ws, range(0, num_spectra))
-            except RuntimeError:
-                logger.notice('Spectrum plotting canceled by user')
-
-        if self._plot_type == 'contour':
-            from mantidplot import importMatrixWorkspace
-            plot_workspace = importMatrixWorkspace(self._plot_ws)
-            plot_workspace.plotGraph2D()
-
-
-# Register algorithm with Mantid
-AlgorithmFactory.subscribe(InelasticIndirectReduction)
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp
index 058459d8cc9..18639f33ad3 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp
@@ -423,14 +423,14 @@ namespace CustomInterfaces
     QString detRange = QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + ","
                      + QString::number(m_dblManager->value(m_properties["ResSpecMax"]));
 
-    IAlgorithm_sptr reductionAlg = AlgorithmManager::Instance().create("InelasticIndirectReduction");
+    IAlgorithm_sptr reductionAlg = AlgorithmManager::Instance().create("ISISIndirectEnergyTransfer");
     reductionAlg->initialize();
     reductionAlg->setProperty("Instrument", getInstrumentConfiguration()->getInstrumentName().toStdString());
     reductionAlg->setProperty("Analyser", getInstrumentConfiguration()->getAnalyserName().toStdString());
     reductionAlg->setProperty("Reflection", getInstrumentConfiguration()->getReflectionName().toStdString());
     reductionAlg->setProperty("InputFiles", files.toStdString());
     reductionAlg->setProperty("OutputWorkspace", "__IndirectCalibration_reduction");
-    reductionAlg->setProperty("DetectorRange", detRange.toStdString());
+    reductionAlg->setProperty("SpectraRange", detRange.toStdString());
     reductionAlg->execute();
 
     if(!reductionAlg->isExecuted())
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp
index bdb8ce5eb36..d8eba02b130 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp
@@ -348,7 +348,7 @@ namespace CustomInterfaces
 
   /**
    * Converts the checkbox selection to a comma delimited list of save formats for the
-   * InelasticIndirectReduction algorithm.
+   * ISISIndirectEnergyTransfer algorithm.
    *
    * @return A vector of save formats
    */
diff --git a/Code/Mantid/Testing/SystemTests/tests/analysis/IndirectEnergyConversionTest.py b/Code/Mantid/Testing/SystemTests/tests/analysis/IndirectEnergyConversionTest.py
index b213a4662ea..b683bf46ee8 100644
--- a/Code/Mantid/Testing/SystemTests/tests/analysis/IndirectEnergyConversionTest.py
+++ b/Code/Mantid/Testing/SystemTests/tests/analysis/IndirectEnergyConversionTest.py
@@ -12,16 +12,16 @@ class IndirectEnergyConversionTest(stresstesting.MantidStressTest):
         files = 'irs21360.raw'
         rebin_string = '-0.5,0.005,0.5'
 
-        InelasticIndirectReduction(InputFiles=files,
-                                   RebiNString=rebin_string,
-                                   DetectorRange=detector_range,
+        ISISIndirectEnergyTransfer(InputFiles=files,
+                                   RebinString=rebin_string,
+                                   SpectraRange=detector_range,
                                    Instrument=instrument,
                                    Analyser=analyser,
                                    Reflection=reflection,
-                                   OutputWorkspace='__IndirectEnergyCOnversionTest_out_group')
+                                   OutputWorkspace='__IndirectEnergyConversionTest_out_group')
 
 
     def validate(self):
         self.disableChecking.append('Instrument')
         self.disableChecking.append('SpectraMap')
-        return 'irs21360_graphite002_red', 'IndirectEnergyConversionTest.nxs'
+        return 'IRS21360_graphite002_red', 'IndirectEnergyConversionTest.nxs'
diff --git a/Code/Mantid/docs/source/algorithms/CreateCalibrationWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/CreateCalibrationWorkspace-v1.rst
index a4e5a0fe2af..a4ee6cace48 100644
--- a/Code/Mantid/docs/source/algorithms/CreateCalibrationWorkspace-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/CreateCalibrationWorkspace-v1.rst
@@ -21,29 +21,20 @@ Usage
 
 .. testcode:: ExCreateCalibrationWorkspaceSimple
 
-   import os
-
    # Create a calibration workspace
    cal_ws = CreateCalibrationWorkspace(InputFiles='IRS26173.raw',
                                        DetectorRange='3,53',
                                        PeakRange='62500,65000',
                                        BackgroundRange='59000,61500')
 
-   # Save the workspace to a NeXus file
-   calib_file = 'iris_calibration.nxs'
-   SaveNexus(InputWorkspace=cal_ws, Filename=calib_file)
-
-   # Check the output file
-   print "File Exists:", os.path.exists(calib_file)
+   print 'Number of spectra: %d' % cal_ws.getNumberHistograms()
+   print 'Number of bins: %d' % cal_ws.blocksize()
 
 Output:
 
 .. testoutput:: ExCreateCalibrationWorkspaceSimple
 
-   File Exists: True
-
-.. testcleanup:: ExCreateCalibrationWorkspaceSimple
-
-   os.remove(calib_file)
+   Number of spectra: 51
+   Number of bins: 1
 
 .. categories::
diff --git a/Code/Mantid/docs/source/algorithms/ISISIndirectEnergyTransfer-v1.rst b/Code/Mantid/docs/source/algorithms/ISISIndirectEnergyTransfer-v1.rst
index 929274cc735..5f295ba1884 100644
--- a/Code/Mantid/docs/source/algorithms/ISISIndirectEnergyTransfer-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/ISISIndirectEnergyTransfer-v1.rst
@@ -21,12 +21,12 @@ Usage
 
 .. testcode:: ExIRISReduction
 
-   InelasticIndirectReduction(InputFiles='IRS21360.raw',
-      OutputWorkspace='IndirectReductions',
-      Instrument='IRIS',
-      Analyser='graphite',
-      Reflection='002',
-      SpectraRange=[3, 53])
+   ISISIndirectEnergyTransfer(InputFiles='IRS21360.raw',
+                              OutputWorkspace='IndirectReductions',
+                              Instrument='IRIS',
+                              Analyser='graphite',
+                              Reflection='002',
+                              SpectraRange=[3, 53])
 
    reduction_workspace_names = mtd['IndirectReductions'].getNames()
 
@@ -37,6 +37,6 @@ Output:
 
 .. testoutput:: ExIRISReduction
 
-   irs21360_graphite002_red
+   IRS21360_graphite002_red
 
 .. categories::
-- 
GitLab