Skip to content

Commit

Permalink
Resolved conflict. Refs #10203.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Sep 3, 2014
2 parents 18660e2 + 24eb686 commit 14218fc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 20 deletions.
Expand Up @@ -61,6 +61,16 @@ def PyInit(self):
self.declareProperty("NormBackRun", 0,
doc="The background" + defaultMsg)

self.declareProperty(StringArrayProperty("FrequencyLogNames", ["SpeedRequest1", "Speed1", "frequency"],
direction=Direction.Input),
"Possible log names for frequency.")

self.declareProperty(StringArrayProperty("WaveLengthLogNames", ["LambdaRequest", "lambda"],
direction=Direction.Input),
"Candidate log names for wave length.")

return

def validateInputs(self):
# correct workspace type
char = self.getProperty("Characterizations").value
Expand Down Expand Up @@ -136,7 +146,7 @@ def processInformation(self, prop_man, info_dict):
try:
val = [float(x) for x in val.split(',')]
except ValueError, err:
self.log().error("Error to parse key = %s value = %s. " % (str(key), str(value)))
self.log().error("Error to parse key = %s value = %s. " % (str(key), str(val)))
raise NotImplementedError(str(err))

try:
Expand All @@ -156,23 +166,33 @@ def closeEnough(self, left, right):
return False

def getLine(self, char, frequency, wavelength):
""" Get line in the characterization file with given frequency and wavelength
"""
# empty dictionary if things are wrong
if frequency is None or wavelength is None:
return dict(DEF_INFO)

# go through every row looking for a match
result = dict(DEF_INFO)
icount = 0
for i in xrange(char.rowCount()):
row = char.row(i)
if not self.closeEnough(frequency, row['frequency']):
continue
if not self.closeEnough(wavelength, row['wavelength']):
continue
result = dict(row)
icount += 1

self.log().information("Total %d rows are parsed for frequency = %f, wavelength = %f" % (icount, frequency, wavelength))
return result

def getFrequency(self, logs, wkspName):
for name in ["SpeedRequest1", "Speed1", "frequency"]:
""" Get frequency from log
"""
frequencynames = self.getProperty("FrequencyLogNames").value
self.log().notice("Type of frequency names is %s" % (str(type(frequencynames))))
for name in frequencynames:
if name in logs.keys():
frequency = logs[name]
if frequency.units != "Hz":
Expand All @@ -198,25 +218,46 @@ def getWavelength(self, logs, wkspName):
Wavelength can be given by 2 sample logs, either LambdaRequest or lambda.
And its unit can be either Angstrom or A.
"""
name = "LambdaRequest"
if name not in logs.keys():
name = 'lambda'
if name not in logs.keys():
self.log().warning("Failed to determine wavelength in \"%s\". No log named 'LambdaRequest' or 'lambda'." % wkspName)
return None

wavelength = logs[name]
if wavelength.units != "Angstrom" and wavelength.units != "A":
msg = "Only know how to deal with LambdaRequest in "\
"Angstrom (A), not %s" % wavelength
self.log().information(msg)
else:
wavelength = wavelength.getStatistics().mean
if wavelength == 0.:
self.log().information("'%s' mean value is zero" % name)
wavelengthnames = self.getProperty("WaveLengthLogNames").value

for name in wavelengthnames:
# skip if not exists
if name not in logs.keys():
continue

# get value
wavelength = logs[name]

# unit
if name == "LambdaRequest":
if wavelength.units != "Angstrom":
msg = "Only know how to deal with LambdaRequest in Angstrom, not %s" % (wavelength.units)
self.log().warning(msg)
break

elif name == "lambda":
if wavelength.units != "A":
msg = "Only know how to deal with lambda in A, not %s" % (wavelength.units)
self.log().warning(msg)
break

else:
if wavelength.units != "Angstrom" and wavelength.units != "A":
msg = "Only know how to deal with %s in Angstrom (A) but not %s" % (name,
wavelength.units)
self.log().warning(msg)
break

# return
wavelength = wavelength.getStatistics().mean
if wavelength == 0.:
self.log().warning("'%s' mean value is zero" % name)
break
else:
return wavelength

# ENDFOR

return None

# Register algorthm with Mantid.
Expand Down
Expand Up @@ -97,7 +97,15 @@ def PyInit(self):

self.declareProperty("NormalizeByCurrent", True, "Normalize by current")

self.declareProperty("CompressTOFTolerance", 0.01, "Tolerance to compress events in TOF.")
self.declareProperty("CompressTOFTolerance", 0.01, "Tolerance to compress events in TOF.")

self.declareProperty(StringArrayProperty("FrequencyLogNames", ["SpeedRequest1", "Speed1", "frequency"],
direction=Direction.Input),
"Possible log names for frequency.")

self.declareProperty(StringArrayProperty("WaveLengthLogNames", ["LambdaRequest", "lambda"],
direction=Direction.Input),
"Candidate log names for wave length.")

return

Expand Down Expand Up @@ -726,12 +734,16 @@ def _getinfo(self, wksp):

if mtd.doesExist("characterizations"):
# get the correct row of the table


charac = api.PDDetermineCharacterizations(InputWorkspace=wksp,
Characterizations="characterizations",
ReductionProperties="__snspowderreduction",
BackRun=self.getProperty("BackgroundNumber").value,
NormRun=self.getProperty("VanadiumNumber").value,
NormBackRun=self.getProperty("VanadiumBackgroundNumber").value)
NormBackRun=self.getProperty("VanadiumBackgroundNumber").value,
FrequencyLogNames = self.getProperty("FrequencyLogNames").value,
WaveLengthLogNames = self.getProperty("WaveLengthLogNames").value)
# convert the result into a dict
manager = PropertyManagerDataService.retrieve("__snspowderreduction")
for name in ["frequency", "wavelength", "bank", "vanadium", "container",
Expand Down

0 comments on commit 14218fc

Please sign in to comment.