Skip to content

Commit

Permalink
Support TOSCA on IndirectTransmission
Browse files Browse the repository at this point in the history
Refs #10673
  • Loading branch information
DanNixon committed Mar 31, 2015
1 parent c673997 commit 4a7e035
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
Expand Up @@ -36,7 +36,7 @@ def summary(self):

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',
Expand Down Expand Up @@ -69,7 +69,10 @@ def PyExec(self):
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()
Expand Down Expand Up @@ -100,8 +103,7 @@ def PyExec(self):
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))

Expand Down Expand Up @@ -148,24 +150,34 @@ def PyExec(self):
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
Expand Down
Expand Up @@ -29,6 +29,29 @@ def test_indirect_transmission_iris_graphite_002(self):
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.
Expand Down
Expand Up @@ -37,7 +37,6 @@
</property>
<property name="disabledInstruments" stdset="0">
<stringlist>
<string>TOSCA</string>
<string>TFXA</string>
</stringlist>
</property>
Expand Down

0 comments on commit 4a7e035

Please sign in to comment.