diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrate.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrate.py index b7dcc6e08a22..09acce72a5d1 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrate.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXCalibrate.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") self.declareProperty(ITableWorkspaceProperty("DetectorPositions", "", Direction.Input, PropertyMode.Optional), @@ -41,6 +44,7 @@ def PyExec(self): fitPeaksAlg.setProperty('InputWorkspace', ws) fitPeaksAlg.setProperty('WorkspaceIndex', 0) # There should be only one index anyway fitPeaksAlg.setProperty('ExpectedPeaks', self.getProperty('ExpectedPeaks').value) + fitPeaksAlg.setProperty('ExpectedPeaksFromFile', self.getProperty('ExpectedPeaksFromFile').value) fitPeaksAlg.execute() self.setProperty('Difc', fitPeaksAlg.getProperty('Difc').value) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py index 706487717334..f1f0bdbeaafc 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/EnginXFitPeaks.py @@ -40,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((self.getPropertyValue("ExpectedPeaksFromFile")),((self.getProperty('ExpectedPeaks').value))) + expectedPeaksD = self._readInExpectedPeaks() # Find approximate peak positions, asumming Gaussian shapes findPeaksAlg = self.createChildAlgorithm('FindPeaks') @@ -105,10 +105,10 @@ def PyExec(self): self.setProperty('Difc', difc) self.setProperty('Zero', zero) - def _readInExpectedPeaks(self, peaksFromFile, peaksMan): + def _readInExpectedPeaks(self): """ 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 = peaksFromFile + exPeaksfile = (self.getPropertyValue("ExpectedPeaksFromFile")) if exPeaksfile != "": with open(exPeaksfile) as f: exPeaksfileCsv = csv.reader(f, delimiter=',', quotechar= '|') @@ -117,11 +117,11 @@ def _readInExpectedPeaks(self, peaksFromFile, peaksMan): exPeakArray.append(float(num)) if exPeakArray == []: print "File could not be read. Defaults being used." - expectedPeaksD = sorted(peaksMan) + expectedPeaksD = sorted(self.getProperty('ExpectedPeaks').value) else: expectedPeaksD = sorted(exPeakArray) else: - expectedPeaksD = sorted(peaksMan) + expectedPeaksD = sorted(self.getProperty('ExpectedPeaks').value) return expectedPeaksD def _getDefaultPeaks(self): @@ -170,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((self.getPropertyValue("ExpectedPeaksFromFile")),((self.getProperty('ExpectedPeaks').value))) + expectedPeaks = self._readInExpectedPeaks() # Expected peak positions in TOF for the detector expectedPeaksTof = map(dSpacingToTof, expectedPeaks)