From bbe37ec11c3b123d378bf59812acdb1ac5010b35 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Mon, 12 Jan 2015 16:47:30 +0000 Subject: [PATCH] Removed old reduction scripts, switch UI to new algo Need to add saving Refs #10855 --- .../ISISIndirectDiffractionReduction.py | 12 +- .../MSGDiffractionReduction.py | 127 ------------------ .../src/IndirectDiffractionReduction.cpp | 18 +-- .../Inelastic/IndirectDiffractionReduction.py | 72 ---------- 4 files changed, 17 insertions(+), 212 deletions(-) delete mode 100644 Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MSGDiffractionReduction.py delete mode 100644 Code/Mantid/scripts/Inelastic/IndirectDiffractionReduction.py diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py index 065416598db0..f4e38a3fc0c8 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ISISIndirectDiffractionReduction.py @@ -3,7 +3,7 @@ from mantid.kernel import * from mantid import config -import os.path as path +import os class ISISIndirectDiffractionReduction(DataProcessorAlgorithm): @@ -133,6 +133,8 @@ def _setup(self): # Get the IPF filename self._ipf_filename = self._instrument_name + '_diffraction_' + self._mode + '_Parameters.xml' + if not os.path.exists(self._ipf_filename): + self._ipf_filename = os.path.join(config['instrumentDefinition.directory'], self._ipf_filename) logger.information('IPF filename is: %s' % (self._ipf_filename)) # Only enable sum files if we actually have more than one file @@ -159,7 +161,7 @@ def _load_files(self): for filename in self._raw_file_list: # The filename without path and extension will be the workspace name - ws_name = path.splitext(path.basename(filename))[0] + ws_name = os.path.splitext(os.path.basename(filename))[0] logger.debug('Loading file %s as workspace %s' % (filename, ws_name)) @@ -415,11 +417,11 @@ def _group_spectra(self, ws_name, masked_detectors): raise RuntimeError('IPF requests grouping using file but does not specify a filename') # If the file is not found assume it is in the grouping files directory - if not path.isfile(grouping_file): - grouping_file = path.join(config.getString('groupingFiles.directory'), grouping_file) + if not os.path.isfile(grouping_file): + grouping_file = os.path.join(config.getString('groupingFiles.directory'), grouping_file) # If it is still not found just give up - if not path.isfile(grouping_file): + if not os.path.isfile(grouping_file): raise RuntimeError('Cannot find grouping file %s' % grouping_file) # Mask detectors if required diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MSGDiffractionReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MSGDiffractionReduction.py deleted file mode 100644 index 15438f256618..000000000000 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MSGDiffractionReduction.py +++ /dev/null @@ -1,127 +0,0 @@ -from mantid.simpleapi import * -from mantid.api import * -from mantid.kernel import * -from mantid import config - -import os.path, math - - -class MSGDiffractionReduction(PythonAlgorithm): - - def category(self): - return 'Diffraction;PythonAlgorithms' - - - def summary(self): - return 'Calculates the scattering & transmission for Indirect Geometry spectrometers.' - - - def PyInit(self): - self.declareProperty(StringArrayProperty(name='InputFiles'), - doc='Comma separated list of input files.') - - self.declareProperty(name='SumFiles', defaultValue=False, - doc='Enabled to sum spectra from each input file.') - - self.declareProperty(name='IndividualGrouping', defaultValue=False, - doc='Do not group results into a single spectra.') - - self.declareProperty(name='Instrument', defaultValue='IRIS', - validator=StringListValidator(['IRIS', 'OSIRIS', 'TOSCA', 'VESUVIO']), - doc='Instrument used for run') - - self.declareProperty(name='Mode', defaultValue='diffspec', - validator=StringListValidator(['diffspec', 'diffonly']), - doc='Diffraction mode used') - - self.declareProperty(IntArrayProperty(name='DetectorRange'), - doc='Range of detectors to use.') - - self.declareProperty(name='RebinParam', defaultValue='', - doc='Rebin parameters.') - - self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '', - direction=Direction.Output), - doc='Group name for the result workspaces.') - - self.declareProperty(StringArrayProperty(name='SaveFormats'), - doc='Save formats to save output in.') - - - def validateInputs(self): - """ - Checks for issues with user input. - """ - issues = dict() - - # Validate input files - input_files = self.getProperty('InputFiles').value - if len(input_files) == 0: - issues['InputFiles'] = 'InputFiles must contain at least one filename' - - # Validate detector range - detector_range = self.getProperty('DetectorRange').value - if len(detector_range) != 2: - issues['DetectorRange'] = 'DetectorRange must be an array of 2 values only' - else: - if detector_range[0] > detector_range[1]: - issues['DetectorRange'] = 'DetectorRange must be in format [lower_index,upper_index]' - - # Validate save formats - save_formats = self.getProperty('SaveFormats').value - valid_formats = ['gss', 'nxs', 'ascii'] - for s_format in save_formats: - if s_format not in valid_formats: - issues['SaveFormats'] = 'Contains invalid save formats' - break - - return issues - - - def PyExec(self): - from IndirectCommon import StartTime, EndTime - from IndirectDiffractionReduction import MSGDiffractionReducer - - StartTime('MSGDiffractionReduction') - - input_files = self.getProperty('InputFiles').value - sum_files = self.getProperty('SumFiles').value - individual_grouping = self.getProperty('IndividualGrouping').value - instrument_name = self.getPropertyValue('Instrument') - mode = self.getPropertyValue('Mode') - detector_range = self.getProperty('DetectorRange').value - rebin_string = self.getPropertyValue('RebinParam') - output_ws_group = self.getPropertyValue('OutputWorkspace') - save_formats = self.getProperty('SaveFormats').value - - ipf_filename = instrument_name + '_diffraction_' + mode + '_Parameters.xml' - - reducer = MSGDiffractionReducer() - reducer.set_instrument_name(instrument_name) - reducer.set_detector_range(int(detector_range[0] - 1), int(detector_range[1] - 1)) - reducer.set_parameter_file(ipf_filename) - reducer.set_sum_files(sum_files) - reducer.set_save_formats(save_formats) - - if individual_grouping: - reducer.set_grouping_policy('Individual') - - for in_file in input_files: - reducer.append_data_file(in_file) - - if rebin_string != '': - reducer.set_rebin_string(rebin_string) - - if instrument_name == 'VESUVIO': - reducer.append_load_option('Mode', 'FoilOut') - - reducer.reduce() - - result_ws_list = reducer.get_result_workspaces() - GroupWorkspaces(InputWorkspaces=result_ws_list, OutputWorkspace=output_ws_group) - self.setProperty('OutputWorkspace', output_ws_group) - - EndTime('MSGDiffractionReduction') - - -AlgorithmFactory.subscribe(MSGDiffractionReduction) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiffractionReduction.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiffractionReduction.cpp index a62b3a4ad024..03fdf205edfd 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiffractionReduction.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiffractionReduction.cpp @@ -102,7 +102,7 @@ void IndirectDiffractionReduction::plotResults(bool error) return; } - // Ungroup the output workspace if MSGDiffractionReduction was used + // Ungroup the output workspace if generic reducer was used if(AnalysisDataService::Instance().doesExist("IndirectDiffraction_Workspaces")) { WorkspaceGroup_sptr diffResultsGroup = AnalysisDataService::Instance().retrieveWS("IndirectDiffraction_Workspaces"); @@ -153,15 +153,13 @@ void IndirectDiffractionReduction::runGenericReduction(QString instName, QString if(!rebinStart.isEmpty() && !rebinWidth.isEmpty() && !rebinEnd.isEmpty()) rebin = rebinStart + "," + rebinWidth + "," + rebinEnd; - bool individualGrouping = m_uiForm.ckIndividualGrouping->isChecked(); - // Get detector range std::vector detRange; detRange.push_back(m_uiForm.set_leSpecMin->text().toLong()); detRange.push_back(m_uiForm.set_leSpecMax->text().toLong()); - // Get MSGDiffractionReduction algorithm instance - IAlgorithm_sptr msgDiffReduction = AlgorithmManager::Instance().create("MSGDiffractionReduction"); + // Get generic reduction algorithm instance + IAlgorithm_sptr msgDiffReduction = AlgorithmManager::Instance().create("ISISIndirectDiffractionReduction"); msgDiffReduction->initialize(); // Get save formats @@ -175,14 +173,18 @@ void IndirectDiffractionReduction::runGenericReduction(QString instName, QString msgDiffReduction->setProperty("Mode", mode.toStdString()); msgDiffReduction->setProperty("SumFiles", m_uiForm.dem_ckSumFiles->isChecked()); msgDiffReduction->setProperty("InputFiles", m_uiForm.dem_rawFiles->getFilenames().join(",").toStdString()); - msgDiffReduction->setProperty("DetectorRange", detRange); + msgDiffReduction->setProperty("SpectraRange", detRange); msgDiffReduction->setProperty("RebinParam", rebin.toStdString()); - msgDiffReduction->setProperty("IndividualGrouping", individualGrouping); - msgDiffReduction->setProperty("SaveFormats", saveFormats); msgDiffReduction->setProperty("OutputWorkspace", "IndirectDiffraction_Workspaces"); + // Add the pproperty for grouping policy if needed + if(m_uiForm.ckIndividualGrouping->isChecked()) + msgDiffReduction->setProperty("GroupingPolicy", "Individual"); + m_batchAlgoRunner->addAlgorithm(msgDiffReduction); + //TODO: saving + m_batchAlgoRunner->executeBatchAsync(); } diff --git a/Code/Mantid/scripts/Inelastic/IndirectDiffractionReduction.py b/Code/Mantid/scripts/Inelastic/IndirectDiffractionReduction.py deleted file mode 100644 index f41533106ec1..000000000000 --- a/Code/Mantid/scripts/Inelastic/IndirectDiffractionReduction.py +++ /dev/null @@ -1,72 +0,0 @@ -import mantid -from msg_reducer import MSGReducer -import inelastic_indirect_reduction_steps as steps - - -class MSGDiffractionReducer(MSGReducer): - """Reducer for Diffraction on IRIS and TOSCA. - """ - - def __init__(self): - super(MSGDiffractionReducer, self).__init__() - self._grouping_policy = 'All' - - def _setup_steps(self): - self.append_step(steps.IdentifyBadDetectors( - MultipleFrames=self._multiple_frames)) - self.append_step(steps.HandleMonitor( - MultipleFrames=self._multiple_frames)) - self.append_step(steps.CorrectByMonitor( - MultipleFrames=self._multiple_frames, EMode="Elastic")) - - if self._multiple_frames: - if self._fold_multiple_frames: - self.append_step(steps.FoldData()) - else: - return - - step = mantid.AlgorithmManager.create("ConvertUnits") - step.setPropertyValue("Target", "dSpacing") - step.setPropertyValue("EMode", "Elastic") - self.append_step(step) - - if self._rebin_string is not None: - step = mantid.AlgorithmManager.create("Rebin") - step.setPropertyValue("Params", self._rebin_string) - self.append_step(step) - else: - self.append_step(steps.RebinToFirstSpectrum()) - - step = steps.Grouping() - step.set_grouping_policy(self._grouping_policy) - self.append_step(step) - - # The "SaveItem" step saves the files in the requested formats. - if len(self._save_formats) > 0: - step = steps.SaveItem() - step.set_formats(self._save_formats) - self.append_step(step) - - step = steps.Naming() - self.append_step(step) - - def set_grouping_policy(self, policy): - """ - Sets the grouping policy for the result data. - - @parm policy New grouping policy - """ - if not isinstance(policy, str): - raise ValueError('Grouping policy must be a string') - - self._grouping_policy = policy - - -def getStringProperty(workspace, property): - """This function is used in the interface. - """ - inst = mantid.AnalysisDataService[workspace].getInstrument() - try: - prop = inst.getStringParameter(property)[0] - except IndexError: return "" - return prop