diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/IndirectTransmission.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/IndirectTransmission.py index 1b9bbcfbc9f497745a23c627b7595b4ee0d22a04..e7d30359777d897fe2065f207b9fbcb296b37a9f 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/IndirectTransmission.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/IndirectTransmission.py @@ -36,7 +36,7 @@ class IndirectTransmission(PythonAlgorithm): def PyInit(self): self.declareProperty(name='Instrument', defaultValue='IRIS', - validator=StringListValidator(['IRIS', 'OSIRIS', 'BASIS', 'VISION']), + validator=StringListValidator(['IRIS', 'OSIRIS', 'TOSCA', 'BASIS', 'VISION']), doc='Instrument') self.declareProperty(name='Analyser', defaultValue='graphite', @@ -69,7 +69,10 @@ class IndirectTransmission(PythonAlgorithm): thickness = self.getPropertyValue('Thickness') # Create an empty instrument workspace - workspace = self._create_instrument_workspace(instrument_name) + workspace = '__empty_' + instrument_name + CreateSimulationWorkspace(OutputWorkspace=workspace, + Instrument=instrument_name, + BinParams='0,0.5,1') # Do some validation on the analyser and reflection instrument = mtd[workspace].getInstrument() @@ -100,8 +103,7 @@ class IndirectTransmission(PythonAlgorithm): LoadParameterFile(Workspace=workspace, Filename=ipf_filename) # Get efixed value - instrument = mtd[workspace].getInstrument() - efixed = instrument.getNumberParameter('efixed-val')[0] + efixed = self._get_efixed(workspace) logger.notice('Analyser : ' + analyser + reflection + ' with energy = ' + str(efixed)) @@ -148,24 +150,34 @@ class IndirectTransmission(PythonAlgorithm): self.setProperty("OutputWorkspace", table_ws) - def _create_instrument_workspace(self, instrument_name): + def _get_efixed(self, workspace): """ - Creates a workspace with the most recent version of the given instrument attached to it. + Gets an efixed value form a workspace. - @param instrument_name Name of the instrument to load - @return Name of the created workspace + @param workspace Name of workspace to extract from + @return Fixed energy value """ - # Get the filename for the most recent instrument defintion - CreateSampleWorkspace(OutputWorkspace='__temp') - idf_filename = mtd['__temp'].getInstrumentFilename(instrument_name) - DeleteWorkspace('__temp') - - # Load instrument defintion file - workspace = '__empty_' + instrument_name - LoadEmptyInstrument(OutputWorkspace=workspace, Filename=idf_filename) - - return workspace + ws = mtd[workspace] + + # Try to get efixed from the parameters first + try: + instrument = ws.getInstrument() + efixed = instrument.getNumberParameter('efixed-val')[0] + except IndexError: + efixed = 0.0 + + # If that fails then get it by taking from group of all detectors + if efixed == 0.0: + spectra_list = range(0, ws.getNumberHistograms()) + GroupDetectors(InputWorkspace=workspace, + OutputWorkspace=workspace, + SpectraList=spectra_list) + ws = mtd[workspace] + det = ws.getDetector(0) + efixed = mtd[workspace].getEFixed(det.getID()) + + return efixed # Register algorithm with Mantid diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionTest.py index 29c60dc01d1c8cb636b4bda07c19c70886177803..a5f05a0f7270c9462d177c65657a57882b6f7eda 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/IndirectTransmissionTest.py @@ -29,6 +29,29 @@ class IndirectTransmissionTest(unittest.TestCase): np.testing.assert_array_almost_equal(values, ref_result, decimal=4) + def test_indirect_transmission_tosca_graphite_002(self): + """ + Test a transmission calculation using TOSCA, graphite, 002. + """ + + instrument = "TOSCA" + analyser = "graphite" + reflection = "002" + + # Using water sample + formula = "H2-O" + density = 0.1 + thickness = 0.1 + + ws = IndirectTransmission(Instrument=instrument, Analyser=analyser, Reflection=reflection, + ChemicalFormula=formula, NumberDensity=density, Thickness=thickness) + + # Expected values from table + ref_result = [5.5137, 0.680081, 2.58187, 53.5069, 56.0888, 0.1, 0.1, 0.566834, 0.429298] + values = ws.column(1) + np.testing.assert_array_almost_equal(values, ref_result, decimal=4) + + def test_indirect_transmission_basis_silicon_111(self): """ Test a transmission calculation using BASIS, silicon 111. diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTransmissionCalc.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTransmissionCalc.ui index 44809830545b5d800dd9fca8441a4af1429cedee..1010c25300f1b42ea070ba25fe03cf72b846116d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTransmissionCalc.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTransmissionCalc.ui @@ -37,7 +37,6 @@ </property> <property name="disabledInstruments" stdset="0"> <stringlist> - <string>TOSCA</string> <string>TFXA</string> </stringlist> </property>