Skip to content

Commit

Permalink
Skip reflectivity calculation for direct beams (#115)
Browse files Browse the repository at this point in the history
* skip calculating the reflectivity of runs whose metadata categorize them as direct beam
  • Loading branch information
backmari authored Dec 11, 2024
1 parent 7541817 commit 2f765c1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/releasenotes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Notes for major and minor releases. Notes for Patch releases are deferred.

**Of interest to the User**:

- PR #115: Skip reflectivity calculation for direct beams
- PR #104: Update Mantid version to 6.10
- PR #95: Optional dead-time correction (disabled by default)
- PR #91: Add ability to reduce multiple samples from the same run
Expand Down
4 changes: 4 additions & 0 deletions reflectivity_ui/interfaces/data_handling/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ def load(self, update_parameters=True, progress=None):

return self.cross_sections

def is_direct_beam(self):
"""Returns True if the main cross-section is a direct beam"""
return self.cross_sections[self.main_cross_section].is_direct_beam


class CrossSectionData(object):
"""
Expand Down
9 changes: 5 additions & 4 deletions reflectivity_ui/interfaces/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,11 @@ def load(self, file_path, configuration, force=False, update_parameters=True, pr
self.direct_beam_list[direct_beam_list_id] = nexus_data

# Compute reflectivity
try:
self.calculate_reflectivity()
except Exception as e:
logging.error("Reflectivity calculation failed for %s exception %s", file_name, e)
if not nexus_data.is_direct_beam():
try:
self.calculate_reflectivity()
except Exception as e:
logging.error("Reflectivity calculation failed for %s exception %s", file_name, e)

# if cached reduced data exceeds maximum cache size, remove the oldest reduced data
while len(self._cache) >= self.MAX_CACHE:
Expand Down
8 changes: 3 additions & 5 deletions test/ui/test_missing_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def test_missing_cross_section(qtbot):
intensity_off_on = np.sum(ui_utilities.data_from_plot2D(main_window.xtof_overview))
# select the On-On spin combination
main_window.selectedChannel1.click()
# check that the reflectivity curve is empty
_, data_y = ui_utilities.data_from_plot1D(main_window.refl)
test = data_y.data - data_y.data[0]
assert np.all(test <= TEST_REFLECTIVITY_THRESHOLD_VALUE)
tmp = ui_utilities.data_from_plot2D(main_window.xtof_overview)
# check that no reflectivity curve is displayed
plot_text = ui_utilities.text_from_plot1D(main_window.refl)
assert plot_text == "No data"
# check the x vs TOF plot has changed
intensity_on_on = np.sum(ui_utilities.data_from_plot2D(main_window.xtof_overview))
assert intensity_on_on / intensity_off_on < TEST_REFLECTIVITY_THRESHOLD_VALUE
Expand Down
18 changes: 18 additions & 0 deletions test/ui/ui_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


# third party imports
import matplotlib.pyplot as plt
from numpy.ma import MaskedArray
from PyQt5 import QtCore

Expand Down Expand Up @@ -47,6 +48,23 @@ def data_from_plot2D(widget: "MplWidget") -> MaskedArray:
return axes.get_images()[0].get_array()


def text_from_plot1D(widget: "MplWidget", line_number=0) -> tuple:
r"""Get the text from an MplWidget representing a 1D plot
Returns
-------
str
The first text that is not a title or label
"""
figure = widget.canvas.fig
axes = figure.get_axes()[0]
texts = [
child
for child in axes.get_children()
if isinstance(child, plt.Text) and child not in [axes.title, axes.xaxis.label, axes.yaxis.label]
]
return texts[0].get_text()


def set_current_file_by_run_number(widget, run_number):
r"""Set the selected file in the main window file list by the given run number"""
list_item = widget.file_list.findItems(str(run_number), QtCore.Qt.MatchContains)[0]
Expand Down

0 comments on commit 2f765c1

Please sign in to comment.