diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionMonitor.py similarity index 68% rename from Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionReduction.py rename to Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionMonitor.py index a6cbf4f2af2f..e97e2d2b8c50 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionReduction.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectTransmissionMonitor.py @@ -7,7 +7,7 @@ import os.path -class IndirectTransmissionReduction(PythonAlgorithm): +class IndirectTransmissionMonitor(PythonAlgorithm): def category(self): return "Workflow\\Inelastic;PythonAlgorithms;Inelastic" @@ -16,10 +16,13 @@ def summary(self): return "Calculates the sample transmission using the raw data files of the sample and its background or container." def PyInit(self): - self.declareProperty(FileProperty('SampleFile', '', FileAction.Load, extensions=['raw']), - doc='Raw sample run file') - self.declareProperty(FileProperty('CanFile', '', FileAction.Load, extensions=['raw']), - doc='Raw background or can run file') + self.declareProperty(WorkspaceProperty('SampleWorkspace', '', direction=Direction.Input), + doc='Sample workspace') + self.declareProperty(WorkspaceProperty('CanWorkspace', '', direction=Direction.Input), + doc='Background/can workspace') + + self.declareProperty(WorkspaceProperty('OutputWorkspace', '', direction=Direction.Output, optional=PropertyMode.Optional), + doc='Output workspace group') self.declareProperty(name='Verbose', defaultValue=False, doc='Output more verbose message to log') self.declareProperty(name='Plot', defaultValue=False, doc='Plot result workspace') @@ -27,19 +30,19 @@ def PyInit(self): def PyExec(self): from IndirectCommon import StartTime, EndTime - StartTime('IndirectTransmissionReduction') + StartTime('IndirectTransmissionMonitor') - sample_filepath = self.getProperty("SampleFile").value - can_filepath = self.getProperty("CanFile").value + sample_ws_in = self.getPropertyValue("SampleWorkspace") + can_ws_in = self.getPropertyValue("CanWorkspace") + out_ws = self.getPropertyValue('OutputWorkspace') verbose = self.getProperty("Verbose").value plot = self.getProperty("Plot").value save = self.getProperty("Save").value - sample_filename = os.path.basename(sample_filepath) - ws_basename, _ = os.path.splitext(sample_filename) + ws_basename = str(sample_ws_in) - self.TransMon(ws_basename, 'Sam', sample_filepath, verbose) - self.TransMon(ws_basename, 'Can', can_filepath, verbose) + self.TransMon(ws_basename, 'Sam', sample_ws_in, verbose) + self.TransMon(ws_basename, 'Can', can_ws_in, verbose) # Divide sample and can workspaces sam_ws = ws_basename + '_Sam' @@ -49,9 +52,13 @@ def PyExec(self): trans = numpy.average(mtd[tr_ws].readY(0)) # Group workspaces - trans_ws = ws_basename + '_Transmission' + if out_ws == '': + out_ws = ws_basename + '_Transmission' + group = sam_ws + ',' + can_ws + ',' + tr_ws - GroupWorkspaces(InputWorkspaces=group, OutputWorkspace=trans_ws) + GroupWorkspaces(InputWorkspaces=group, OutputWorkspace=out_ws) + + self.setProperty('OutputWorkspace', out_ws) if verbose: logger.notice('Transmission : ' + str(trans)) @@ -59,17 +66,17 @@ def PyExec(self): # Save the tranmissin workspace group to a nexus file if save: workdir = config['defaultsave.directory'] - path = os.path.join(workdir, trans_ws + '.nxs') - SaveNexusProcessed(InputWorkspace=trans_ws, Filename=path) + path = os.path.join(workdir, out_ws + '.nxs') + SaveNexusProcessed(InputWorkspace=out_ws, Filename=path) if verbose: logger.notice('Output file created : ' + path) # Plot spectra from transmission workspace if plot: mtd_plot = import_mantidplot() - mtd_plot.plotSpectrum(trans_ws, 0) + mtd_plot.plotSpectrum(out_ws, 0) - EndTime('IndirectTransmissionReduction') + EndTime('IndirectTransmissionMonitor') def UnwrapMon(self, inWS): # Unwrap monitor - inWS contains M1,M2,S1 - outWS contains unwrapped Mon @@ -85,13 +92,10 @@ def UnwrapMon(self, inWS): return out_ws - def TransMon(self, ws_basename, file_type, filename, verbose): - if verbose: - logger.notice('Raw file : ' + file_type) - - LoadRaw(Filename=filename, OutputWorkspace='__m1', SpectrumMin=1, SpectrumMax=1) - LoadRaw(Filename=filename, OutputWorkspace='__m2', SpectrumMin=2, SpectrumMax=2) - LoadRaw(Filename=filename, OutputWorkspace='__det', SpectrumMin=3, SpectrumMax=3) + def TransMon(self, ws_basename, file_type, input_ws, verbose): + CropWorkspace(InputWorkspace=input_ws, OutputWorkspace='__m1', StartWorkspaceIndex=0, EndWorkspaceIndex=0) + CropWorkspace(InputWorkspace=input_ws, OutputWorkspace='__m2', StartWorkspaceIndex=1, EndWorkspaceIndex=1) + CropWorkspace(InputWorkspace=input_ws, OutputWorkspace='__det', StartWorkspaceIndex=2, EndWorkspaceIndex=2) # Check for single or multiple time regimes mon_tcb_start = mtd['__m1'].readX(0)[0] @@ -106,7 +110,6 @@ def TransMon(self, ws_basename, file_type, filename, verbose): else: ConvertUnits(InputWorkspace='__m1', OutputWorkspace='__Mon1', Target="Wavelength") - ConvertUnits(InputWorkspace='__m2', OutputWorkspace='__Mon2', Target="Wavelength") DeleteWorkspace('__m2') # delete monWS @@ -129,4 +132,4 @@ def TransMon(self, ws_basename, file_type, filename, verbose): DeleteWorkspace('__Mon2') # delete monWS # Register algorithm with Mantid -AlgorithmFactory.subscribe(IndirectTransmissionReduction) +AlgorithmFactory.subscribe(IndirectTransmissionMonitor) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt index 1d7ff6790d7c..c8f127c8fbe6 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt @@ -14,7 +14,7 @@ set ( TEST_PY_FILES FindReflectometryLinesTest.py GetEiT0atSNSTest.py IndirectILLReductionTest.py - IndirectTransmissionReductionTest.py + IndirectTransmissionMonitorTest.py LoadFullprofFileTest.py LoadLiveDataTest.py LoadLogPropertyTableTest.py diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionReductionTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionMonitorTest.py similarity index 81% rename from Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionReductionTest.py rename to Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionMonitorTest.py index 2f3175af4464..c426bd57ee6e 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionReductionTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionMonitorTest.py @@ -2,7 +2,7 @@ import mantid from mantid.simpleapi import * -class IndirectTransmissionReductionTest(unittest.TestCase): +class IndirectTransmissionMonitorTest(unittest.TestCase): def setUp(self): self.kwargs = {} @@ -23,7 +23,7 @@ def tearDown(self): pass def test_basic(self): - IndirectTransmissionReduction(**self.kwargs) + IndirectTransmissionMonitor(**self.kwargs) trans_workspace = mtd[self.run_number + '_Transmission'] @@ -33,7 +33,7 @@ def test_basic(self): def test_nexus_save(self): self.kwargs['Save'] = True - IndirectTransmissionReduction(**self.kwargs) + IndirectTransmissionMonitor(**self.kwargs) path = os.path.join(config['defaultsave.directory'], self.run_number + '_Transmission.nxs') self.assertTrue(os.path.isfile(path), msg='Transmission workspace should be saved to default save directory') @@ -41,12 +41,12 @@ def test_nexus_save(self): def test_empty_filenames(self): self.kwargs['CanFile'] = '' - self.assertRaises(ValueError, IndirectTransmissionReduction, **self.kwargs) + self.assertRaises(ValueError, IndirectTransmissionMonitor, **self.kwargs) def test_nonexistent_file(self): self.kwargs['CanFile'] = 'NoFile.raw' - self.assertRaises(ValueError, IndirectTransmissionReduction, **self.kwargs) + self.assertRaises(ValueError, IndirectTransmissionMonitor, **self.kwargs) if __name__ == '__main__': unittest.main() diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp index 7d3159231b3e..767261ccce68 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTransmission.cpp @@ -34,10 +34,13 @@ namespace CustomInterfaces QString sampleNo = m_uiForm.transInputFile->getFirstFilename(); QString canNo = m_uiForm.transCanFile->getFirstFilename(); - IAlgorithm_sptr transAlg = AlgorithmManager::Instance().create("IndirectTransmissionReduction", -1); + IAlgorithm_sptr transAlg = AlgorithmManager::Instance().create("IndirectTransmissionMonitor", -1); transAlg->initialize(); - transAlg->setProperty("SampleFile", sampleNo.toStdString()); - transAlg->setProperty("CanFile", canNo.toStdString()); + + //TODO + transAlg->setProperty("SampleWorkspace", sampleNo.toStdString()); + transAlg->setProperty("CanWorkspace", canNo.toStdString()); + transAlg->setProperty("Verbose", m_uiForm.trans_ckVerbose->isChecked()); transAlg->setProperty("Plot", m_uiForm.trans_ckPlot->isChecked()); transAlg->setProperty("Save", m_uiForm.trans_ckSave->isChecked()); diff --git a/Code/Mantid/docs/source/algorithms/IndirectTransmissionReduction-v1.rst b/Code/Mantid/docs/source/algorithms/IndirectTransmissionMonitor-v1.rst similarity index 100% rename from Code/Mantid/docs/source/algorithms/IndirectTransmissionReduction-v1.rst rename to Code/Mantid/docs/source/algorithms/IndirectTransmissionMonitor-v1.rst