Skip to content
Snippets Groups Projects
Commit 51032d06 authored by Harry Jeffery's avatar Harry Jeffery
Browse files

Merge pull request #494 from mantidproject/10673_support_tosca_on_transmission_calc

Support TOSCA on IndirectTransmission
parents fb047181 4a7e035f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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.
......
......@@ -37,7 +37,6 @@
</property>
<property name="disabledInstruments" stdset="0">
<stringlist>
<string>TOSCA</string>
<string>TFXA</string>
</stringlist>
</property>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment