Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #10 from mantidproject/feature/10263_poldi_fit_clo…
Browse files Browse the repository at this point in the history
…se_peaks_combined

Feature/10263 poldi fit close peaks combined
  • Loading branch information
FedeMPouzols committed Feb 4, 2015
2 parents bd03c03 + 7029c6d commit 182cd55
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions SystemTests/AnalysisTests/POLDIFitPeaks1DTest.py
Expand Up @@ -4,58 +4,69 @@

'''Checking results of PoldiFitPeaks1D.'''
class POLDIFitPeaks1DTest(stresstesting.MantidStressTest):
# The errors of fitted parameters in version 2 are a bit small
# because of the "fabricated data", so a larger margin has to be allowed.
versionDeltas = {1: 2.0e-4, 2: 1.5e-3}
errorMultiplier = {1: 1.0, 2: 4.0}

def runTest(self):
dataFiles = ["poldi2013n006904"]
dataFiles = ["poldi2013n006904", "poldi_2_phases_theoretical"]
versions = [1, 2]
deleteList = [[], ['12-16', '10', '9']]

self.loadReferenceCorrelationData(dataFiles)
self.loadReferencePeakData(dataFiles)
self.loadReferenceFitResults(dataFiles)
self.runPeakSearch(dataFiles)
self.runPoldiFitPeaks1D(dataFiles)
self.analyseResults(dataFiles)
self.runPeakSearch(dataFiles, deleteList)
self.runPoldiFitPeaks1D(dataFiles, versions)
self.analyseResults(dataFiles, versions)

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, deleteList):
for dataFile,deleteRowList in zip(filenames, deleteList):
PoldiPeakSearch(InputWorkspace=dataFile,
MinimumPeakSeparation=8,
OutputWorkspace="%s_Peaks" % (dataFile))

def runPeakSearch(self, filenames):
for dataFile in filenames:
PoldiPeakSearch(InputWorkspace=dataFile, OutputWorkspace="%s_Peaks" % (dataFile))
for deleteRows in deleteRowList:
DeleteTableRows(TableWorkspace="%s_Peaks" % (dataFile), Rows=deleteRows)

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))
def runPoldiFitPeaks1D(self, filenames, versions):
for dataFile, version in zip(filenames, versions):
args = {"InputWorkspace": dataFile,
"FwhmMultiples": 4,
"PoldiPeakTable": "%s_Peaks" % (dataFile),
"OutputWorkspace": "%s_Peaks_Refined" % (dataFile),
"FitPlotsWorkspace": "%s_FitPlots" % (dataFile),
"Version": version}

if version == 2:
args["AllowedOverlap"] = 0.1

PoldiFitPeaks1D(**args)

# 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:
def analyseResults(self, filenames, versions):
for dataFile, version in zip(filenames, versions):
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)
referencePositions = [float(x) for x in referencePeaks.column(0)]

fwhms = calculatedPeaks.column(4)
referenceFwhms = referencePeaks.column(1)
referenceFwhms = [float(x) for x in referencePeaks.column(1)]

for i in range(10):
# extract position and fwhm with uncertainties
Expand All @@ -71,11 +82,12 @@ def analyseResults(self, filenames):
# find closest reference peak
deltas = np.array([np.abs(position[0] - x) for x in referencePositions])

self.assertDelta(deltas.min(), 0.0, 1e-4)

self.assertDelta(deltas.min(), 0.0, self.versionDeltas[version])
minIndex = deltas.argmin()

self.assertTrue(self.uncertainValueEqualsReference(position, referencePositions[minIndex], 1.0))
self.assertDelta(fwhm[0], referenceFwhms[minIndex], 2e-4)
self.assertTrue(self.uncertainValueEqualsReference(position, referencePositions[minIndex], self.errorMultiplier[version]))
self.assertDelta(fwhm[0], referenceFwhms[minIndex], self.versionDeltas[version])

def positionAcceptable(self, position):
return position[1] < 1e-3
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 182cd55

Please sign in to comment.