Skip to content

Commit

Permalink
Updated documentation, added unit testing
Browse files Browse the repository at this point in the history
Refs #11188
  • Loading branch information
DanNixon committed Mar 2, 2015
1 parent d125419 commit 6a82cb8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 14 deletions.
Expand Up @@ -204,7 +204,7 @@ def _get_angles(self):
source_pos = mtd[self._sample_ws_name].getInstrument().getSource().getPos()
sample_pos = mtd[self._sample_ws_name].getInstrument().getSample().getPos()
beam_pos = sample_pos - source_pos
self._angles = []
self._angles = list()
for index in range(0, num_hist):
detector = mtd[self._sample_ws_name].getDetector(index)
two_theta = detector.getTwoTheta(sample_pos, beam_pos) * 180.0 / math.pi # calc angle
Expand All @@ -220,6 +220,7 @@ def _wave_range(self):
number_waves = self._number_wavelengths
wave_bin = (wave_max - wave_min) / (number_waves-1)

self._waves = list()
for idx in range(0, number_waves):
self._waves.append(wave_min + idx * wave_bin)

Expand Down
Expand Up @@ -15,6 +15,7 @@ set ( TEST_PY_FILES
DSFinterpTest.py
FilterLogByTimeTest.py
FindReflectometryLinesTest.py
FlatPlatePaalmanPIngsCorrectionTest.py
GetEiT0atSNSTest.py
IndirectILLReductionTest.py
InelasticIndirectReductionTest.py
Expand Down
@@ -0,0 +1,120 @@
import unittest
from mantid.kernel import *
from mantid.api import *
from mantid.simpleapi import CreateSampleWorkspace, Scale, DeleteWorkspace, FlatPlatePaalmanPingsCorrection


class FlatPlatePaalmanPingsCorrectionTest(unittest.TestCase):

def setUp(self):
"""
Create sample workspaces.
"""

sample = CreateSampleWorkspace(NumBanks=5,
BankPixelWidth=2,
XUnit='Wavelength',
XMin=6.8,
XMax=7.9,
BinWidth=0.1)
self._sample_ws = sample

can = Scale(InputWorkspace=sample, Factor=1.2)
self._can_ws = can

self._corrections_ws_name = 'corrections'


def tearDown(self):
"""
Remove workspaces from ADS.
"""

DeleteWorkspace(self._sample_ws)
DeleteWorkspace(self._can_ws)
DeleteWorkspace(self._corrections_ws_name)


def _verify_workspace(self, ws_name):
"""
Do validation on a correction workspace.
@param ws_name Name of workspace to validate
"""

corrections_ws = mtd[self._corrections_ws_name]

# Check it is in the corrections workspace group
self.assertTrue(corrections_ws.contains(ws_name))

test_ws = mtd[ws_name]

# Check workspace is in wavelength
self.assertEqual(test_ws.getAxis(0).getUnit().unitID(),
'Wavelength')

# Check it has the same number of spectra as the sample
self.assertEqual(test_ws.getNumberHistograms(),
self._sample_ws.getNumberHistograms())

# Check it has X binning matching NumWavelengths
self.assertEqual(test_ws.blocksize(), 10)


def _verify_workspaces_for_can(self):
"""
Do validation on the additional correction factors for sample and can.
"""

ass_ws_name = self._corrections_ws_name + '_ass'
assc_ws_name = self._corrections_ws_name + '_assc'
acsc_ws_name = self._corrections_ws_name + '_acsc'
acc_ws_name = self._corrections_ws_name + '_acc'

workspaces = [ass_ws_name, assc_ws_name, acsc_ws_name, acc_ws_name]

for workspace in workspaces:
self._verify_workspace(workspace)


def test_sampleOnly(self):
"""
Test simple run with sample workspace only.
"""

FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name,
SampleWorkspace=self._sample_ws,
SampleChemicalFormula='H2-O',
SampleThickness=0.1,
SampleAngle=45,
NumberWavelengths=10,
Emode='Indirect',
Efixed=1.845)

ass_ws_name = self._corrections_ws_name + '_ass'
self. _verify_workspace(ass_ws_name)


def test_sampleAndCan(self):
"""
Test simple run with sample and can workspace.
"""

FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name,
SampleWorkspace=self._sample_ws,
SampleChemicalFormula='H2-O',
SampleThickness=0.1,
SampleAngle=45,
CanWorkspace=self._can_ws,
CanChemicalFormula='V',
CanFrontThickness=0.01,
CanBackThickness=0.01,
NumberWavelengths=10,
Emode='Indirect',
Efixed=1.845)

self._verify_workspaces_for_can()


if __name__=="__main__":
unittest.main()
Expand Up @@ -39,23 +39,23 @@ Usage
can = Scale(InputWorkspace=can, Factor=1.2)

# Calculate absorption corrections
abs = FlatPlatePaalmanPingsCorrection(SampleWorkspace=sample,
SampleChemicalFormula='H2-O',
SampleThickness=0.1,
SampleAngle=45,
CanWorkspace=can,
CanChemicalFormula='V',
CanFrontThickness=0.01,
CanBackThickness=0.01,
Emode='Indirect',
Efixed=1.845)

print 'Correction workspaces: %s' % ', '.join(abs.getNames())
corr = FlatPlatePaalmanPingsCorrection(SampleWorkspace=sample,
SampleChemicalFormula='H2-O',
SampleThickness=0.1,
SampleAngle=45,
CanWorkspace=can,
CanChemicalFormula='V',
CanFrontThickness=0.01,
CanBackThickness=0.01,
Emode='Indirect',
Efixed=1.845)

print 'Correction workspaces: %s' % (', '.join(corr.getNames()))

Output:

.. testoutput:: exSampleAndCan

Correction workspaces: abs_ass, abs_assc, abs_acsc, abs_acc
Correction workspaces: corr_ass, corr_assc, corr_acsc, corr_acc

.. categories::

0 comments on commit 6a82cb8

Please sign in to comment.