Skip to content

Commit

Permalink
Updated unit test and docs for cylinder algo
Browse files Browse the repository at this point in the history
Refs #11413
  • Loading branch information
DanNixon committed Mar 23, 2015
1 parent 00eaa10 commit da492d8
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 36 deletions.
Expand Up @@ -17,47 +17,53 @@ def setUp(self):
self._red_ws = red_ws


def _test_workspaces(self, corrected, ass):
def _test_workspaces(self, corrected, factor_group):
"""
Checks the units of the Ass and corrected workspaces.
@param corrected Corrected workspace
@param ass Assc corrections workspace
@param factor_group WorkspaceGroup containing factors
"""

# Test units of corrected workspace
corrected_x_unit = corrected.getAxis(0).getUnit().unitID()
self.assertEqual(corrected_x_unit, 'DeltaE')

ass_x_unit = ass.getAxis(0).getUnit().unitID()
self.assertEquals(ass_x_unit, 'Wavelength')
# Test units of factor workspaces
for ws in factor_group:
x_unit = ws.getAxis(0).getUnit().unitID()
self.assertEquals(x_unit, 'Wavelength')

ass_y_unit = ass.YUnitLabel()
self.assertEqual(ass_y_unit, 'Attenuation factor')
y_unit = ws.YUnitLabel()
self.assertEqual(y_unit, 'Attenuation factor')


def test_sample_corrections_only(self):
"""
Tests corrections for the sample only.
"""

corrected, ass = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
ChemicalFormula='H2-O',
SampleRadius=0.2)
corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
SampleChemicalFormula='H2-O',
Events=500)

self._test_workspaces(corrected, ass)
self.assertEqual(fact.size(), 1)
self._test_workspaces(corrected, fact)


def test_sample_and_can_subtraction(self):
"""
Tests corrections for the sample and simple container subtraction.
"""

corrected, ass = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
CanWorkspace=self._can_ws,
ChemicalFormula='H2-O',
SampleRadius=0.2)
corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
CanWorkspace=self._can_ws,
SampleChemicalFormula='H2-O',
UseCanCorrections=False,
Events=500)

self._test_workspaces(corrected, ass)
self.assertEqual(fact.size(), 1)
self._test_workspaces(corrected, fact)


def test_sample_and_can_subtraction_with_scale(self):
Expand All @@ -66,13 +72,31 @@ def test_sample_and_can_subtraction_with_scale(self):
with can scale.
"""

corrected, ass = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
CanWorkspace=self._can_ws,
CanScaleFactor=0.8,
ChemicalFormula='H2-O',
SampleRadius=0.2)
corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
CanWorkspace=self._can_ws,
CanScaleFactor=0.8,
SampleChemicalFormula='H2-O',
UseCanCorrections=False,
Events=500)

self._test_workspaces(corrected, ass)
self.assertEqual(fact.size(), 1)
self._test_workspaces(corrected, fact)


def test_sample_and_can_corrections(self):
"""
Tests corrections for the sample and container.
"""

corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=self._red_ws,
CanWorkspace=self._can_ws,
SampleChemicalFormula='H2-O',
CanChemicalFormula='V',
UseCanCorrections=True,
Events=500)

self.assertEqual(fact.size(), 2)
self._test_workspaces(corrected, fact)


if __name__ == '__main__':
Expand Down
Expand Up @@ -9,12 +9,13 @@
Description
-----------

Calculates and applies corrections for scattering abs absorption in a
Calculates and applies corrections for scattering and absorption in a
cylindrical sample for a run on an indirect inelastic instrument, optionally
also performing a simple can subtraction is a container workspace is provided.
allowing for the subtraction or corrections of the container.

The corrections workspace (:math:`A_{s,s}`) is the standard Paalman and Pings
attenuation factor for absorption and scattering in the sample.
The correction factor workspace is a workspace group containing the correction
factors in the Paalman and Pings format, note that only :math:`{A_{s,s}}` and
:math:`A_{c,c}` factors are calculated by thsi algorithm.

Usage
-----
Expand All @@ -28,32 +29,78 @@ Usage
red_ws = LoadNexusProcessed(Filename='irs26176_graphite002_red.nxs')
can_ws = LoadNexusProcessed(Filename='irs26173_graphite002_red.nxs')

corrected, ass = IndirectCylinderAbsorption(SampleWorkspace=red_ws,
CanWorkspace=can_ws,
CanScaleFactor=0.8,
ChemicalFormula='H2-O',
SampleRadius=0.2)
corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=red_ws,
SampleChemicalFormula='H2-O',
CanWorkspace=can_ws,
CanScaleFactor=0.8,
SampleRadius=0.2,
UseCanCorrections=False,
Events=100)

ass = fact[0]

print ('Corrected workspace is intensity against %s'
% (corrected.getAxis(0).getUnit().caption()))

print ('Corrections workspace is %s against %s'
print ('Ass workspace is %s against %s'
% (ass.YUnitLabel(), ass.getAxis(0).getUnit().caption()))


.. testcleanup:: SampleCorrectionsWithCanSubtraction

DeleteWorkspace(red_ws)
DeleteWorkspace(can_ws)
DeleteWorkspace(corrected)
DeleteWorkspace(ass)
DeleteWorkspace(fact)

**Output:**


.. testoutput:: SampleCorrectionsWithCanSubtraction

Corrected workspace is intensity against Energy transfer
Corrections workspace is Attenuation factor against Wavelength
Corrected workspace is intensity against Energy transfer
Ass workspace is Attenuation factor against Wavelength

**Example - Sample and container corrections for IRIS:**

.. testcode:: SampleCorrectionsWithCanCorrections

red_ws = LoadNexusProcessed(Filename='irs26176_graphite002_red.nxs')
can_ws = LoadNexusProcessed(Filename='irs26173_graphite002_red.nxs')

corrected, fact = IndirectCylinderAbsorption(SampleWorkspace=red_ws,
SampleChemicalFormula='H2-O',
SampleRadius=0.2,
CanWorkspace=can_ws,
CanScaleFactor=0.8,
CanChemicalFormula='V',
CanRadius=0.22,
UseCanCorrections=True,
Events=100)

ass = fact[0]
acc = fact[1]

print ('Corrected workspace is intensity against %s'
% (corrected.getAxis(0).getUnit().caption()))

print ('Ass workspace is %s against %s'
% (ass.YUnitLabel(), ass.getAxis(0).getUnit().caption()))

print ('Acc workspace is %s against %s'
% (acc.YUnitLabel(), acc.getAxis(0).getUnit().caption()))

.. testcleanup:: SampleCorrectionsWithCanCorrections

DeleteWorkspace(red_ws)
DeleteWorkspace(can_ws)
DeleteWorkspace(corrected)
DeleteWorkspace(fact)

**Output:**

.. testoutput:: SampleCorrectionsWithCanCorrections

Corrected workspace is intensity against Energy transfer
Ass workspace is Attenuation factor against Wavelength
Acc workspace is Attenuation factor against Wavelength

.. categories::

0 comments on commit da492d8

Please sign in to comment.