This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/9432_system_tests_poldi_…
…peak_search_and_fit'
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import stresstesting | ||
from mantid.simpleapi import * | ||
import numpy as np | ||
|
||
'''Checking results of PoldiFitPeaks1D.''' | ||
class POLDIFitPeaks1DTest(stresstesting.MantidStressTest): | ||
def runTest(self): | ||
dataFiles = ["poldi2013n006904"] | ||
|
||
self.loadReferenceCorrelationData(dataFiles) | ||
self.loadReferencePeakData(dataFiles) | ||
self.loadReferenceFitResults(dataFiles) | ||
self.runPeakSearch(dataFiles) | ||
self.runPoldiFitPeaks1D(dataFiles) | ||
self.analyseResults(dataFiles) | ||
|
||
def loadReferenceCorrelationData(self, filenames): | ||
for dataFile in filenames: | ||
Load(Filename="%s_reference.nxs" % (dataFile), OutputWorkspace=dataFile) | ||
|
||
def loadReferencePeakData(self, filenames): | ||
for dataFile in filenames: | ||
Load(Filename="%s_reference_Peaks.nxs" % (dataFile), OutputWorkspace="%s_reference_Peaks" % (dataFile)) | ||
|
||
def runPeakSearch(self, filenames): | ||
for dataFile in filenames: | ||
PoldiPeakSearch(InputWorkspace=dataFile, OutputWorkspace="%s_Peaks" % (dataFile)) | ||
|
||
def loadReferenceFitResults(self, filenames): | ||
for dataFile in filenames: | ||
Load(Filename="%s_reference_1DFit.nxs" % (dataFile), OutputWorkspace="%s_reference_1DFit" % (dataFile)) | ||
|
||
def runPoldiFitPeaks1D(self, filenames): | ||
for dataFile in filenames: | ||
PoldiFitPeaks1D(InputWorkspace=dataFile, | ||
FwhmMultiples=5, | ||
PoldiPeakTable="%s_Peaks" % (dataFile), | ||
OutputWorkspace="%s_Peaks_Refined" % (dataFile), | ||
ResultTableWorkspace="%s_Results" % (dataFile), | ||
FitCharacteristicsWorkspace="%s_FitData" % (dataFile), | ||
FitPlotsWorkspace="%s_FitPlots" % (dataFile)) | ||
|
||
# This test makes sure that: | ||
# - standard deviations of position and relative fwhm are acceptably small (indicates reasonable fit) | ||
# - refined peak positions are within one standard deviation of reference results obtained from existing program | ||
# - fwhms do not deviate too much from reference results | ||
# - currently, only the first 10 peaks are compared (as in the peak search test) | ||
def analyseResults(self, filenames): | ||
for dataFile in filenames: | ||
calculatedPeaks = mtd["%s_Peaks_Refined" % (dataFile)] | ||
referencePeaks = mtd["%s_reference_1DFit" % (dataFile)] | ||
self.assertEqual(calculatedPeaks.rowCount(), referencePeaks.rowCount()) | ||
|
||
positions = calculatedPeaks.column(2) | ||
referencePositions = referencePeaks.column(0) | ||
|
||
fwhms = calculatedPeaks.column(4) | ||
referenceFwhms = referencePeaks.column(1) | ||
|
||
for i in range(10): | ||
# extract position and fwhm with uncertainties | ||
positionparts = positions[i].split() | ||
position = [float(positionparts[0]), float(positionparts[2])] | ||
|
||
fwhmparts = fwhms[i].split() | ||
fwhm = [float(fwhmparts[0]), float(fwhmparts[2])] | ||
|
||
self.assertTrue(self.positionAcceptable(position)) | ||
self.assertTrue(self.fwhmAcceptable(fwhm)) | ||
|
||
# find closest reference peak | ||
deltas = np.array([np.abs(position[0] - x) for x in referencePositions]) | ||
|
||
self.assertDelta(deltas.min(), 0.0, 1e-4) | ||
minIndex = deltas.argmin() | ||
|
||
self.assertTrue(self.uncertainValueEqualsReference(position, referencePositions[minIndex], 1.0)) | ||
self.assertDelta(fwhm[0], referenceFwhms[minIndex], 2e-4) | ||
|
||
def positionAcceptable(self, position): | ||
return position[1] < 1e-3 | ||
|
||
def fwhmAcceptable(self, fwhm): | ||
return fwhm[1] < 3e-3 | ||
|
||
def uncertainValueEqualsReference(self, value, reference, sigmas): | ||
return np.abs(value[0] - reference) < (sigmas * value[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import stresstesting | ||
from mantid.simpleapi import * | ||
import numpy as np | ||
|
||
'''This test checks that the results of PoldiAutoCorrelation match the expected outcome.''' | ||
class POLDIPeakSearchTest(stresstesting.MantidStressTest): | ||
def runTest(self): | ||
dataFiles = ["poldi2013n006903", "poldi2013n006904"] | ||
|
||
self.loadReferenceCorrelationData(dataFiles) | ||
self.loadReferencePeakData(dataFiles) | ||
self.runPeakSearch(dataFiles) | ||
self.analyseResults(dataFiles) | ||
|
||
def loadReferenceCorrelationData(self, filenames): | ||
for dataFile in filenames: | ||
Load(Filename="%s_reference.nxs" % (dataFile), OutputWorkspace=dataFile) | ||
|
||
def loadReferencePeakData(self, filenames): | ||
for dataFile in filenames: | ||
Load(Filename="%s_reference_Peaks.nxs" % (dataFile), OutputWorkspace="%s_reference_Peaks" % (dataFile)) | ||
|
||
def runPeakSearch(self, filenames): | ||
for dataFile in filenames: | ||
PoldiPeakSearch(InputWorkspace=dataFile, OutputWorkspace="%s_Peaks" % (dataFile)) | ||
|
||
def analyseResults(self, filenames): | ||
for dataFile in filenames: | ||
calculatedPeaks = mtd["%s_Peaks" % (dataFile)] | ||
referencePeaks = mtd["%s_reference_Peaks" % (dataFile)] | ||
self.assertEqual(calculatedPeaks.rowCount(), referencePeaks.rowCount()) | ||
|
||
positions = calculatedPeaks.column(2) | ||
referencePositions = referencePeaks.column(0) | ||
|
||
# In this test we only compare positions, because the height | ||
# and error estimates are derived differently than in the | ||
# original software, so the results are not exactly the same. | ||
# | ||
# Most important in this case are peak positions. Since the order | ||
# depends on height, it may be different, so the comparison can not | ||
# be done 1:1. | ||
for position in positions[:10]: | ||
deltas = [np.abs(float(position) - x) for x in referencePositions] | ||
|
||
self.assertDelta(min(deltas), 0.0, 1e-6) |
Binary file added
BIN
+10.4 KB
SystemTests/AnalysisTests/ReferenceResults/poldi2013n006903_reference_Peaks.nxs
Binary file not shown.
Binary file added
BIN
+12.3 KB
SystemTests/AnalysisTests/ReferenceResults/poldi2013n006904_reference_1DFit.nxs
Binary file not shown.
Binary file added
BIN
+10.4 KB
SystemTests/AnalysisTests/ReferenceResults/poldi2013n006904_reference_Peaks.nxs
Binary file not shown.