Skip to content

Commit

Permalink
Refs #10910 csv loading added in calibrateFull
Browse files Browse the repository at this point in the history
  • Loading branch information
Lottie Greenwood committed Jan 29, 2015
1 parent c3770dc commit 95b752c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 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")

def PyExec(self):
Expand Down Expand Up @@ -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
Expand Down
@@ -1,7 +1,7 @@
from mantid.kernel import *
from mantid.api import *
import csv

import csv
import math
import numpy as np

Expand All @@ -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")
Expand All @@ -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')
Expand Down Expand Up @@ -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= '|')
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 95b752c

Please sign in to comment.