Commit b6d781ff authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #30905 Added Counts

Added new column called counts, this only applies to DAQ periods.
parent e693dc7b
......@@ -108,7 +108,7 @@ void LoadMuonNexus::init() {
std::make_unique<ArrayProperty<std::string>>("PeriodsInformation"),
"An array of strings which hold period information. This array is in the "
"format ['NumberOfSequences', 'Labels', 'Type', 'Frames', "
"'TotalFrames']. Empty "
"'TotalFrames', 'Counts']. Empty "
"strings "
"show no value "
"could be read from file.");
......
......@@ -126,24 +126,30 @@ void MuonNexusReader::readFromFile(const string &filename) {
// Try to read in period information
std::vector<std::string> periodInformation{
"period_sequences", "period_labels", "period_type",
"frames_period_requested", "frames_period_raw"};
"frames_period_requested", "frames_period_raw", "total_counts_period"};
try {
handle.openGroup("beam", "NXbeam");
for (const auto &info : periodInformation) {
try {
std::string tempString;
if (info == "period_sequences") {
if (info == "period_sequences") { // Int data
int temp = 0;
handle.readData(info, temp);
tempString = std::to_string(temp);
} else if (info == "frames_period_requested" ||
info == "frames_period_raw" || info == "period_type") {
info == "frames_period_raw" || info == "period_type") { // Int array data
std::vector<int> temp;
handle.readData(info, temp);
for (const auto &value : temp)
tempString += std::to_string(value) + ";";
tempString.erase(tempString.length() - 1); // Remove final ;
} else {
} else if (info == "total_counts_period"){ // Float array data
std::vector<float> temp;
handle.readData(info, temp);
for (const auto &value : temp)
tempString += std::to_string(value) + ";";
tempString.erase(tempString.length() - 1); // Remove final ;
} else { // String data
handle.readData(info, tempString);
}
m_periodInformation.emplace_back(tempString);
......
......@@ -15,6 +15,7 @@ Muon Analysis 2 and Frequency Domain Analysis
New Features
############
- Added a new "periods" button to the grouping tab which displays a table of information on periods (currently only supporting nexus V1 files).
Improvements
############
......
......@@ -12,7 +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, CONTEXT_MAP, PERIOD_INFO_NOT_FOUND
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget, CONTEXT_MAP, PERIOD_INFO_NOT_FOUND, INFO_DELIM
class GroupingTabPresenter(object):
......@@ -288,39 +288,27 @@ class GroupingTabPresenter(object):
def _add_period_info_to_widget(self):
self.period_info_widget.number_of_sequences = self._model._data.periods_info[0]
names = self._model._data.periods_info[CONTEXT_MAP["Name"]].split(';')
types = self._model._data.periods_info[CONTEXT_MAP["Type"]].split(';')
frames = self._model._data.periods_info[CONTEXT_MAP["Frames"]].split(';')
total_frames = self._model._data.periods_info[CONTEXT_MAP["Total Good Frames"]].split(';')
names, types, frames, total_frames, count = self._fix_up_period_info_lists(names, types, frames, total_frames)
names = self._model._data.periods_info[CONTEXT_MAP["Name"]].split(INFO_DELIM)
types = self._model._data.periods_info[CONTEXT_MAP["Type"]].split(INFO_DELIM)
frames = self._model._data.periods_info[CONTEXT_MAP["Frames"]].split(INFO_DELIM)
total_frames = self._model._data.periods_info[CONTEXT_MAP["Total Good Frames"]].split(INFO_DELIM)
counts = self._model._data.periods_info[CONTEXT_MAP["Counts"]].split(INFO_DELIM)
names, types, frames, total_frames, counts, count = self._fix_up_period_info_lists([names, types, frames, total_frames, counts])
for i in range(count):
self.period_info_widget.add_period_to_table(names[i], types[i], frames[i], total_frames[i])
self.period_info_widget.add_period_to_table(names[i], types[i], frames[i], total_frames[i], counts[self.period_info_widget.daq_count])
def _fix_up_period_info_lists(self, names, types, frames, total_frames):
def _fix_up_period_info_lists(self, info_list):
# First find number of periods
count = max(len(names), len(frames), len(total_frames))
lengths_list = [len(i) for i in info_list]
count = max(lengths_list)
# Then make sure lists are correct size
if len(names) != count:
if names[0] == "":
names = [PERIOD_INFO_NOT_FOUND] * count
else:
names += [PERIOD_INFO_NOT_FOUND] * count-len(names)
if len(types) != count:
if types[0] == "":
types = [PERIOD_INFO_NOT_FOUND] * count
else:
types += [PERIOD_INFO_NOT_FOUND] * count-len(types)
if len(frames) != count:
if frames[0] == "":
frames = [PERIOD_INFO_NOT_FOUND] * count
else:
frames += [PERIOD_INFO_NOT_FOUND] * count - len(frames)
if len(total_frames) != count:
if total_frames[0] == "":
total_frames = [PERIOD_INFO_NOT_FOUND] * count
else:
total_frames += [PERIOD_INFO_NOT_FOUND] * count - len(total_frames)
return names, types, frames, total_frames, count
for info in info_list:
if len(info) != count:
if info[0] == "":
info = [PERIOD_INFO_NOT_FOUND] * count
else:
info += [PERIOD_INFO_NOT_FOUND] * (count-len(info))
return *info_list, count
# ------------------------------------------------------------------------------------------------------------------
# Observer / Observable
......
......@@ -7,24 +7,27 @@
from qtpy import QtWidgets, PYQT4, QtCore
from Muon.GUI.Common.utilities import table_utils
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Good Frames"]
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Good Frames", "Counts"]
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
COLUMN_COUNT = 6
COLUMN_COUNT = 7
HEADER_COLUMN_MAP = {"Period Number": 0,
"Name": 1,
"Type": 2,
"DAQ Number": 3,
"Frames": 4,
"Total Good Frames": 5}
"Total Good Frames": 5,
"Counts": 6}
CONTEXT_MAP = {"Name": 1,
"Type": 2,
"Frames": 3,
"Total Good Frames": 4}
"Total Good Frames": 4,
"Counts": 5}
PERIOD_INFO_NOT_FOUND = "Not found"
DWELL_STRING = "-"
NOT_DAQ_STRING = "-"
DAQ = "1"
DWELL = "2"
CYCLES_NOT_FOUND = "Number of period cycles not found"
INFO_DELIM = ';'
class MuonPeriodInfoWidget(QtWidgets.QWidget):
......@@ -58,7 +61,11 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
else:
self._label.setText(CYCLES_NOT_FOUND)
def add_period_to_table(self, name, period_type, frames, total_frames):
@property
def daq_count(self):
return self._daq_count
def add_period_to_table(self, name, period_type, frames, total_frames, counts):
row_num = self._num_rows()
self._table.insertRow(row_num)
self._table.setItem(row_num, HEADER_COLUMN_MAP["Period Number"], self._new_text_widget(str(row_num + 1)))
......@@ -67,9 +74,11 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
self._daq_count += 1
self._table.setItem(row_num, HEADER_COLUMN_MAP["Type"], self._new_text_widget("DAQ"))
self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(str(self._daq_count)))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Counts"], self._new_text_widget(counts))
elif period_type == DWELL:
self._table.setItem(row_num, HEADER_COLUMN_MAP["Type"], self._new_text_widget("DWELL"))
self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(DWELL_STRING))
self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(NOT_DAQ_STRING))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Counts"], self._new_text_widget(NOT_DAQ_STRING))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Frames"], self._new_text_widget(frames))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Total Good Frames"], self._new_text_widget(total_frames))
......
......@@ -7,7 +7,7 @@
import unittest
from mantidqt.utils.qt.testing import start_qapplication
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget, CYCLES_NOT_FOUND, DAQ, DWELL, DWELL_STRING
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget, CYCLES_NOT_FOUND, DAQ, DWELL, NOT_DAQ_STRING
@start_qapplication
......@@ -15,13 +15,14 @@ class MuonPeriodInfoWidgetTest(unittest.TestCase):
def setUp(self):
self.widget = MuonPeriodInfoWidget()
def assert_row_values(self, row_num, period_number, name, type, daq_number, frames, total_frames):
def assert_row_values(self, row_num, period_number, name, type, daq_number, frames, total_frames, counts):
self.assertEqual(period_number, self.widget._table.item(row_num, 0).text())
self.assertEqual(name, self.widget._table.item(row_num, 1).text())
self.assertEqual(type, self.widget._table.item(row_num, 2).text())
self.assertEqual(daq_number, self.widget._table.item(row_num, 3).text())
self.assertEqual(frames, self.widget._table.item(row_num, 4).text())
self.assertEqual(total_frames, self.widget._table.item(row_num, 5).text())
self.assertEqual(counts, self.widget._table.item(row_num, 6).text())
def test_empty_on_initialize(self):
self.assertEqual(True, self.widget.is_empty())
......@@ -30,20 +31,20 @@ class MuonPeriodInfoWidgetTest(unittest.TestCase):
self.assertEqual(True, self.widget.is_empty())
def test_add_entry(self):
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000")
self.widget.add_period_to_table("state 1", DAQ, "10", "200")
self.assert_row_values(0, "1", "state 1 dwell", "DWELL", DWELL_STRING, "50", "1000")
self.assert_row_values(1, "2", "state 1", "DAQ", "1", "10", "200")
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25")
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25")
self.assert_row_values(0, "1", "state 1 dwell", "DWELL", NOT_DAQ_STRING, "50", "1000", NOT_DAQ_STRING)
self.assert_row_values(1, "2", "state 1", "DAQ", "1", "10", "200", "25")
self.assertEqual(2, self.widget._num_rows())
self.assertEqual(False, self.widget.is_empty())
def test_daq_count_increases_correctly(self):
self.widget.add_period_to_table("state 1", DAQ, "10", "200")
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25")
self.assertEqual(1, self.widget._daq_count)
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000")
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25")
self.assertEqual(1, self.widget._daq_count)
self.widget.add_period_to_table("state 2", DAQ, "10", "200")
self.widget.add_period_to_table("state 3", DAQ, "10", "200")
self.widget.add_period_to_table("state 2", DAQ, "10", "200", "25")
self.widget.add_period_to_table("state 3", DAQ, "10", "200", "25")
self.assertEqual(3, self.widget._daq_count)
def test_number_of_sequences_when_empty(self):
......
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