Skip to content
Snippets Groups Projects
Commit 21463dba authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Only load calibration file once per invocation

parent c8af42be
No related merge requests found
......@@ -2,7 +2,7 @@ from __future__ import (absolute_import, division, print_function)
from mantid.api import mtd, AlgorithmFactory, DataProcessorAlgorithm, ITableWorkspaceProperty, \
MatrixWorkspaceProperty, MultipleFileProperty, PropertyMode
from mantid.kernel import Direction
from mantid.kernel import ConfigService, Direction
from mantid.simpleapi import AlignAndFocusPowder, CompressEvents, ConvertUnits, CreateCacheFilename, \
DeleteWorkspace, DetermineChunking, Divide, EditInstrumentGeometry, FilterBadPulses, Load, \
LoadNexusProcessed, PDDetermineCharacterizations, Plus, RenameWorkspace, SaveNexusProcessed
......@@ -10,9 +10,11 @@ import os
EXTENSIONS_NXS = ["_event.nxs", ".nxs.h5"]
PROPS_FOR_INSTR = ["PrimaryFlightPath", "SpectrumIDs", "L2", "Polar", "Azimuthal"]
PROPS_FOR_ALIGN = ["CalFileName", "GroupFilename", "GroupingWorkspace",
"CalibrationWorkspace", "OffsetsWorkspace",
"MaskWorkspace", "MaskBinTable",
CAL_FILE, GROUP_FILE = "CalFileName", "GroupFilename"
CAL_WKSP, GRP_WKSP, MASK_WKSP = "CalibrationWorkspace", "GroupingWorkspace", "MaskWorkspace"
PROPS_FOR_ALIGN = [CAL_FILE, GROUP_FILE,
GRP_WKSP,CAL_WKSP, "OffsetsWorkspace",
MASK_WKSP, "MaskBinTable",
"Params", "ResampleX", "Dspacing", "DMin", "DMax",
"TMin", "TMax", "PreserveEvents",
"RemovePromptPulseWidth", "CompressTolerance",
......@@ -99,6 +101,29 @@ class AlignAndFocusPowderFromFiles(DataProcessorAlgorithm):
args[name] = prop.value
return args
def __updateAlignAndFocusArgs(self, wkspname):
self.log().warning('__updateAlignAndFocusArgs(%s)!!!!!!!' % wkspname)
# if the files are missing, there is nothing to do
if (not CAL_FILE in self.kwargs) and (not GROUP_FILE in self.kwargs):
self.log().warning('--> Nothing to do')
self.log().warning('--> Updating')
# delete the files from the list of kwargs
if CAL_FILE in self.kwargs:
del self.kwargs[CAL_FILE]
if CAL_FILE in self.kwargs:
del self.kwargs[GROUP_FILE]
# get the instrument name
instr = mtd[wkspname].getInstrument().getName()
instr = ConfigService.getInstrument(instr).shortName()
# use the canonical names if they weren't specifed
for key, ext in zip((CAL_WKSP, GRP_WKSP, MASK_WKSP),
('_cal', '_group', '_mask')):
if not key in self.kwargs:
self.kwargs[key] = instr + ext
def __determineCharacterizations(self, filename, wkspname):
tempname = '__%s_temp' % wkspname
Load(Filename=filename, OutputWorkspace=tempname,
......@@ -172,6 +197,7 @@ class AlignAndFocusPowderFromFiles(DataProcessorAlgorithm):
prog_start += 2.*prog_per_chunk_step # AlignAndFocusPowder counts for two steps
if j == 0:
self.__updateAlignAndFocusArgs(chunkname)
RenameWorkspace(InputWorkspace=chunkname, OutputWorkspace=wkspname)
else:
Plus(LHSWorkspace=wkspname, RHSWorkspace=chunkname, OutputWorkspace=wkspname,
......@@ -199,7 +225,8 @@ class AlignAndFocusPowderFromFiles(DataProcessorAlgorithm):
for (i, filename) in enumerate(filenames):
# default name is based off of filename
wkspname = os.path.split(filename)[-1].split('.')[0]
self.__determineCharacterizations(filename, wkspname)
self.__determineCharacterizations(filename,
wkspname) # updates instance variable
cachefile = self.__getCacheName(wkspname)
wkspname += '_f%d' % i # add file number to be unique
......
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