Unverified Commit a5345e68 authored by Gemma Guest's avatar Gemma Guest Committed by GitHub
Browse files

Merge pull request #32556 from mantidproject/32555_d16_reduction_bugs

D16 SANSILLAutoProcess reduction issues
parents 60175141 8ed70b8d
...@@ -19,8 +19,14 @@ ...@@ -19,8 +19,14 @@
#include <boost/algorithm/string/predicate.hpp> //assert(boost::algorithm::ends_with("mystring", "ing")); #include <boost/algorithm/string/predicate.hpp> //assert(boost::algorithm::ends_with("mystring", "ing"));
namespace Mantid::DataHandling { namespace Mantid {
namespace {
/// static logger
Kernel::Logger g_log("LoadHelper");
} // namespace
namespace DataHandling {
using namespace Kernel; using namespace Kernel;
using namespace API; using namespace API;
...@@ -241,7 +247,12 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru ...@@ -241,7 +247,12 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
else else
runDetails.addProperty(property_name, property_value); runDetails.addProperty(property_name, property_value);
} else { } else {
runDetails.addProperty(property_name, property_value); if (!runDetails.hasProperty(property_name)) {
runDetails.addProperty(property_name, property_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} }
} else if ((type == NX_FLOAT32) || (type == NX_FLOAT64) || (type == NX_INT16) || (type == NX_INT32) || } else if ((type == NX_FLOAT32) || (type == NX_FLOAT64) || (type == NX_INT16) || (type == NX_INT32) ||
...@@ -266,10 +277,16 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru ...@@ -266,10 +277,16 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
} else if (type == NX_FLOAT64) { } else if (type == NX_FLOAT64) {
property_double_value = *(reinterpret_cast<double *>(dataBuffer)); property_double_value = *(reinterpret_cast<double *>(dataBuffer));
} }
if (units_status != NX_ERROR) if (!runDetails.hasProperty(property_name)) {
runDetails.addProperty(property_name, property_double_value, std::string(units_sbuf));
else if (units_status != NX_ERROR)
runDetails.addProperty(property_name, property_double_value); runDetails.addProperty(property_name, property_double_value, std::string(units_sbuf));
else
runDetails.addProperty(property_name, property_double_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} else if (build_small_float_array) { } else if (build_small_float_array) {
// An array, converted to "name_index", with index < 10 // An array, converted to "name_index", with index < 10
// (see // (see
...@@ -282,10 +299,18 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru ...@@ -282,10 +299,18 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
} }
std::string indexed_property_name = std::string indexed_property_name =
property_name + std::string("_") + std::to_string(dim_index); property_name + std::string("_") + std::to_string(dim_index);
if (units_status != NX_ERROR)
runDetails.addProperty(indexed_property_name, property_double_value, std::string(units_sbuf)); if (!runDetails.hasProperty(property_name)) {
else if (units_status != NX_ERROR)
runDetails.addProperty(indexed_property_name, property_double_value); runDetails.addProperty(indexed_property_name, property_double_value,
std::string(units_sbuf));
else
runDetails.addProperty(indexed_property_name, property_double_value);
} else {
g_log.warning()
<< "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} }
} }
...@@ -300,10 +325,15 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru ...@@ -300,10 +325,15 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
property_int_value = *(reinterpret_cast<short unsigned int *>(dataBuffer)); property_int_value = *(reinterpret_cast<short unsigned int *>(dataBuffer));
} }
if (units_status != NX_ERROR) if (!runDetails.hasProperty(property_name)) {
runDetails.addProperty(property_name, property_int_value, std::string(units_sbuf)); if (units_status != NX_ERROR)
else runDetails.addProperty(property_name, property_int_value, std::string(units_sbuf));
runDetails.addProperty(property_name, property_int_value); else
runDetails.addProperty(property_name, property_int_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} // if (type==... } // if (type==...
} }
...@@ -469,4 +499,5 @@ V3D LoadHelper::getComponentPosition(const API::MatrixWorkspace_sptr &ws, const ...@@ -469,4 +499,5 @@ V3D LoadHelper::getComponentPosition(const API::MatrixWorkspace_sptr &ws, const
return pos; return pos;
} }
} // namespace Mantid::DataHandling } // namespace DataHandling
} // namespace Mantid
...@@ -503,18 +503,12 @@ size_t LoadILLSANS::loadDataFromMonitors(NeXus::NXEntry &firstEntry, size_t firs ...@@ -503,18 +503,12 @@ size_t LoadILLSANS::loadDataFromMonitors(NeXus::NXEntry &firstEntry, size_t firs
HistogramData::BinEdges histoBinEdges(data.dim2() + 1, HistogramData::LinearGenerator(0.0, 1)); HistogramData::BinEdges histoBinEdges(data.dim2() + 1, HistogramData::LinearGenerator(0.0, 1));
m_localWorkspace->setBinEdges(firstIndex, std::move(histoBinEdges)); m_localWorkspace->setBinEdges(firstIndex, std::move(histoBinEdges));
} else { } else {
if (m_isD16Omega) { if (type != MultichannelType::KINETIC) {
HistogramData::Points histoPoints = HistogramData::BinEdges histoBinEdges = HistogramData::BinEdges(m_defaultBinning);
HistogramData::Points(std::vector<double>(1, 0.5 * (m_defaultBinning[0] + m_defaultBinning[1]))); m_localWorkspace->setBinEdges(firstIndex, std::move(histoBinEdges));
m_localWorkspace->setPoints(firstIndex, std::move(histoPoints));
} else { } else {
if (type != MultichannelType::KINETIC) { HistogramData::Points histoPoints = HistogramData::Points(m_defaultBinning);
HistogramData::BinEdges histoBinEdges = HistogramData::BinEdges(m_defaultBinning); m_localWorkspace->setPoints(firstIndex, std::move(histoPoints));
m_localWorkspace->setBinEdges(firstIndex, std::move(histoBinEdges));
} else {
HistogramData::Points histoPoints = HistogramData::Points(m_defaultBinning);
m_localWorkspace->setPoints(firstIndex, std::move(histoPoints));
}
} }
} }
// Add average monitor counts to a property: // Add average monitor counts to a property:
...@@ -568,17 +562,12 @@ size_t LoadILLSANS::loadDataFromTubes(NeXus::NXInt &data, const std::vector<doub ...@@ -568,17 +562,12 @@ size_t LoadILLSANS::loadDataFromTubes(NeXus::NXInt &data, const std::vector<doub
m_localWorkspace->setCounts(index, histoCounts); m_localWorkspace->setCounts(index, histoCounts);
m_localWorkspace->setCountVariances(index, histoVariances); m_localWorkspace->setCountVariances(index, histoVariances);
if (m_isD16Omega) { if (type == MultichannelType::KINETIC) {
const HistogramData::Points histoPoints(std::vector<double>(1, 0.5 * (timeBinning[0] + timeBinning[1]))); const HistogramData::Points histoPoints(timeBinning);
m_localWorkspace->setPoints(index, histoPoints); m_localWorkspace->setPoints(index, histoPoints);
} else { } else {
if (type == MultichannelType::KINETIC) { const HistogramData::BinEdges binEdges(timeBinning);
const HistogramData::Points histoPoints(timeBinning); m_localWorkspace->setBinEdges(index, binEdges);
m_localWorkspace->setPoints(index, histoPoints);
} else {
const HistogramData::BinEdges binEdges(timeBinning);
m_localWorkspace->setBinEdges(index, binEdges);
}
} }
} }
} }
......
...@@ -391,7 +391,7 @@ public: ...@@ -391,7 +391,7 @@ public:
TS_ASSERT(alg.isExecuted()); TS_ASSERT(alg.isExecuted());
MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace"); MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
TS_ASSERT(outputWS); TS_ASSERT(outputWS);
TS_ASSERT(!outputWS->isHistogramData()) TS_ASSERT(outputWS->isHistogramData())
TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320)); TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320));
TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320 + 1)); TS_ASSERT(outputWS->detectorInfo().isMonitor(320 * 320 + 1));
TS_ASSERT_EQUALS(outputWS->blocksize(), 1) TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
......
...@@ -408,6 +408,8 @@ class SANSILLAutoProcess(DataProcessorAlgorithm): ...@@ -408,6 +408,8 @@ class SANSILLAutoProcess(DataProcessorAlgorithm):
self.copyProperties('SANSILLIntegration', ['ShapeTable']) self.copyProperties('SANSILLIntegration', ['ShapeTable'])
self.copyProperties('SANSILLReduction', 'Wavelength')
def PyExec(self): def PyExec(self):
self.setUp() self.setUp()
outputSamples = [] outputSamples = []
...@@ -721,11 +723,34 @@ class SANSILLAutoProcess(DataProcessorAlgorithm): ...@@ -721,11 +723,34 @@ class SANSILLAutoProcess(DataProcessorAlgorithm):
NormaliseBy=self.normalise) NormaliseBy=self.normalise)
return container_name return container_name
def getWavelength(self, logs):
"""Returns wavelength from the property Wavelength, if defined, otherwise attempts to obtain it from
the logs."""
WAVELENGTH_LOG1 = "wavelength"
WAVELENGTH_LOG2 = "selector.wavelength"
wavelength = None
if not self.getProperty('Wavelength').isDefault:
wavelength = self.getProperty('Wavelength').value
else:
try:
wavelength = float(logs[WAVELENGTH_LOG1])
if wavelength < 0.0:
wavelength = None
raise ValueError
except:
try:
wavelength = float(logs[WAVELENGTH_LOG2])
if wavelength < 0.0:
wavelength = None
raise ValueError
except:
logger.notice("Unable to get a valid wavelength from the "
"sample logs.")
return wavelength
def createCustomSuffix(self, ws): def createCustomSuffix(self, ws):
DISTANCE_LOG = "L2" DISTANCE_LOG = "L2"
COLLIMATION_LOG = "collimation.actual_position" COLLIMATION_LOG = "collimation.actual_position"
WAVELENGTH_LOG1 = "wavelength"
WAVELENGTH_LOG2 = "selector.wavelength"
logs = mtd[ws].run().getProperties() logs = mtd[ws].run().getProperties()
logs = {log.name:log.value for log in logs} logs = {log.name:log.value for log in logs}
...@@ -757,21 +782,9 @@ class SANSILLAutoProcess(DataProcessorAlgorithm): ...@@ -757,21 +782,9 @@ class SANSILLAutoProcess(DataProcessorAlgorithm):
except: except:
logger.notice("Unable to get a valid collimation distance from " logger.notice("Unable to get a valid collimation distance from "
"the sample logs.") "the sample logs.")
wavelength = None
try: wavelength = self.getWavelength(logs)
wavelength = float(logs[WAVELENGTH_LOG1])
if wavelength < 0.0:
wavelength = None
raise ValueError
except:
try:
wavelength = float(logs[WAVELENGTH_LOG2])
if wavelength < 0.0:
wavelength = None
raise ValueError
except:
logger.notice("Unable to get a valid wavelength from the "
"sample logs.")
suffix = "" suffix = ""
if distance: if distance:
suffix += "_d{:.1f}m".format(distance) suffix += "_d{:.1f}m".format(distance)
...@@ -879,6 +892,7 @@ class SANSILLAutoProcess(DataProcessorAlgorithm): ...@@ -879,6 +892,7 @@ class SANSILLAutoProcess(DataProcessorAlgorithm):
self.getProperty('SampleThickness').value, self.getProperty('SampleThickness').value,
WaterCrossSection= WaterCrossSection=
self.getProperty('WaterCrossSection').value, self.getProperty('WaterCrossSection').value,
Wavelength=self.getProperty('Wavelength').value
) )
output_sample = self.output + '_#' + str(i + 1) output_sample = self.output + '_#' + str(i + 1)
......
...@@ -139,6 +139,11 @@ class SANSILLParameterScan(PythonAlgorithm): ...@@ -139,6 +139,11 @@ class SANSILLParameterScan(PythonAlgorithm):
_, load_ws_name = needs_loading(self.sample, "Load") _, load_ws_name = needs_loading(self.sample, "Load")
LoadAndMerge(Filename=self.sample, OutputWorkspace=load_ws_name + "_grouped", LoadAndMerge(Filename=self.sample, OutputWorkspace=load_ws_name + "_grouped",
LoaderOptions={"Wavelength": self.wavelength}, startProgress=0, endProgress=0.7) LoaderOptions={"Wavelength": self.wavelength}, startProgress=0, endProgress=0.7)
# Omega scans are loaded as histogram data for compatibility reasons, but we need point data from now on.
# Converting from histogram to point data is straight forward and no meaningful information can be lost.
ConvertToPointData(InputWorkspace=load_ws_name + "_grouped", OutputWorkspace=load_ws_name + "_grouped")
ConjoinXRuns(InputWorkspaces=load_ws_name + "_grouped", ConjoinXRuns(InputWorkspaces=load_ws_name + "_grouped",
OutputWorkspace=load_ws_name + "_joined", OutputWorkspace=load_ws_name + "_joined",
SampleLogAsXAxis=self.observable, startProgress=0.7, endProgress=0.75) SampleLogAsXAxis=self.observable, startProgress=0.7, endProgress=0.75)
......
...@@ -268,6 +268,10 @@ class SANSILLReduction(PythonAlgorithm): ...@@ -268,6 +268,10 @@ class SANSILLReduction(PythonAlgorithm):
self.setPropertySettings('SolventInputWorkspace', sample) self.setPropertySettings('SolventInputWorkspace', sample)
self.declareProperty('Wavelength', 0.0,
validator=FloatBoundedValidator(lower=0.),
doc='Wavelength set for the data, will override nexus, intended for D16 reduction.')
def _normalise(self, ws, monID=None): def _normalise(self, ws, monID=None):
""" """
Normalizes the workspace by time (SampleLog Timer) or Monitor Normalizes the workspace by time (SampleLog Timer) or Monitor
...@@ -761,7 +765,11 @@ class SANSILLReduction(PythonAlgorithm): ...@@ -761,7 +765,11 @@ class SANSILLReduction(PythonAlgorithm):
progress = Progress(self, start=0.0, end=1.0, nreports=processes.index(process) + 1) progress = Progress(self, start=0.0, end=1.0, nreports=processes.index(process) + 1)
ws = '__' + self.getPropertyValue('OutputWorkspace') ws = '__' + self.getPropertyValue('OutputWorkspace')
if self.getPropertyValue('Run'): if self.getPropertyValue('Run'):
LoadAndMerge(Filename=self.getPropertyValue('Run').replace('+', ','), LoaderName='LoadILLSANS', OutputWorkspace=ws) loader_options = {}
if not self.getProperty('Wavelength').isDefault:
loader_options['Wavelength'] = self.getProperty('Wavelength').value
LoadAndMerge(Filename=self.getPropertyValue('Run').replace('+', ','), LoaderName='LoadILLSANS',
OutputWorkspace=ws, LoaderOptions=loader_options)
if isinstance(mtd[ws], WorkspaceGroup): if isinstance(mtd[ws], WorkspaceGroup):
# we do not want the summing done by LoadAndMerge since it will be pair-wise and slow # we do not want the summing done by LoadAndMerge since it will be pair-wise and slow
# instead we load and list, and merge once with merge runs # instead we load and list, and merge once with merge runs
......
4fc4ccc7bca8fce1b06bae7702a1226c
0d66584779dfb86d98b852545931ba44
d9ac1ce32bfa0a2ced559fd4a2aab33c
136af7320a24a35346b778ea7efbbf9b
71a8e72dde3940ec2aa8dd1ce0fd4897
4951f6fd137944c68467007bc0613625
4de49095f344b431277bb54334ebea3f
...@@ -650,6 +650,58 @@ class D16_AutoProcess_Test(systemtesting.MantidSystemTest): ...@@ -650,6 +650,58 @@ class D16_AutoProcess_Test(systemtesting.MantidSystemTest):
) )
class D16_AutoProcess_Test_cycle213(systemtesting.MantidSystemTest):
"""
Tests autoprocess with D16 data from cycle 213.
"""
def __init__(self):
super(D16_AutoProcess_Test_cycle213, self).__init__()
self.setUp()
def setUp(self):
config['default.facility'] = 'ILL'
config['default.instrument'] = 'D16'
config['logging.loggers.root.level'] = 'Warning'
config.appendDataSearchSubDir('ILL/D16/')
config['algorithms.retained'] = '0'
def cleanup(self):
mtd.clear()
def validate(self):
self.tolerance = 1e-3
self.tolerance_is_rel_err = True
self.disableChecking.append("Instrument")
return ['iq', 'D16_213_iq.nxs']
def runTest(self):
sample = "23389:23390"
transmission_sample = '23388'
beam = '23376'
transmission_beam = '23376'
absorber = '23380'
cell_background = '23359'
transmission_empty_cell = '23358'
# process the sample where wavelength is incorrectly defined in nexus
SANSILLAutoProcess(
SampleRuns=sample,
BeamRuns=beam,
DefaultMaskFile="side_mask",
MaskFiles="beam_mask, side_mask",
TransmissionBeamRuns=transmission_beam,
OutputWorkspace='iq',
ContainerTransmissionRuns=transmission_empty_cell,
SampleTransmissionRuns=transmission_sample,
ContainerRuns=cell_background,
AbsorberRuns=absorber,
ThetaDependent=False,
SampleThickness=0.6,
StitchReferenceIndex=0,
Wavelength=4.54
)
class D22_AutoProcess_Single_Sensitivity(systemtesting.MantidSystemTest): class D22_AutoProcess_Single_Sensitivity(systemtesting.MantidSystemTest):
""" """
Tests auto process with D22 data with one sensitivity measurement. Tests auto process with D22 data with one sensitivity measurement.
......
...@@ -244,8 +244,9 @@ class RundexSettings(object): ...@@ -244,8 +244,9 @@ class RundexSettings(object):
"WavelengthRange", "WavelengthRange",
"StitchReferenceIndex", "StitchReferenceIndex",
"ClearCorrected2DWorkspace", "ClearCorrected2DWorkspace",
"ShapeTable" "ShapeTable",
], "Wavelength"
],
SANS_PSCAN : [ SANS_PSCAN : [
"SensitivityMap", "SensitivityMap",
"DefaultMaskFile", "DefaultMaskFile",
......
Markdown is supported
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