diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py index 9d586a12440d..262e1afe37c7 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrateFull.py @@ -22,6 +22,9 @@ def PyInit(self): self.declareProperty(FloatArrayProperty("ExpectedPeaks", ""), "A list of dSpacing values where peaks are expected.") + self.declareProperty(FileProperty(name="ExpectedPeaksFromFile",defaultValue="",action=FileAction.OptionalLoad,extensions = [".csv"]), + "Load from file a list of dSpacing values to be translated into TOF to find expected peaks.") + self.declareProperty("Bank", 1, "Which bank to calibrate") def PyExec(self): @@ -91,10 +94,13 @@ def _createPositionsTable(self): def _fitPeaks(self, ws, wsIndex): """ Fits expected peaks to the spectrum, and returns calibrated zero and difc values. """ + import EnginXFitPeaks + #expectedPeaks = EnginXFitPeaks.EnginXFitPeaks._readInExpectedPeaks((self.getPropertyValue("ExpectedPeaksFromFile")),((self.getProperty('ExpectedPeaks').value))) alg = self.createChildAlgorithm('EnginXFitPeaks') alg.setProperty('InputWorkspace', ws) alg.setProperty('WorkspaceIndex', wsIndex) # There should be only one index anyway alg.setProperty('ExpectedPeaks', self.getProperty('ExpectedPeaks').value) + alg.setProperty('ExpectedPeaksFromFile', self.getProperty('ExpectedPeaksFromFile').value) alg.execute() difc = alg.getProperty('Difc').value diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py index 4868db59303b..706487717334 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py @@ -1,7 +1,7 @@ from mantid.kernel import * from mantid.api import * -import csv +import csv import math import numpy as np @@ -25,7 +25,8 @@ def PyInit(self): self.declareProperty(FloatArrayProperty("ExpectedPeaks", (self._getDefaultPeaks())), "A list of dSpacing values to be translated into TOF to find expected peaks.") - self.declareProperty(FileProperty(name="ExpectedPeaksFromFile",defaultValue="",action=FileAction.OptionalLoad,extensions = [".csv"]),"Load from file a list of dSpacing values to be translated into TOF to find expected peaks.") + self.declareProperty(FileProperty(name="ExpectedPeaksFromFile",defaultValue="",action=FileAction.OptionalLoad,extensions = [".csv"]), + "Load from file a list of dSpacing values to be translated into TOF to find expected peaks.") self.declareProperty("Difc", 0.0, direction = Direction.Output, doc = "Fitted Difc value") @@ -39,7 +40,7 @@ def PyExec(self): # FindPeaks will returned a list of peaks sorted by the centre found. Sort the peaks as well, # so we can match them with fitted centres later. expectedPeaksTof = sorted(expectedPeaksTof) - expectedPeaksD = self._readInExpectedPeaks() + expectedPeaksD = self._readInExpectedPeaks((self.getPropertyValue("ExpectedPeaksFromFile")),((self.getProperty('ExpectedPeaks').value))) # Find approximate peak positions, asumming Gaussian shapes findPeaksAlg = self.createChildAlgorithm('FindPeaks') @@ -104,10 +105,10 @@ def PyExec(self): self.setProperty('Difc', difc) self.setProperty('Zero', zero) - def _readInExpectedPeaks(self): - """ Reads in expected peaks from the .csv file """ + def _readInExpectedPeaks(self, peaksFromFile, peaksMan): + """ Reads in expected peaks from the .csv file, and the manually entered peaks and decides which is used. File is given preference over manually entered peaks.""" exPeakArray = [] - exPeaksfile = self.getPropertyValue("ExpectedPeaksFromFile") + exPeaksfile = peaksFromFile if exPeaksfile != "": with open(exPeaksfile) as f: exPeaksfileCsv = csv.reader(f, delimiter=',', quotechar= '|') @@ -116,11 +117,11 @@ def _readInExpectedPeaks(self): exPeakArray.append(float(num)) if exPeakArray == []: print "File could not be read. Defaults being used." - expectedPeaksD = sorted(self.getProperty('ExpectedPeaks').value) + expectedPeaksD = sorted(peaksMan) else: expectedPeaksD = sorted(exPeakArray) else: - expectedPeaksD = sorted(self.getProperty('ExpectedPeaks').value) + expectedPeaksD = sorted(peaksMan) return expectedPeaksD def _getDefaultPeaks(self): @@ -169,7 +170,7 @@ def _expectedPeaksInTOF(self): # Function for converting dSpacing -> TOF for the detector dSpacingToTof = lambda d: 252.816 * 2 * (50 + detL2) * math.sin(detTwoTheta / 2.0) * d - expectedPeaks = self._readInExpectedPeaks() + expectedPeaks = self._readInExpectedPeaks((self.getPropertyValue("ExpectedPeaksFromFile")),((self.getProperty('ExpectedPeaks').value))) # Expected peak positions in TOF for the detector expectedPeaksTof = map(dSpacingToTof, expectedPeaks)