diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectCalibration.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectCalibration.py index e0b2ddb9cf82e0e26278a0310464c70db097232f..339b87bcf750e4d16cc05d3d57f8e904f0504a51 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectCalibration.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectCalibration.py @@ -1,4 +1,4 @@ -#pylint: disable=no-init +#pylint: disable=no-init,too-many-instance-attributes from mantid.kernel import * from mantid.api import * from mantid.simpleapi import * @@ -15,6 +15,7 @@ class IndirectCalibration(DataProcessorAlgorithm): _spec_range = None _intensity_scale = None _plot = None + _run_numbers = None def category(self): @@ -29,16 +30,19 @@ class IndirectCalibration(DataProcessorAlgorithm): self.declareProperty(StringArrayProperty(name='InputFiles'), doc='Comma separated list of input files') - self.declareProperty(IntArrayProperty(name='DetectorRange', values=[0, 1],\ - validator=IntArrayMandatoryValidator()), + self.declareProperty(IntArrayProperty(name='DetectorRange', + values=[0, 1], + validator=IntArrayMandatoryValidator()), doc='Range of detectors.') - self.declareProperty(FloatArrayProperty(name='PeakRange', values=[0.0, 100.0],\ - validator=FloatArrayMandatoryValidator()), + self.declareProperty(FloatArrayProperty(name='PeakRange', + values=[0.0, 100.0], + validator=FloatArrayMandatoryValidator()), doc='Time of flight range over the peak.') - self.declareProperty(FloatArrayProperty(name='BackgroundRange', values=[0.0, 1000.0],\ - validator=FloatArrayMandatoryValidator()), + self.declareProperty(FloatArrayProperty(name='BackgroundRange', + values=[0.0, 1000.0], + validator=FloatArrayMandatoryValidator()), doc='Time of flight range over the background.') self.declareProperty(name='ScaleFactor', defaultValue=1.0, @@ -48,11 +52,10 @@ class IndirectCalibration(DataProcessorAlgorithm): doc='Plot the calibration data as a spectra plot.') self.declareProperty(WorkspaceProperty('OutputWorkspace', '', - direction=Direction.Output), + direction=Direction.Output), doc='Output workspace for calibration data.') - def validateInputs(self): """ Validates input ranges. @@ -86,58 +89,82 @@ class IndirectCalibration(DataProcessorAlgorithm): def PyExec(self): from mantid import logger + from IndirectCommon import getInstrRun self._setup() runs = [] + self._run_numbers = list() for in_file in self._input_files: (_, filename) = os.path.split(in_file) (root, _) = os.path.splitext(filename) try: - Load(Filename=in_file, OutputWorkspace=root,\ - SpectrumMin=int(self._spec_range[0]), SpectrumMax=int(self._spec_range[1]),\ - LoadLogFiles=False) + Load(Filename=in_file, + OutputWorkspace=root, + SpectrumMin=int(self._spec_range[0]), + SpectrumMax=int(self._spec_range[1]), + LoadLogFiles=False) + runs.append(root) + self._run_numbers.append(str(getInstrRun(root)[1])) + except Exception as exc: logger.error('Could not load raw file "%s": %s' % (in_file, str(exc))) calib_ws_name = 'calibration' if len(runs) > 1: - MergeRuns(InputWorkspaces=",".join(runs), OutputWorkspace=calib_ws_name) + MergeRuns(InputWorkspaces=",".join(runs), + OutputWorkspace=calib_ws_name) factor = 1.0 / len(runs) - Scale(InputWorkspace=calib_ws_name, OutputWorkspace=calib_ws_name, Factor=factor) + Scale(InputWorkspace=calib_ws_name, + OutputWorkspace=calib_ws_name, + Factor=factor) else: calib_ws_name = runs[0] - CalculateFlatBackground(InputWorkspace=calib_ws_name, OutputWorkspace=calib_ws_name, - StartX=self._back_range[0], EndX=self._back_range[1], Mode='Mean') + CalculateFlatBackground(InputWorkspace=calib_ws_name, + OutputWorkspace=calib_ws_name, + StartX=self._back_range[0], + EndX=self._back_range[1], + Mode='Mean') number_historgrams = mtd[calib_ws_name].getNumberHistograms() - ws_mask, num_zero_spectra = FindDetectorsOutsideLimits(InputWorkspace=calib_ws_name, OutputWorkspace='__temp_ws_mask') + ws_mask, num_zero_spectra = FindDetectorsOutsideLimits(InputWorkspace=calib_ws_name, + OutputWorkspace='__temp_ws_mask') DeleteWorkspace(ws_mask) - Integration(InputWorkspace=calib_ws_name, OutputWorkspace=calib_ws_name, - RangeLower=self._peak_range[0], RangeUpper=self._peak_range[1]) + Integration(InputWorkspace=calib_ws_name, + OutputWorkspace=calib_ws_name, + RangeLower=self._peak_range[0], + RangeUpper=self._peak_range[1]) - temp_sum = SumSpectra(InputWorkspace=calib_ws_name, OutputWorkspace='__temp_sum') + temp_sum = SumSpectra(InputWorkspace=calib_ws_name, + OutputWorkspace='__temp_sum') total = temp_sum.readY(0)[0] DeleteWorkspace(temp_sum) if self._intensity_scale is None: self._intensity_scale = 1 / (total / (number_historgrams - num_zero_spectra)) - Scale(InputWorkspace=calib_ws_name, OutputWorkspace=calib_ws_name, - Factor=self._intensity_scale, Operation='Multiply') + Scale(InputWorkspace=calib_ws_name, + OutputWorkspace=calib_ws_name, + Factor=self._intensity_scale, + Operation='Multiply') - RenameWorkspace(InputWorkspace=calib_ws_name, OutputWorkspace=self._out_ws) + RenameWorkspace(InputWorkspace=calib_ws_name, + OutputWorkspace=self._out_ws) # Remove old workspaces if len(runs) > 1: for run in runs: DeleteWorkspace(Workspace=run) + self._add_logs() self.setProperty('OutputWorkspace', self._out_ws) - self._post_process() + + if self._plot: + from mantidplot import plotBin + plotBin(mtd[self._out_ws], 0) def _setup(self): @@ -159,22 +186,26 @@ class IndirectCalibration(DataProcessorAlgorithm): self._plot = self.getProperty('Plot').value - def _post_process(self): + def _add_logs(self): """ - Handles adding logs and plotting. + Handles adding sample logs. """ # Add sample logs to output workspace + sample_logs = [ + ('calib_peak_min', self._peak_range[0]), + ('calib_peak_max', self._peak_range[1]), + ('calib_back_min', self._back_range[0]), + ('calib_back_max', self._back_range[1]), + ('calib_run_numbers', ','.join(self._run_numbers)) + ] + if self._intensity_scale is not None: - AddSampleLog(Workspace=self._out_ws, LogName='Scale Factor', LogType='Number', LogText=str(self._intensity_scale)) - AddSampleLog(Workspace=self._out_ws, LogName='Peak Min', LogType='Number', LogText=str(self._peak_range[0])) - AddSampleLog(Workspace=self._out_ws, LogName='Peak Max', LogType='Number', LogText=str(self._peak_range[1])) - AddSampleLog(Workspace=self._out_ws, LogName='Back Min', LogType='Number', LogText=str(self._back_range[0])) - AddSampleLog(Workspace=self._out_ws, LogName='Back Max', LogType='Number', LogText=str(self._back_range[1])) + sample_logs.append(('calib_scale_factor', self._intensity_scale)) - if self._plot: - from mantidplot import plotBin - plotBin(mtd[self._out_ws], 0) + AddSampleLogMultiple(Workspace=self._out_ws, + LogNames=[log[0] for log in sample_logs], + LogValues=[log[1] for log in sample_logs]) # Register algorithm with Mantid diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectResolution.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectResolution.py index 4e44f558bbffd3a82cbdae85be954ca21d09d833..7da278f60e8da69ef5ddd3b7c8609f5c1a8599cb 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectResolution.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectResolution.py @@ -19,6 +19,7 @@ class IndirectResolution(DataProcessorAlgorithm): _plot = None _save = None + def category(self): return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic' @@ -61,8 +62,10 @@ class IndirectResolution(DataProcessorAlgorithm): direction=Direction.Output), doc='Output resolution workspace.') + def PyExec(self): from IndirectCommon import getWSprefix + self._setup() ISISIndirectEnergyTransfer(Instrument=self._instrument, @@ -77,13 +80,20 @@ class IndirectResolution(DataProcessorAlgorithm): 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) + Scale(InputWorkspace=icon_ws, + OutputWorkspace=icon_ws, + Factor=self._scale_factor) - CalculateFlatBackground(InputWorkspace=icon_ws, OutputWorkspace=self._out_ws, - StartX=self._background[0], EndX=self._background[1], - Mode='Mean', OutputMode='Subtract Background') + CalculateFlatBackground(InputWorkspace=icon_ws, + OutputWorkspace=self._out_ws, + StartX=self._background[0], + EndX=self._background[1], + Mode='Mean', + OutputMode='Subtract Background') - Rebin(InputWorkspace=self._out_ws, OutputWorkspace=self._out_ws, Params=self._rebin_string) + Rebin(InputWorkspace=self._out_ws, + OutputWorkspace=self._out_ws, + Params=self._rebin_string) self._post_process() self.setProperty('OutputWorkspace', self._out_ws) @@ -115,31 +125,27 @@ class IndirectResolution(DataProcessorAlgorithm): Handles adding logs, saving and plotting. """ - use_scale_factor = self._scale_factor == 1.0 - AddSampleLog(Workspace=self._out_ws, LogName='scale', - LogType='String', LogText=str(use_scale_factor)) - if use_scale_factor: - AddSampleLog(Workspace=self._out_ws, LogName='scale_factor', - LogType='Number', LogText=str(self._scale_factor)) + sample_logs = [ + ('res_back_start', self._background[0]), + ('res_back_end', self._background[1]) + ] - AddSampleLog(Workspace=self._out_ws, LogName='back_start', - LogType='Number', LogText=str(self._background[0])) - AddSampleLog(Workspace=self._out_ws, LogName='back_end', - LogType='Number', LogText=str(self._background[1])) + if self._scale_factor != 1.0: + sample_logs.append(('res_scale_factor', self._scale_factor)) rebin_params = self._rebin_string.split(',') if len(rebin_params) == 3: - AddSampleLog(Workspace=self._out_ws, LogName='rebin_low', - LogType='Number', LogText=rebin_params[0]) - AddSampleLog(Workspace=self._out_ws, LogName='rebin_width', - LogType='Number', LogText=rebin_params[1]) - AddSampleLog(Workspace=self._out_ws, LogName='rebin_high', - LogType='Number', LogText=rebin_params[2]) + sample_logs.append(('rebin_low', rebin_params[0])) + sample_logs.append(('rebin_width', rebin_params[1])) + sample_logs.append(('rebin_high', rebin_params[2])) + + AddSampleLogMultiple(Workspace=self._out_ws, + LogNames=[log[0] for log in sample_logs], + LogValues=[log[1] for log in sample_logs]) self.setProperty('OutputWorkspace', self._out_ws) if self._save: - logger.information("Resolution file saved to default save directory.") SaveNexusProcessed(InputWorkspace=self._out_ws, Filename=self._out_ws + '.nxs') if self._plot: diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp index d2535faf70719ea4ee848164266af16363e54fb2..d1ad9e91dd2a6b0b0f09f76ae665f749c4ef269a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp @@ -156,7 +156,8 @@ namespace CustomInterfaces { // Get properties QString firstFile = m_uiForm.leRunNo->getFirstFilename(); - QString filenames = m_uiForm.leRunNo->getFilenames().join(","); + QStringList filenameList = m_uiForm.leRunNo->getFilenames(); + QString filenames = filenameList.join(","); auto instDetails = getInstrumentDetails(); QString instDetectorRange = instDetails["spectra-min"] + "," + instDetails["spectra-max"]; @@ -168,7 +169,10 @@ namespace CustomInterfaces QString outputWorkspaceNameStem = firstFileInfo.baseName() + "_" + getInstrumentConfiguration()->getAnalyserName() + getInstrumentConfiguration()->getReflectionName(); - QString calibrationWsName = outputWorkspaceNameStem + "_calib"; + QString calibrationWsName = outputWorkspaceNameStem; + if(filenameList.size() > 1) + calibrationWsName += "_multi"; + calibrationWsName += "_calib"; // Configure the calibration algorithm IAlgorithm_sptr calibrationAlg = AlgorithmManager::Instance().create("IndirectCalibration"); @@ -209,7 +213,10 @@ namespace CustomInterfaces // Configure the resolution algorithm if(m_uiForm.ckCreateResolution->isChecked()) { - QString resolutionWsName = outputWorkspaceNameStem + "_res"; + QString resolutionWsName = outputWorkspaceNameStem; + if(filenameList.size() > 1) + resolutionWsName += "_multi"; + resolutionWsName += "_res"; QString resDetectorRange = QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + "," + QString::number(m_dblManager->value(m_properties["ResSpecMax"]));