Skip to content
Snippets Groups Projects
Commit 0106a9de authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #3705 Correct one bank at a time; normalize by upstream monitor

parent 58dca1b6
No related branches found
No related tags found
No related merge requests found
...@@ -146,7 +146,7 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -146,7 +146,7 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
return wksp return wksp
def _loadNeXusData(self, runnumber, extension, **kwargs): def _loadNeXusData(self, runnumber, bank, extension, **kwargs):
if self.getProperty("CompressOnRead"): if self.getProperty("CompressOnRead"):
kwargs["CompressTolerance"] = COMPRESS_TOL_TOF kwargs["CompressTolerance"] = COMPRESS_TOL_TOF
else: else:
...@@ -155,7 +155,14 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -155,7 +155,14 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
filename = name + extension filename = name + extension
try: # first just try loading the file try: # first just try loading the file
alg = LoadEventNexus(Filename=filename, OutputWorkspace=name, **kwargs) alg = LoadEventNexus(Filename=filename, OutputWorkspace=name, BankName=bank, SingleBankPixelsOnly='0', LoadMonitors=True, MonitorsAsEvents=True, **kwargs)
#Normalise by sum of counts in upstream monitor
Integration(InputWorkspace=mtd[str(name)+'_monitors'], OutputWorkspace='Mon', EndWorkspaceIndex='0')
temp = mtd['Mon']
Divide(LHSWorkspace=alg.workspace(), RHSWorkspace=temp, OutputWorkspace=alg.workspace(), AllowDifferentNumberSpectra='1')
mtd.deleteWorkspace(str(name)+'_monitors')
mtd.deleteWorkspace('Mon')
mtd.releaseFreeMemory()
return alg.workspace() return alg.workspace()
except: except:
...@@ -171,11 +178,18 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -171,11 +178,18 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
name = name[0:-1*len("_event")] name = name[0:-1*len("_event")]
# TODO use timemin and timemax to filter what events are being read # TODO use timemin and timemax to filter what events are being read
alg = LoadEventNexus(Filename=filename, OutputWorkspace=name, **kwargs) alg = LoadEventNexus(Filename=filename, OutputWorkspace=name, BankName=bank, SingleBankPixelsOnly='0', LoadMonitors=True, MonitorsAsEvents=True, **kwargs)
#Normalise by sum of counts in upstream monitor
Integration(InputWorkspace=mtd[str(name)+'_monitors'], OutputWorkspace='Mon', EndWorkspaceIndex='0')
temp = mtd['Mon']
Divide(LHSWorkspace=alg.workspace(), RHSWorkspace=temp, OutputWorkspace=alg.workspace(), AllowDifferentNumberSpectra='1')
mtd.deleteWorkspace(str(name)+'_monitors')
mtd.deleteWorkspace('Mon')
mtd.releaseFreeMemory()
return alg.workspace() return alg.workspace()
def _loadData(self, runnumber, extension, filterWall=None): def _loadData(self, runnumber, bank, extension, filterWall=None):
filter = {} filter = {}
if filterWall is not None: if filterWall is not None:
if filterWall[0] > 0.: if filterWall[0] > 0.:
...@@ -187,11 +201,11 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -187,11 +201,11 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
return None return None
if extension.endswith(".nxs"): if extension.endswith(".nxs"):
return self._loadNeXusData(runnumber, extension, **filter) return self._loadNeXusData(runnumber, bank, extension, **filter)
else: else:
return self._loadPreNeXusData(runnumber, extension) return self._loadPreNeXusData(runnumber, extension)
def _focus(self, wksp, info, filterLogs=None): def _focus(self, wksp, bank, info, filterLogs=None):
if wksp is None: if wksp is None:
return None return None
# take care of filtering events # take care of filtering events
...@@ -208,18 +222,18 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -208,18 +222,18 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
% (filterLogs[0], str(wksp))) % (filterLogs[0], str(wksp)))
if not self.getProperty("CompressOnRead"): if not self.getProperty("CompressOnRead"):
CompressEvents(InputWorkspace=wksp, OutputWorkspace=wksp, Tolerance=COMPRESS_TOL_TOF) # 100ns CompressEvents(InputWorkspace=wksp, OutputWorkspace=wksp, Tolerance=COMPRESS_TOL_TOF) # 100ns
groups = "" #groups = ""
numrange = 60 #numrange = 60
for num in xrange(1,numrange): #for num in xrange(1,numrange):
comp = wksp.getInstrument().getComponentByName("bank%d" % (num) ) #comp = wksp.getInstrument().getComponentByName("bank%d" % (num) )
if not comp == None: #if not comp == None:
groups+=("bank%d," % (num) ) #groups+=("bank%d," % (num) )
print groups CreateGroupingWorkspace(InputWorkspace=wksp, GroupNames=bank, OutputWorkspace=str(wksp)+"group")
CreateGroupingWorkspace(InputWorkspace=wksp, GroupNames=groups, OutputWorkspace=str(wksp)+"group")
ConvertUnits(InputWorkspace=wksp, OutputWorkspace=wksp, Target="dSpacing") ConvertUnits(InputWorkspace=wksp, OutputWorkspace=wksp, Target="dSpacing")
DiffractionFocussing(InputWorkspace=wksp, OutputWorkspace=wksp, DiffractionFocussing(InputWorkspace=wksp, OutputWorkspace=wksp,
GroupingWorkspace=str(wksp)+"group") GroupingWorkspace=str(wksp)+"group")
wksp/=(256*256) #Scale peaks to heights that work well with integration
wksp*=160
mtd.deleteWorkspace(str(wksp)+"group") mtd.deleteWorkspace(str(wksp)+"group")
mtd.releaseFreeMemory() mtd.releaseFreeMemory()
SortEvents(InputWorkspace=wksp, SortBy="X Value") SortEvents(InputWorkspace=wksp, SortBy="X Value")
...@@ -353,7 +367,7 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -353,7 +367,7 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
samRun = None samRun = None
info = None info = None
for temp in samRuns: for temp in samRuns:
temp = self._loadData(temp, SUFFIX, filterWall) temp = self._loadData(temp, bank, SUFFIX, filterWall)
tempinfo = self._getinfo(temp) tempinfo = self._getinfo(temp)
if samRun is None: if samRun is None:
samRun = temp samRun = temp
...@@ -361,95 +375,126 @@ class SNSSingleCrystalReduction(PythonAlgorithm): ...@@ -361,95 +375,126 @@ class SNSSingleCrystalReduction(PythonAlgorithm):
else: else:
Plus(samRun, temp, samRun) Plus(samRun, temp, samRun)
mtd.deleteWorkspace(str(temp)) mtd.deleteWorkspace(str(temp))
mtd.releaseFreeMemory()
samRuns = [samRun] samRuns = [samRun]
Banks = ["bank17","bank18","bank26","bank27","bank36","bank37","bank38","bank39","bank46","bank47","bank48","bank49","bank57","bank58"]
for samRun in samRuns: for samRun in samRuns:
# first round of processing the sample samRunnum = samRun
if not self.getProperty("Sum"): for bank in Banks:
samRun = self._loadData(samRun, SUFFIX, filterWall) # first round of processing the sample
SortEvents(InputWorkspace=samRun, SortBy="X Value") if not self.getProperty("Sum"):
NormaliseByCurrent(InputWorkspace=samRun, OutputWorkspace=samRun) samRun = self._loadData(samRunnum, bank, SUFFIX, filterWall)
info = self._getinfo(samRun) SortEvents(InputWorkspace=samRun, SortBy="X Value")
info = self._getinfo(samRun)
# process the container
canRun = self.getProperty("BackgroundNumber") # process the container
if canRun <= 0: canRun = self.getProperty("BackgroundNumber")
canRun = info.can if canRun <= 0:
if canRun > 0: canRun = info.can
temp = mtd["%s_%d" % (self._instrument, canRun)] if canRun > 0:
if temp is None: temp = mtd["%s_%d" % (self._instrument, canRun)]
canRun = self._loadData(canRun, SUFFIX, (0., 0.)) if temp is None:
if self._xadjpixels+self._yadjpixels > 0: canRun = self._loadData(canRun, bank, SUFFIX, (0., 0.))
SmoothNeighbours(InputWorkspace=canRun, OutputWorkspace=canRun, if self._xadjpixels+self._yadjpixels > 0:
AdjX=self._xadjpixels, AdjY=self._yadjpixels) SmoothNeighbours(InputWorkspace=canRun, OutputWorkspace=canRun,
CompressEvents(InputWorkspace=canRun, OutputWorkspace=canRun, AdjX=self._xadjpixels, AdjY=self._yadjpixels, ZeroEdgePixels=20)
Tolerance=COMPRESS_TOL_TOF) # 5ns CompressEvents(InputWorkspace=canRun, OutputWorkspace=canRun,
SortEvents(InputWorkspace=canRun, SortBy="X Value") Tolerance=COMPRESS_TOL_TOF) # 5ns
NormaliseByCurrent(InputWorkspace=canRun, OutputWorkspace=canRun) SortEvents(InputWorkspace=canRun, SortBy="X Value")
else:
canRun = temp
else: else:
canRun = temp canRun = None
else:
canRun = None if canRun is not None:
samRun -= canRun
if canRun is not None: CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
samRun -= canRun Tolerance=COMPRESS_TOL_TOF) # 10ns
CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
Tolerance=COMPRESS_TOL_TOF) # 10ns # process the vanadium run
vanRun = self.getProperty("VanadiumNumber")
# process the vanadium run if vanRun <= 0:
vanRun = self.getProperty("VanadiumNumber") vanRun = info.van
if vanRun <= 0: if vanRun > 0:
vanRun = info.van temp = mtd["%s_%d" % (self._instrument, vanRun)]
if vanRun > 0: if temp is None:
temp = mtd["%s_%d" % (self._instrument, vanRun)] vanRun = self._loadData(vanRun, bank, SUFFIX, (0., 0.))
if temp is None: if self._xadjpixels+self._yadjpixels > 0:
vanRun = self._loadData(vanRun, SUFFIX, (0., 0.)) SmoothNeighbours(InputWorkspace=vanRun, OutputWorkspace=vanRun,
#if self._xadjpixels+self._yadjpixels > 0: AdjX=0, AdjY=0, ZeroEdgePixels=20)
#SmoothNeighbours(InputWorkspace=vanRun, OutputWorkspace=vanRun, CompressEvents(InputWorkspace=vanRun, OutputWorkspace=vanRun,
#AdjX=self._xadjpixels, AdjY=self._yadjpixels) Tolerance=COMPRESS_TOL_TOF) # 5ns
#CompressEvents(InputWorkspace=vanRun, OutputWorkspace=vanRun, SortEvents(InputWorkspace=vanRun, SortBy="X Value")
#Tolerance=COMPRESS_TOL_TOF) # 5ns if canRun is not None:
SortEvents(InputWorkspace=vanRun, SortBy="X Value") vanRun -= canRun
NormaliseByCurrent(InputWorkspace=vanRun, OutputWorkspace=vanRun) mtd.deleteWorkspace(str(canRun))
if canRun is not None: mtd.releaseFreeMemory()
vanRun -= canRun CompressEvents(InputWorkspace=vanRun, OutputWorkspace=vanRun,
Integration(InputWorkspace=vanRun,OutputWorkspace='VanSumTOF',IncludePartialBins='1') Tolerance=COMPRESS_TOL_TOF) # 10ns
vanRun = self._focus(vanRun, info) Integration(InputWorkspace=vanRun,OutputWorkspace='VanSumTOF',IncludePartialBins='1')
ConvertToMatrixWorkspace(InputWorkspace=vanRun, OutputWorkspace=vanRun) vanRun = self._focus(vanRun, bank, info)
ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="dSpacing") ConvertToMatrixWorkspace(InputWorkspace=vanRun, OutputWorkspace=vanRun)
StripVanadiumPeaks(InputWorkspace=vanRun, OutputWorkspace=vanRun, PeakWidthPercent=self._vanPeakWidthPercent) ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="dSpacing")
ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="TOF") StripVanadiumPeaks(InputWorkspace=vanRun, OutputWorkspace=vanRun, PeakWidthPercent=self._vanPeakWidthPercent)
FFTSmooth(InputWorkspace=vanRun, OutputWorkspace=vanRun, Filter="Butterworth", ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="TOF")
Params=self._vanSmoothing,IgnoreXBins=True,AllSpectra=True) FFTSmooth(InputWorkspace=vanRun, OutputWorkspace=vanRun, Filter="Butterworth",
MultipleScatteringCylinderAbsorption(InputWorkspace=vanRun, OutputWorkspace=vanRun, # numbers for vanadium Params=self._vanSmoothing,IgnoreXBins=True,AllSpectra=True)
AttenuationXSection=2.8, ScatteringXSection=5.1, #MultipleScatteringCylinderAbsorption(InputWorkspace=vanRun, OutputWorkspace=vanRun, # numbers for vanadium
SampleNumberDensity=0.0721, CylinderSampleRadius=.3175) #AttenuationXSection=2.8, ScatteringXSection=5.1,
SetUncertaintiesToZero(InputWorkspace=vanRun, OutputWorkspace=vanRun) #SampleNumberDensity=0.0721, CylinderSampleRadius=.3175)
SetUncertaintiesToZero(InputWorkspace=vanRun, OutputWorkspace=vanRun)
else:
vanRun = temp
else: else:
vanRun = temp vanRun = None
else:
vanRun = None # the final bit of math
if vanRun is not None:
# the final bit of math vanI = mtd["VanSumTOF"]
if vanRun is not None: FindDetectorsOutsideLimits(InputWorkspace=vanI,OutputWorkspace='VanMask',
vanI = mtd["VanSumTOF"] HighThreshold='1.0e+300',LowThreshold='1.0e-300')
FindDetectorsOutsideLimits(InputWorkspace=vanI,OutputWorkspace='VanMask',HighThreshold='1.0000000000000001e+300',LowThreshold='1.0e-300') vanmask = mtd["VanMask"]
vanmask = mtd["VanMask"] MaskDetectors(Workspace=vanI,MaskedWorkspace=vanmask)
MaskDetectors(Workspace=vanI,MaskedWorkspace=vanmask) MaskDetectors(Workspace=samRun,MaskedWorkspace=vanmask)
MaskDetectors(Workspace=samRun,MaskedWorkspace=vanmask) mtd.deleteWorkspace('VanMask')
Divide(LHSWorkspace=samRun,RHSWorkspace=vanI,OutputWorkspace=samRun,AllowDifferentNumberSpectra='1') mtd.releaseFreeMemory()
Divide(LHSWorkspace=samRun, RHSWorkspace=vanRun, OutputWorkspace=samRun, AllowDifferentNumberSpectra=True) SmoothNeighbours(InputWorkspace=samRun, OutputWorkspace=samRun,
normalized = True AdjX=0, AdjY=0, ZeroEdgePixels=20)
else: Divide(LHSWorkspace=samRun,RHSWorkspace=vanI,OutputWorkspace=samRun,AllowDifferentNumberSpectra=True)
normalized = False mtd.deleteWorkspace(str(vanI))
mtd.releaseFreeMemory()
Divide(LHSWorkspace=samRun, RHSWorkspace=vanRun, OutputWorkspace=samRun, AllowDifferentNumberSpectra=True)
mtd.deleteWorkspace(str(vanRun))
mtd.releaseFreeMemory()
FindDetectorsOutsideLimits(InputWorkspace=samRun,OutputWorkspace='SamMask',
HighThreshold='1.0e+300',LowThreshold='1.0e-300')
sammask = mtd["SamMask"]
MaskDetectors(Workspace=samRun,MaskedWorkspace=sammask)
mtd.deleteWorkspace('SamMask')
mtd.releaseFreeMemory()
CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
Tolerance=COMPRESS_TOL_TOF) # 5ns
mtd.releaseFreeMemory()
normalized = True
else:
normalized = False
if bank is "bank17":
samRunstr = str(samRun)
RenameWorkspace(InputWorkspace=samRun,OutputWorkspace=samRunstr+"_total")
samRunT = mtd[samRunstr+"_total"]
else:
samRunT += samRun
mtd.deleteWorkspace(str(samRun))
mtd.releaseFreeMemory()
# write out the files # write out the files
RenameWorkspace(InputWorkspace=samRunT,OutputWorkspace=samRunstr)
samRun = mtd[samRunstr]
samRun = self._bin(samRun, info) samRun = self._bin(samRun, info)
CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
Tolerance=COMPRESS_TOL_TOF) # 5ns
self._save(samRun, normalized) self._save(samRun, normalized)
samRun = str(samRun) #mtd.deleteWorkspace(str(samRun))
mtd.deleteWorkspace(samRun)
mtd.releaseFreeMemory() mtd.releaseFreeMemory()
mtd.registerPyAlgorithm(SNSSingleCrystalReduction()) mtd.registerPyAlgorithm(SNSSingleCrystalReduction())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment