Skip to content

Commit

Permalink
updates for system test of callfull-then-cal, re #12426
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Jul 14, 2015
1 parent 1c413bb commit 2c6abf7
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 57 deletions.
110 changes: 95 additions & 15 deletions Code/Mantid/Testing/SystemTests/tests/analysis/EnggCalibrateTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,114 @@
import stresstesting
from mantid.simpleapi import *

class EnggCalibrateTest(stresstesting.MantidStressTest):
class EnginXFocusWithVanadiumCorrection(stresstesting.MantidStressTest):

def __init__(self):
stresstesting.MantidStressTest.__init__(self)
self.difc = -1
self.zero = -1
self.difc_b2 = -1
self.zero_b2 = -1

def runTest(self):
calib_ws = Load(Filename = 'ENGINX00193749.nxs')
pass

positions = EnggCalibrateFull(Workspace = calib_ws,
Bank = '1',
ExpectedPeaks = '1.3529, 1.6316, 1.9132')
def validate(self):
pass

def cleanup(self):
pass

class EnginXCalibrateFullThenCalibrateTest(stresstesting.MantidStressTest):

def __init__(self):
stresstesting.MantidStressTest.__init__(self)
# difc and zero parameters for GSAS
self.difc = -1
self.difc_b2 = -1
self.zero_b2 = -1
self.zero = -1
# table workspace with detector positions
self.posTable = None

def runTest(self):
# These lines run a 'CalibrateFull' and calibrate for the instrument EnginX

(self.difc, self.zero) = EnggCalibrate(InputWorkspace = calib_ws,
Bank = '1',
ExpectedPeaks = '2.7057,1.9132,1.6316,1.5621,1.3528,0.9566',
DetectorPositions = positions)
# This must be the long Ceria (CeO2) run for calibrate-full
long_calib_ws = Load(Filename = 'ENGINX00193749.nxs')

# This must be the (big) Vanadium (V-Nb) run for vanadium corrections
van_ws = Load(Filename = 'ENGINX00236516.nxs')

positions = EnggCalibrateFull(Workspace = long_calib_ws,
VanadiumWorkspace = van_ws,
Bank = '1',
ExpectedPeaks = '1.3529, 1.6316, 1.9132')
self.posTable = positions

# Bank 1
(self.difc, self.zero) = EnggCalibrate(InputWorkspace = long_calib_ws,
VanadiumWorkspace = van_ws,
Bank = '1',
ExpectedPeaks = '2.7057,1.9132,1.6316,1.5621,1.3528,0.9566',
DetectorPositions = self.posTable)

# Bank 2
(self.difc_b2, self.zero_b2) = EnggCalibrate(InputWorkspace = long_calib_ws,
VanadiumWorkspace = van_ws,
Bank = '2',
ExpectedPeaks = '2.7057,1.9132,1.6316,1.5621,1.3528,0.9566',
DetectorPositions = self.posTable)

def _relErrLessDelta(self, val, ref, epsilon):
"""
Checks that a value 'val' does not defer from a reference value 'ref' by 'epsilon'
or more. This method compares the relative error. An epsilon of 0.1 means a relative
difference of 10 % = 100*0.1 %
@param val :: value obtained from a calculation or algorithm
@param ref :: (expected) reference value
@param epsilon :: acceptable relative error (error tolerance)
@returns if val differs in relative terms from ref by less than epsilon
"""
if 0 == ref:
return False
return (abs((ref-val)/ref) < epsilon)

def validate(self):
# === check detector positions table produced by EnggCalibrateFull
self.assertTrue(self.posTable)
self.assertEquals(self.posTable.columnCount(), 9)
self.assertEquals(self.posTable.rowCount(), 1200)
self.assertEquals(self.posTable.cell(88, 0), 100089) # det ID
self.assertEquals(self.posTable.cell(200, 0), 101081) # det ID

# this will be used as a comparison delta of 'delta' %
exdelta = 1e-5
# Note that the reference values are given with 12 digits more for reference than
# for assert-comparison purposes (comparisons are not that picky, by far)
self.assertTrue(self._relErrLessDelta(self.posTable.cell(100, 3), 1.49010562897, exdelta))
#self.assertDelta(self.posTable.cell(100, 3), 1.49010562897, delta)
self.assertTrue(self._relErrLessDelta(self.posTable.cell(400, 4), 1.65264105797, exdelta))
self.assertTrue(self._relErrLessDelta(self.posTable.cell(200, 5), 0.296705961227, exdelta))
self.assertTrue(self._relErrLessDelta(self.posTable.cell(610, 7), 18585.1738281, exdelta))
self.assertTrue(self._relErrLessDelta(self.posTable.cell(1199, 8), -1.56501817703, exdelta))

# === check difc, zero parameters for GSAS produced by EnggCalibrate
# Mac fitting tests produce differences for some reason.
import sys
if sys.platform == "darwin":
# Mac fitting tests produce differences for some reason.
self.assertDelta(self.difc, 18405.4, 0.1)
self.assertDelta(self.zero, 3.60, 0.05)
else:
self.assertDelta(self.difc, 18404.496, 0.001)
self.assertDelta(self.zero, 4.4345, 0.001)
delta_darwin = 5e-3
exdelta = delta_darwin

# Bank 1
self.assertTrue(self._relErrLessDelta(self.difc, 18405.0526862, exdelta))
self.assertTrue(self._relErrLessDelta(self.zero, -0.835863958543, exdelta))

# Bank 2
self.assertTrue(self._relErrLessDelta(self.difc_b2, 18391.1104257, exdelta))
self.assertTrue(self._relErrLessDelta(self.zero_b2, -8.66653176951, exdelta))

def cleanup(self):
mtd.remove('positions')

0 comments on commit 2c6abf7

Please sign in to comment.