Commit d64f7bf1 authored by Zhang, Chen's avatar Zhang, Chen Committed by Peterson, Peter
Browse files

allow va cal to use cache

parent d2edd2ce
......@@ -172,8 +172,8 @@ def __load_cached_data(cache_file_name, sha1, abs_method=""):
:param sha1: SHA1 that identify cached workspace
:param cache_file_name: cache file name to search
return abs_wksp_sample,
abs_wksp_container
return found_abs_wksp_sample, found_abs_wksp_container
abs_wksp_sample, abs_wksp_container
"""
# init
abs_wksp_sample, abs_wksp_container = "", ""
......@@ -215,10 +215,7 @@ def __load_cached_data(cache_file_name, sha1, abs_method=""):
found_abs_wksp_sample = mtd.doesExist(abs_wksp_sample)
found_abs_wksp_container = mtd.doesExist(abs_wksp_container)
abs_wksp_sample = abs_wksp_sample if found_abs_wksp_sample else ""
abs_wksp_container = abs_wksp_container if found_abs_wksp_container else ""
return abs_wksp_sample, abs_wksp_container
return found_abs_wksp_sample, found_abs_wksp_container, abs_wksp_sample, abs_wksp_container
# NOTE:
......@@ -228,7 +225,14 @@ def __load_cached_data(cache_file_name, sha1, abs_method=""):
# -- bare minimum signaure of the function
# func(wksp_name: str, abs_method:str, cache_dir="")
def abs_cache(func):
"""decorator to make the caching process easier"""
"""decorator to make the caching process easier
example:
without caching:
SNSPowderReduction successful, Duration 5 minutes 53.54 seconds
with caching (disk):
SNSPowderReduction successful, Duration 1 minutes 14.18 seconds
"""
@wraps(func)
def inner(*args, **kwargs):
# unpack key arguments
......@@ -245,14 +249,13 @@ def abs_cache(func):
cache_filename, signature = __get_cache_name(wksp_name, abs_method, cache_dir)
# step_2: try load the cached data
abs_wksp_sample, abs_wksp_container = __load_cached_data(cache_filename, signature,
abs_method)
found_sample, found_container, abs_wksp_sample, abs_wksp_container = __load_cached_data(cache_filename, signature, abs_method)
# step_3: calculation
if (abs_method == "SampleOnly") and (abs_wksp_sample != ""):
return abs_wksp_sample
if (abs_method == "SampleOnly") and found_sample:
return abs_wksp_sample, ""
else:
if (abs_wksp_sample != "") and (abs_wksp_container != ""):
if found_sample and found_container:
# cache is available in memory now, skip calculation
return abs_wksp_sample, abs_wksp_container
else:
......
......@@ -13,7 +13,7 @@ from mantid.api import mtd, AlgorithmFactory, AnalysisDataService, DistributedDa
ITableWorkspace, MatrixWorkspace
from mantid.kernel import (
ConfigService, Direction, EnabledWhenProperty, FloatArrayProperty, FloatBoundedValidator, IntArrayBoundedValidator,
IntArrayProperty, Property, PropertyCriterion, PropertyManagerDataService, StringListValidator)
IntArrayProperty, Property, PropertyCriterion, PropertyManagerDataService, StringListValidator, StringTimeSeriesProperty)
from mantid.dataobjects import SplittersWorkspace # SplittersWorkspace
from mantid.utils import absorptioncorrutils
if AlgorithmFactory.exists('GatherWorkspaces'):
......@@ -1357,6 +1357,19 @@ class SNSPowderReduction(DistributedDataProcessorAlgorithm):
opt_wl_max=self._wavelengthMax)
# calculate the correction which is 1/normal carpenter correction - it doesn't look at sample shape
# NOTE: somehow most of the information that create_absorption_input should provide is missing, so
# we are forced to add them dynamically here.
missing_value_dict = {
"SampleFormula": 'V',
"SampleDensity": str(absorptioncorrutils.VAN_SAMPLE_DENSITY),
"BL11A:CS:ITEMS:HeightInContainerUnits": "mm", # or cm? not sure which one
"BL11A:CS:ITEMS:HeightInContainer": "7.0",
"SampleContainer": "None",
}
for key, value in missing_value_dict.items():
mtd[absWksp].mutableRun()[key] = StringTimeSeriesProperty(key)
mtd[absWksp].mutableRun()[key].addValue(0, value)
abs_v_wsn, _ = absorptioncorrutils.calc_absorption_corr_using_wksp(
absWksp,
"SampleOnly",
......@@ -1364,10 +1377,6 @@ class SNSPowderReduction(DistributedDataProcessorAlgorithm):
cache_dir=self.getProperty('CacheDir').value,
)
api.RenameWorkspace(abs_v_wsn, '__V_corr_abs')
# api.AbsorptionCorrection(absWksp,
# OutputWorkspace='__V_corr_abs',
# ScatterFrom='Sample',
# ElementSize=self._elementSize)
api.CalculateCarpenterSampleCorrection(InputWorkspace=absWksp, OutputWorkspaceBaseName='__V_corr',
CylinderSampleRadius=self._vanRadius,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment