Skip to content

Commit

Permalink
Refs #10910 csv loading added in calibrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lottie Greenwood committed Jan 29, 2015
1 parent 95b752c commit ead10cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -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),
Expand All @@ -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)
Expand Down
Expand Up @@ -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')
Expand Down Expand Up @@ -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= '|')
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ead10cb

Please sign in to comment.