Commit 01362b34 authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #30905 Added Period Info Button Along With New Widget

Updated the loadmuonnexus1 loader to read period information. Created a new widget for the period information. Need to deal with what happens when information cannot be found
parent f6f4b416
......@@ -88,6 +88,8 @@ protected:
specnum_t m_numberOfSpectra;
/// The number of periods in the raw file
int64_t m_numberOfPeriods;
/// The different pieces of information about periods
std::vector<std::string> m_periodInformation;
/// Has the spectrum_list property been set?
bool m_list;
/// Have the spectrum_min/max properties been set?
......
......@@ -97,10 +97,19 @@ void LoadMuonNexus::init() {
"Table or a group of tables containing detector dead times. Version 1 "
"only.");
declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("DetectorGroupingTable", "", Direction::Output,
PropertyMode::Optional),
"Table or a group of tables with information about the "
"detector grouping stored in the file (if any). Version 1 only.");
declareProperty(
std::make_unique<WorkspaceProperty<Workspace>>("DetectorGroupingTable",
"", Direction::Output,
PropertyMode::Optional),
"Table or a group of tables with information about the "
"detector grouping stored in the file (if any). Version 1 only.");
declareProperty(
std::make_unique<ArrayProperty<std::string>>("PeriodsInformation"),
"An array of strings which hold period information. This array is in the "
"format ['NumberOfSequences', 'Labels', 'TotalFrames']. Empty strings "
"show no value "
"could be read from file.");
}
/// Validates the optional 'spectra to read' properties, if they have been set
......
......@@ -141,6 +141,10 @@ void LoadMuonNexus1::exec() {
m_numberOfPeriods = nxload.t_nper;
}
// Read in period information
m_periodInformation = nxload.getPeriodInfo();
setProperty("PeriodsInformation", m_periodInformation);
bool autoGroup = getProperty("AutoGroup");
// Grouping info should be returned if user has set the property
......
......@@ -36,6 +36,8 @@ private:
int nexusLogCount; ///< number of NXlog sections read from file
std::vector<bool> logType; ///< true if i'th log is numeric
std::vector<std::string> logNames; ///< stores name read from file
std::vector<std::string>
m_periodInformation; /// stores the information of the periods
void openFirstNXentry(NeXus::File &handle);
bool readMuonLogData(NeXus::File &handle); ///< method to read the fields of open NXlog section
std::vector<std::vector<float>> logValues, ///< array of values for i'th NXlog section
......@@ -90,4 +92,5 @@ public:
int *detectorGroupings; ///< detector grouping info
int numDetectors; ///< detector count
std::string getInstrumentName() const; ///< return instrument name
std::vector<std::string> getPeriodInfo() const; /// Return period information
};
......@@ -122,7 +122,39 @@ void MuonNexusReader::readFromFile(const string &filename) {
// get instrument name
handle.openGroup("instrument", "NXinstrument");
handle.readData("name", nexus_instrument_name);
handle.closeGroup();
// Try to read in period information
std::vector<std::string> periodInformation{"period_sequences", "period_labels",
"frames_period_raw"};
try {
handle.openGroup("beam", "NXbeam");
for (const auto &info : periodInformation) {
try {
std::string tempString;
if (info == "period_sequences") {
int temp = 0;
handle.readData(info, temp);
tempString = std::to_string(temp);
} else if (info == "frames_period_raw") {
std::vector<int> temp;
handle.readData(info, temp);
for (const auto &value : temp)
tempString += std::to_string(value) + ";";
} else {
handle.readData(info, tempString);
}
m_periodInformation.emplace_back(tempString);
} catch (...) {
g_log.debug("Muon nexus file does not contain " + info);
m_periodInformation.emplace_back(std::string{""});
}
}
handle.closeGroup();
} catch (...) {
g_log.debug("Muon nexus file does not contain beam info");
}
handle.closeGroup(); // Close instrument group
// Get number of switching states if available. Take this as number of periods
// If not available set as one period.
......@@ -319,3 +351,7 @@ bool MuonNexusReader::logTypeNumeric(const int i) const { return (logType[i]); }
* @return the log name at the given index
*/
string MuonNexusReader::getLogName(const int i) const { return (logNames[i]); }
std::vector<std::string> MuonNexusReader::getPeriodInfo() const {
return m_periodInformation;
}
......@@ -79,6 +79,7 @@ class MuonDataContext(object):
self.instrumentNotifier = MuonDataContext.InstrumentNotifier(self)
self.message_notifier = MuonDataContext.MessageNotifier(self)
self.base_directory = base_directory
self.periods_info = []
def is_data_loaded(self):
return self._loaded_data.num_items() > 0
......
......@@ -296,3 +296,9 @@ class GroupingTabModel(object):
def get_periods(self, name):
return self._groups_and_pairs[name].periods
def get_period_labels(self):
return self._data.period_labels
def get_num_period_cycles(self):
return self._data.num_period_cycles
......@@ -12,6 +12,7 @@ from Muon.GUI.Common import thread_model
from Muon.GUI.Common.run_selection_dialog import RunSelectionDialog
from Muon.GUI.Common.thread_model_wrapper import ThreadModelWrapper
from Muon.GUI.Common.utilities.run_string_utils import run_string_to_list
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget
class GroupingTabPresenter(object):
......@@ -34,6 +35,7 @@ class GroupingTabPresenter(object):
self.grouping_table_widget = grouping_table_widget
self.pairing_table_widget = pairing_table_widget
self.diff_table = diff_table
self.period_info_widget = MuonPeriodInfoWidget()
self._view.set_description_text('')
self._view.on_add_pair_requested(self.add_pair_from_grouping_table)
......@@ -41,6 +43,7 @@ class GroupingTabPresenter(object):
self._view.on_load_grouping_button_clicked(self.handle_load_grouping_from_file)
self._view.on_save_grouping_button_clicked(self.handle_save_grouping_file)
self._view.on_default_grouping_button_clicked(self.handle_default_grouping_button_clicked)
self._view.on_period_information_button_clicked(self.handle_period_information_button_clicked)
# monitors for loaded data changing
self.loadObserver = GroupingTabPresenter.LoadObserver(self)
......@@ -277,6 +280,17 @@ class GroupingTabPresenter(object):
else: # else plot groups
self.grouping_table_widget.plot_default_case()
def handle_period_information_button_clicked(self):
if self._model._data.periods_info:
self._add_period_info_to_widget()
self.period_info_widget.show()
def _add_period_info_to_widget(self):
self.period_info_widget.number_of_sequences = self._model._data.periods_info[0]
total_frames = self._model._data.periods_info[2].split(';')
for index, name in enumerate(self._model._data.periods_info[1].split(';')):
self.period_info_widget.add_period_to_table(name, total_frames[index])
# ------------------------------------------------------------------------------------------------------------------
# Observer / Observable
# ------------------------------------------------------------------------------------------------------------------
......
......@@ -21,6 +21,7 @@ class GroupingTabView(QtWidgets.QWidget):
self.save_grouping_button = None
self.clear_grouping_button = None
self.default_grouping_button = None
self.period_information_button = None
self.vertical_layout = None
self.horizontal_layout_base = None
self.horizontal_layout_description = None
......@@ -64,12 +65,18 @@ class GroupingTabView(QtWidgets.QWidget):
self.default_grouping_button.setToolTip(
"Restore the default grouping for the currently selected instrument.")
self.period_information_button = QtWidgets.QPushButton(self)
self.period_information_button.setText("Periods")
self.period_information_button.setToolTip(
"Display a table with further information about the periods of the run(s)")
self.horizontal_layout = QtWidgets.QHBoxLayout()
self.horizontal_layout.setObjectName("horizontalLayout")
self.horizontal_layout.addWidget(self.load_grouping_button)
self.horizontal_layout.addWidget(self.save_grouping_button)
self.horizontal_layout.addWidget(self.clear_grouping_button)
self.horizontal_layout.addWidget(self.default_grouping_button)
self.horizontal_layout.addWidget(self.period_information_button)
self.horizontal_layout_base = QtWidgets.QHBoxLayout()
......@@ -112,6 +119,7 @@ class GroupingTabView(QtWidgets.QWidget):
self.save_grouping_button.setEnabled(enabled)
self.clear_grouping_button.setEnabled(enabled)
self.default_grouping_button.setEnabled(enabled)
self.period_information_button.setEnabled(enabled)
def set_grouping_table(self, table):
self._grouping_table = table
......@@ -193,3 +201,6 @@ class GroupingTabView(QtWidgets.QWidget):
def on_save_grouping_button_clicked(self, slot):
self.save_grouping_button.clicked.connect(slot)
def on_period_information_button_clicked(self, slot):
self.period_information_button.clicked.connect(slot)
......@@ -48,7 +48,7 @@ class BrowseFileWidgetModel(object):
failed_files = []
for filename in self._filenames:
try:
ws, run, filename, psi_data = load_utils.load_workspace_from_filename(filename)
ws, run, filename, psi_data, _ = load_utils.load_workspace_from_filename(filename)
except Exception as error:
failed_files += [(filename, error)]
continue
......
......@@ -31,7 +31,8 @@ class LoadRunWidgetModel(object):
failed_files = []
for filename in self._filenames:
try:
ws, run, filename, _ = load_utils.load_workspace_from_filename(filename)
ws, run, filename, _, period_info = load_utils.load_workspace_from_filename(filename)
self._data_context.periods_info = period_info
except ValueError as error:
failed_files += [(filename, error)]
continue
......
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright &copy; 2021 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from qtpy import QtWidgets, PYQT4, QtCore
from Muon.GUI.Common.utilities import table_utils
HEADERS = ["Period Number", "Name", "Total Frames"]
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
COLUMN_COUNT = 3
class MuonPeriodInfoWidget(QtWidgets.QWidget):
"""
This is a simple widget used by the Muon GUI's to display additional information about periods of a run.
"""
def __init__(self, parent=None):
super(MuonPeriodInfoWidget, self).__init__(parent)
self._label = None
self._table = None
self._number_of_sequencs = 0
# Create layout
self._create_layout()
@property
def number_of_sequences(self):
return self._number_of_sequences
@number_of_sequences.setter
def number_of_sequences(self, value):
self._number_of_sequences = value
if self.label:
if value:
self.label.setText("Run contains " + value + " cycles of periods")
else:
self.label.setText("Number of period cycles not found")
def add_period_to_table(self, name, total_frames):
row_num = self._num_rows()
self.table.insertRow(row_num)
self.table.setItem(row_num, 0, self._new_text_widget(str(row_num + 1))) # Set period number
self.table.setItem(row_num, 1, self._new_text_widget(name)) # Set name
self.table.setItem(row_num, 2, self._new_text_widget(total_frames)) # Set name
def _new_text_widget(self, text):
new_widget = table_utils.ValidatedTableItem(lambda text: True)
new_widget.setText(text)
new_widget.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
return new_widget
def _num_rows(self):
return self.table.rowCount()
def _create_layout(self):
self.label = QtWidgets.QLabel("Run contains 0 cycles of periods")
self.table = QtWidgets.QTableWidget(0, COLUMN_COUNT, parent=self)
self.table.setHorizontalHeaderLabels(HEADERS)
self.table.horizontalHeader().setStyleSheet(HEADER_STYLE)
self.table.verticalHeader().setVisible(False)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.table)
self.setLayout(self.layout)
self.setWindowTitle("Period Information")
......@@ -232,7 +232,7 @@ def load_workspace_from_filename(filename,
load_result["DeadTimeTable"] = None
load_result["FirstGoodData"] = round(load_result["FirstGoodData"] - load_result['TimeZero'], 3)
return load_result, run, filename, psi_data
return load_result, run, filename, psi_data, alg.getProperty("PeriodsInformation").value
def empty_loaded_data():
......
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