Skip to content

Commit

Permalink
Merge pull request mantidproject#20491 from mantidproject/20483_Indir…
Browse files Browse the repository at this point in the history
…ectDiffractionIncorrectRelationship

Indirect - Diffraction Reduction - Incorrect summing of files
  • Loading branch information
SimonHeybrock authored Sep 28, 2017
2 parents c70e249 + de5a219 commit 9dc74fa
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void export_FileFinder() {
"The hint can be a comma separated list of run numbers and can also "
"include ranges of runs, e.g. 123-135 or equivalently 123-35"
"If no instrument prefix is given then the current default is used.")
.def("getCaseSensitive", &FileFinderImpl::getCaseSensitive, (arg("self")),
"Option to get if file finder should be case sensitive.")
.def("setCaseSensitive", &FileFinderImpl::setCaseSensitive,
(arg("self"), arg("cs")),
"Option to set if file finder should be case sensitive.")
.def("Instance", &FileFinder::Instance,
return_value_policy<reference_existing_object>(),
"Returns a reference to the FileFinder singleton instance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os

from IndirectReductionCommon import load_files
from IndirectReductionCommon import load_files, load_file_ranges

from mantid.simpleapi import *
from mantid.api import *
Expand Down Expand Up @@ -128,16 +128,6 @@ def validateInputs(self):
logger.warning('type = ' + str(type(mode)))
issues['CalFile'] = 'Cal Files are currently only available for use in OSIRIS diffspec mode'

num_samples = len(input_files)
num_vanadium = len(self.getProperty('VanadiumFiles').value)
if num_samples != num_vanadium and num_vanadium != 0:
run_num_mismatch = 'You must input the same number of sample and vanadium runs'
issues['InputFiles'] = run_num_mismatch
issues['VanadiumFiles'] = run_num_mismatch

if self._grouping_method == 'Workspace' and self._grouping_workspace is None:
issues['GroupingWorkspace'] = 'Must select a grouping workspace for current GroupingWorkspace'

return issues

# ------------------------------------------------------------------------------
Expand All @@ -163,13 +153,13 @@ def PyExec(self):
load_opts['Mode'] = 'FoilOut'
load_opts['LoadMonitors'] = True

self._workspace_names, self._chopped_data = load_files(self._data_files,
self._ipf_filename,
self._spectra_range[0],
self._spectra_range[1],
sum_files=self._sum_files,
load_logs=self._load_logs,
load_opts=load_opts)
self._workspace_names, self._chopped_data = load_file_ranges(self._data_files,
self._ipf_filename,
self._spectra_range[0],
self._spectra_range[1],
sum_files=self._sum_files,
load_logs=self._load_logs,
load_opts=load_opts)

# applies the changes in the provided calibration file
self._apply_calibration()
Expand All @@ -182,10 +172,12 @@ def PyExec(self):
self._ipf_filename,
self._spectra_range[0],
self._spectra_range[1],
sum_files=self._sum_files,
load_logs=self._load_logs,
load_opts=load_opts)

if len(self._workspace_names) > len(self._vanadium_runs):
raise RuntimeError("There cannot be more sample runs than vanadium runs.")

for index, c_ws_name in enumerate(self._workspace_names):
is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

Expand Down Expand Up @@ -283,13 +275,11 @@ def PyExec(self):

# Remove the container workspaces
if self._container_workspace is not None:
DeleteWorkspace(self._container_workspace)
DeleteWorkspace(self._container_workspace + '_mon')
self._delete_all([self._container_workspace])

# Remove the vanadium workspaces
if self._vanadium_ws:
for van_ws in self._vanadium_ws:
DeleteWorkspace(van_ws)
DeleteWorkspace(van_ws+'_mon')
self._delete_all(self._vanadium_ws)

# Rename output workspaces
output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]
Expand All @@ -306,7 +296,6 @@ def _setup(self):
"""
Gets algorithm properties.
"""

self._output_ws = self.getPropertyValue('OutputWorkspace')
self._data_files = self.getProperty('InputFiles').value
self._container_data_files = self.getProperty('ContainerFiles').value
Expand Down Expand Up @@ -340,17 +329,10 @@ def _setup(self):
self._ipf_filename = os.path.join(config['instrumentDefinition.directory'], self._ipf_filename)
logger.information('IPF filename is: %s' % self._ipf_filename)

if len(self._data_files) == 1:
logger.warning('SumFiles options has no effect when only one file is provided')
# Only enable sum files if we actually have more than one file
sum_files = self.getProperty('SumFiles').value
self._sum_files = False

if sum_files:
num_raw_files = len(self._data_files)
if num_raw_files > 1:
self._sum_files = True
logger.information('Summing files enabled (have %d files)' % num_raw_files)
else:
logger.information('SumFiles options is ignored when only one file is provided')
self._sum_files = self.getProperty('SumFiles').value

def _apply_calibration(self):
"""
Expand Down Expand Up @@ -388,6 +370,19 @@ def _load_and_scale_container(self, scale_factor, load_opts):
Factor=scale_factor,
Operation='Multiply')

def _delete_all(self, workspace_names):
"""
Deletes the workspaces with the specified names and their associated
monitor workspaces.
:param workspace_names: The names of the workspaces to delete.
"""

for workspace_name in workspace_names:
DeleteWorkspace(workspace_name)

if mtd.doesExist(workspace_name + "_mon"):
DeleteWorkspace(workspace_name + '_mon')

# ------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ def validateInputs(self):

num_samples = len(self._sample_runs)
num_vanadium = len(self._vanadium_runs)
if num_samples != num_vanadium:
run_num_mismatch = 'You must input the same number of sample and vanadium runs'

if num_samples > num_vanadium:
run_num_mismatch = 'You must input at least as many vanadium files as sample files'
issues['Sample'] = run_num_mismatch
issues['Vanadium'] = run_num_mismatch
if self._container_files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
from mantid.simpleapi import *
from mantid.api import *
from mantid.kernel import config


class ISISIndirectDiffractionReductionTest(unittest.TestCase):
Expand Down Expand Up @@ -73,23 +74,26 @@ def test_sum_files(self):
"""
Test summing multiple runs.
"""
cs = FileFinder.Instance().getCaseSensitive()

wks = ISISIndirectDiffractionReduction(InputFiles=['IRS26176.RAW', 'IRS26173.RAW'],
FileFinder.Instance().setCaseSensitive(False)
wks = ISISIndirectDiffractionReduction(InputFiles=['26173-26176'],
SumFiles=True,
Instrument='IRIS',
Mode='diffspec',
SpectraRange=[105, 112])
FileFinder.Instance().setCaseSensitive(cs)

self.assertTrue(isinstance(wks, WorkspaceGroup), 'Result workspace should be a workspace group.')
self.assertEqual(len(wks), 1)
self.assertEqual(wks.getNames()[0], 'iris26176_multi_diffspec_red')
self.assertEqual(wks.getNames()[0], 'iris26173_multi_diffspec_red')

red_ws = wks[0]
self.assertEqual(red_ws.getAxis(0).getUnit().unitID(), 'dSpacing')
self.assertEqual(red_ws.getNumberHistograms(), 1)

self.assertTrue('multi_run_numbers' in red_ws.getRun())
self.assertEqual(red_ws.getRun().get('multi_run_numbers').value, '26176,26173')
self.assertEqual(red_ws.getRun().get('multi_run_numbers').value, '26173,26174,26175,26176')

def test_grouping_individual(self):
"""
Expand Down
1 change: 1 addition & 0 deletions Testing/Data/UnitTest/IRS26174.RAW.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
94e0fbf798a1b3c3d8718dfe4ebcaab3
1 change: 1 addition & 0 deletions Testing/Data/UnitTest/IRS26175.RAW.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
019aa1211f82d2fc383dcd64e8679bb9
13 changes: 10 additions & 3 deletions docs/source/release/v3.11.0/indirect_inelastic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ Elwin
Bugfixes
--------
- Save Result now writes to file the temperature-dependent elastic intensity normalized to the lowest temperature.
- Added 'ExtractMembers' property to ConvolutionFitSequential algorithm - this allows for extracting the members of the
convolution fitting into their own workspaces.

ConvFit
~~~~~~~

Improvements
------------
- Added 'ExtractMembers' property to ConvolutionFitSequential algorithm - this allows for extracting the members of the
convolution fitting into their own workspaces.

Bugfixes
--------
- Correct treatment of the resolution function: convolve sample and resolution spectra with same momentum transfer.
- Property to pass the workspace index added to :ref:`algm-ConvolutionFitSequential`.


MSDFit
~~~~~~

Expand Down Expand Up @@ -82,5 +84,10 @@ Bugfixes
- An issue has been fixed in :ref:`algm-IndirectILLEnergyTransfer` when handling the data with mirror sense, that have shifted 0 monitor counts in the left and right wings. This was causing the left and right workspaces to have different x-axis binning and to fail to sum during the unmirroring step.
- An issue has been fixed in :ref:`algm-IndirectILLReductionFWS` when the scaling of the data after vanadium calibration was not applied.
- :ref:`algm-CalculateSampleTransmission` now divides by the tabulated wavelength when calculating the absorption cross section.
- The Sum Files option in the Indirect Diffraction Reduction interface now allows for correctly corresponding each sum of
sample runs defined with a range (e.g. A-B, where A and B are run numbers) to the corresponding vanadium run, dependent on D-Range.
- The 'Sample Runs' field in the Indirect Diffraction Interface now recognizes 3 operators: '-', '+', ':'. The '-' operator is used
to supply a given range of runs and sum them when SumFiles is checked. The '+' operator is used to supply a given list of runs and
sum when SumFiles is checked. The ':' operator is used to supply a range of runs, which will never be summed.

`Full list of changes on GitHub <http://github.com/mantidproject/mantid/pulls?q=is%3Apr+milestone%3A%22Release+3.11%22+is%3Amerged+label%3A%22Component%3A+Indirect+Inelastic%22>`_
16 changes: 13 additions & 3 deletions qt/scientific_interfaces/Indirect/IndirectDiffractionReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ void IndirectDiffractionReduction::run() {
showInformationBox("Sample files input is invalid.");
return;
}

if (mode == "diffspec" && m_uiForm.ckUseVanadium->isChecked() &&
m_uiForm.rfVanFile_only->getFilenames().isEmpty()) {
showInformationBox("Use Vanadium File checked but no vanadium files "
"have been supplied.");
return;
}

if (instName == "OSIRIS") {
if (mode == "diffonly") {
if (!validateVanCal()) {
Expand Down Expand Up @@ -145,7 +153,10 @@ void IndirectDiffractionReduction::algorithmComplete(bool error) {
// Handles completion of the diffraction algorithm chain
disconnect(m_batchAlgoRunner, 0, this, SLOT(algorithmComplete(bool)));

deleteGroupingWorkspace();
// Delete grouping workspace, if created.
if (AnalysisDataService::Instance().doesExist(m_groupingWsName)) {
deleteGroupingWorkspace();
}

if (error) {
showInformationBox(
Expand Down Expand Up @@ -364,8 +375,7 @@ void IndirectDiffractionReduction::runGenericReduction(QString instName,
msgDiffReduction->setProperty("LoadLogFiles",
m_uiForm.ckLoadLogs->isChecked());
msgDiffReduction->setProperty(
"InputFiles",
m_uiForm.rfSampleFiles->getFilenames().join(",").toStdString());
"InputFiles", m_uiForm.rfSampleFiles->getText().toStdString());
msgDiffReduction->setProperty("SpectraRange", detRange);
msgDiffReduction->setProperty("RebinParam", rebin.toStdString());
msgDiffReduction->setProperty("OutputWorkspace",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<item row="2" column="2">
<widget class="QCheckBox" name="ckSumFiles">
<property name="text">
<string>Sum Files</string>
<string>Sum Sample Files</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -201,7 +201,7 @@
<item row="5" column="0">
<widget class="QCheckBox" name="ckManualDRange">
<property name="text">
<string>Manual dRange:</string>
<string>Manual dRange (Vanadium):</string>
</property>
</widget>
</item>
Expand Down
Loading

0 comments on commit 9dc74fa

Please sign in to comment.