Skip to content
Snippets Groups Projects
Unverified Commit d78ab2e4 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #28193 from mantidproject/28181_Dont_try_to_mask_missing_ws_spectra

Dont try to mask missing ws spectra
parents d44ccb8e ab048f45
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,14 @@ SANS Changes
.. contents:: Table of Contents
:local:
Bug Fixed
#########
- Applying a mask to a range of spectra after cropping to a bank could fail
if there were gaps in the spectrum numbers. The masking will now skip
over any spectrum numbers not in workspace and emit a warning.
.. warning:: **Developers:** Sort changes under appropriate heading
putting new features at the top of the section, followed by
improvements, followed by bug fixes.
......
......@@ -10,6 +10,8 @@ from abc import (ABCMeta, abstractmethod)
from six import with_metaclass
from mantid.kernel import Logger
from sans.algorithm_detail.mask_functions import SpectraBlock
from sans.algorithm_detail.xml_shapes import (add_cylinder, add_outside_cylinder, create_phi_mask, create_line_mask)
from sans.common.constants import EMPTY_NAME
......@@ -260,17 +262,31 @@ def mask_spectra(mask_info, workspace, spectra_block, detector_type):
for horizontal, vertical in zip(block_cross_horizontal, block_cross_vertical):
total_spectra.extend(spectra_block.get_block(horizontal, vertical, 1, 1))
if not total_spectra:
return workspace
# Perform the masking
if total_spectra:
mask_name = "MaskSpectra"
mask_options = {"InputWorkspace": workspace,
"InputWorkspaceIndexType": "SpectrumNumber",
"OutputWorkspace": "__dummy"}
mask_alg = create_unmanaged_algorithm(mask_name, **mask_options)
mask_alg.setProperty("InputWorkspaceIndexSet", list(set(total_spectra)))
mask_alg.setProperty("OutputWorkspace", workspace)
mask_alg.execute()
workspace = mask_alg.getProperty("OutputWorkspace").value
ws_spectra_list = workspace.getSpectrumNumbers()
# Any gaps in the spectra list we skip over attempting to mask
filtered_mask_spectra = [spec for spec in total_spectra if spec in ws_spectra_list]
if len(filtered_mask_spectra) != len(total_spectra):
log = Logger("SANS - Mask Workspace")
log.warning("Skipped masking some spectrum numbers that do not exist in the workspace. Re-run"
" with logging set to information for more details")
log.information("The following spectrum numbers do not exist in the ws (cropped to component):")
for i in list(set(total_spectra) - set(filtered_mask_spectra)):
log.information(str(i))
mask_name = "MaskSpectra"
mask_options = {"InputWorkspace": workspace,
"InputWorkspaceIndexType": "SpectrumNumber",
"OutputWorkspace": "__dummy"}
mask_alg = create_unmanaged_algorithm(mask_name, **mask_options)
mask_alg.setProperty("InputWorkspaceIndexSet", list(set(filtered_mask_spectra)))
mask_alg.setProperty("OutputWorkspace", workspace)
mask_alg.execute()
workspace = mask_alg.getProperty("OutputWorkspace").value
return workspace
......
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