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

Re #30905 Changed loader to use sample logs instead

parent aacb0b70
......@@ -73,6 +73,10 @@ protected:
virtual void runLoadInstrumentFromNexus(DataObjects::Workspace2D_sptr) {}
void checkOptionalProperties();
void runLoadInstrument(const DataObjects::Workspace2D_sptr &);
Mantid::API::Algorithm_sptr createSampleLogAlgorithm(DataObjects::Workspace2D_sptr &ws);
void addToSampleLog(const std::string &logName, const int logNumber, DataObjects::Workspace2D_sptr &ws);
void addToSampleLog(const std::string &logName, const std::string log, DataObjects::Workspace2D_sptr &ws);
void addToSampleLog(const std::string &logName, const std::vector<int> logs, DataObjects::Workspace2D_sptr &ws);
/// The name and path of the input file
std::string m_filename;
......
......@@ -101,12 +101,6 @@ void LoadMuonNexus::init() {
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", Direction::Output),
"An array of strings which hold period information. This array is in the "
"format ['NumberOfSequences', 'Type', 'Frames', "
"'TotalFrames', 'Tag', 'Counts', 'Labels']. Strings are separated by ';' and empty "
"strings show no value could be read from file.");
}
/// Validates the optional 'spectra to read' properties, if they have been set
......@@ -178,5 +172,33 @@ int LoadMuonNexus::confidence(Kernel::NexusDescriptor &descriptor) const {
return 0; // Not to be used but LoadMuonNexus2, which inherits from this will
}
/**
*
*/
Mantid::API::Algorithm_sptr LoadMuonNexus::createSampleLogAlgorithm(DataObjects::Workspace2D_sptr &ws) {
Mantid::API::Algorithm_sptr logAlg = createChildAlgorithm("AddSampleLog");
logAlg->setProperty("Workspace", ws);
return logAlg;
}
/**
*/
void LoadMuonNexus::addToSampleLog(const std::string &logName, const int logNumber, DataObjects::Workspace2D_sptr &ws) {
auto alg = createSampleLogAlgorithm(ws);
alg->setProperty("LogType", "Number");
alg->setProperty("NumberType", "Int");
alg->setProperty("LogName", logName);
alg->setProperty("LogText", std::to_string(logNumber));
alg->executeAsChildAlg();
}
void LoadMuonNexus::addToSampleLog(const std::string &logName, const std::string logString,
DataObjects::Workspace2D_sptr &ws) {
auto alg = createSampleLogAlgorithm(ws);
alg->setProperty("LogType", "String");
alg->setProperty("LogName", logName);
alg->setProperty("LogText", logString);
alg->executeAsChildAlg();
}
} // namespace DataHandling
} // namespace Mantid
......@@ -141,10 +141,6 @@ 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
......@@ -235,6 +231,12 @@ void LoadMuonNexus1::exec() {
}
addPeriodLog(localWorkspace, period);
addGoodFrames(localWorkspace, period, nxload.t_nper);
addToSampleLog("period_sequences", nxload.m_numPeriodSequences, localWorkspace);
addToSampleLog("period_labels", nxload.m_periodNames, localWorkspace);
addToSampleLog("period_type", nxload.m_periodTypes, localWorkspace);
addToSampleLog("frames_period_requested", nxload.m_framesPeriodsRequested, localWorkspace);
addToSampleLog("frames_period_raw", nxload.m_framesPeriodsRaw, localWorkspace);
addToSampleLog("period_output", nxload.m_periodsOutput, localWorkspace);
size_t counter = 0;
for (auto i = m_spec_min; i < m_spec_max; ++i) {
......
......@@ -60,10 +60,16 @@ private:
boost::posix_time::ptime start(boost::gregorian::date(1970, 1, 1));
return (t - start).total_seconds();
}
void readIntPeriodInfo(NeXus::File &handle);
void readIntArrayPeriodInfo(NeXus::File &handle);
void readFloatArrayPeriodInfo(NeXus::File &handle);
void readStringPeriodInfo(NeXus::File &handle);
void readPeriodInfo(NeXus::File &handle);
template <class T> std::string convertVectorToString(T values, std::string delim) {
std::string result("");
if (!values.empty()) {
for (const auto &value : values)
result += std::to_string(value) + delim;
result.erase(result.length() - 1); // Remove final delim
}
return result;
}
public:
/// Default constructor
......@@ -96,4 +102,11 @@ public:
int m_numDetectors; ///< detector count
std::string getInstrumentName() const; ///< return instrument name
std::vector<std::string> getPeriodInfo() const; /// Return period information
int m_numPeriodSequences;
std::string m_periodNames;
std::string m_periodTypes;
std::string m_framesPeriodsRequested;
std::string m_framesPeriodsRaw;
std::string m_periodsOutput;
std::string m_periodsCounts;
};
......@@ -7,6 +7,8 @@
#include "MantidNexus/MuonNexusReader.h"
#include "MantidKernel/System.h"
#include <array>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/scoped_array.hpp>
#include <nexus/NeXusException.hpp>
#include <sstream>
......@@ -33,6 +35,14 @@ const std::array<std::string, 4> PERIOD_INFO_INT_ARRAY{"period_type", "frames_pe
"period_output"};
const std::array<std::string, 1> PERIOD_INFO_FLOAT_ARRAY{"total_counts_period"};
const std::array<std::string, 1> PERIOD_INFO_STRING{"period_labels"};
const std::string PERIOD_SEQUENCES("period_sequences");
const std::string PERIOD_TYPE("period_type");
const std::string FRAMES_PERIOD_REQUESTED("frames_period_requested");
const std::string FRAMES_PERIOD_RAW("frames_period_raw");
const std::string PERIOD_OUTPUT("period_output");
const std::string TOTAL_COUNTS_PERIOD("total_counts_period");
const std::string PERIOD_LABELS("period_labels");
} // namespace
using namespace Mantid;
......@@ -40,7 +50,7 @@ using namespace Mantid;
/// Default constructor
MuonNexusReader::MuonNexusReader()
: m_nexusInstrumentName(), m_nexusSampleName(), m_nexusLogCount(0), m_startTime_time_t(), t_nsp1(0), t_ntc1(0),
t_nper(0), m_numDetectors(0) {}
t_nper(0), m_numDetectors(0), m_numPeriodSequences(0) {}
/// Destructor deletes temp storage
MuonNexusReader::~MuonNexusReader() {}
......@@ -127,11 +137,7 @@ void MuonNexusReader::readFromFile(const string &filename) {
// Try to read in period information
try {
handle.openGroup("beam", "NXbeam");
// Loop each data type and add to info
readIntPeriodInfo(handle);
readIntArrayPeriodInfo(handle);
readFloatArrayPeriodInfo(handle);
readStringPeriodInfo(handle);
readPeriodInfo(handle);
handle.closeGroup();
} catch (...) {
g_log.debug("Muon nexus file does not contain beam info");
......@@ -155,70 +161,70 @@ void MuonNexusReader::readFromFile(const string &filename) {
// file will close on leaving the function
}
// Functions to read different types of period information from Nexus File handle
void MuonNexusReader::readIntPeriodInfo(NeXus::File &handle) {
for (const auto &intInfo : PERIOD_INFO_INT) {
try {
int temp = 0;
handle.readData(intInfo, temp);
m_periodInformation.emplace_back(std::string{std::to_string(temp)});
} catch (...) {
g_log.debug("Muon nexus file does not contain " + intInfo);
m_periodInformation.emplace_back(std::string{""});
}
/**
* Try to read in vairous peices of period information.
* Period info includes:
* - Period sequences
* - Period Names
* - Period type
* - Frames periods requested
* - Raw frames
* - Tag
* - Total counts per period
* const std::array<std::string, 1> PERIOD_INFO_INT{"period_sequences"};
const std::array<std::string, 4> PERIOD_INFO_INT_ARRAY{"period_type", "frames_period_requested", "frames_period_raw",
"period_output"};
const std::array<std::string, 1> PERIOD_INFO_FLOAT_ARRAY{"total_counts_period"};
const std::array<std::string, 1> PERIOD_INFO_STRING{"period_labels"};
*/
void MuonNexusReader::readPeriodInfo(NeXus::File &handle) {
int tempInt;
std::string tempString;
std::vector<int> tempIntVector;
std::vector<float> tempFloatVector;
try {
handle.readData(PERIOD_SEQUENCES, tempInt);
m_numPeriodSequences = tempInt;
} catch (...) {
g_log.debug("Muon nexus file does not contain " + PERIOD_SEQUENCES);
}
};
void MuonNexusReader::readIntArrayPeriodInfo(NeXus::File &handle) {
for (const auto &intArrayInfo : PERIOD_INFO_INT_ARRAY) {
try {
std::vector<int> temp;
std::string tempString = "";
handle.readData(intArrayInfo, temp);
if (!temp.empty()) {
for (const auto &value : temp)
tempString += std::to_string(value) + ";";
tempString.erase(tempString.length() - 1); // Remove final ;
}
m_periodInformation.emplace_back(tempString);
} catch (...) {
g_log.debug("Muon nexus file does not contain " + intArrayInfo);
m_periodInformation.emplace_back(std::string{""});
}
try {
handle.readData(PERIOD_LABELS, tempString);
m_periodNames = tempString;
} catch (...) {
g_log.debug("Muon nexus file does not contain " + PERIOD_LABELS);
}
};
void MuonNexusReader::readFloatArrayPeriodInfo(NeXus::File &handle) {
for (const auto &floatArrayInfo : PERIOD_INFO_FLOAT_ARRAY) {
try {
std::vector<float> temp;
std::string tempString = "";
handle.readData(floatArrayInfo, temp);
if (!temp.empty()) {
for (const auto &value : temp)
tempString += std::to_string(value) + ";";
tempString.erase(tempString.length() - 1); // Remove final ;
}
m_periodInformation.emplace_back(tempString);
} catch (...) {
g_log.debug("Muon nexus file does not contain " + floatArrayInfo);
m_periodInformation.emplace_back(std::string{""});
}
try {
handle.readData(PERIOD_TYPE, tempIntVector);
m_periodTypes = convertVectorToString(tempIntVector, ";");
} catch (...) {
g_log.debug("Muon nexus file does not contain " + PERIOD_TYPE);
}
};
void MuonNexusReader::readStringPeriodInfo(NeXus::File &handle) {
for (const auto &stringArrayInfo : PERIOD_INFO_STRING) {
try {
std::string tempString = "";
handle.readData(stringArrayInfo, tempString);
m_periodInformation.emplace_back(tempString);
} catch (...) {
g_log.debug("Muon nexus file does not contain " + stringArrayInfo);
m_periodInformation.emplace_back(std::string{""});
}
try {
handle.readData(FRAMES_PERIOD_REQUESTED, tempIntVector);
m_framesPeriodsRequested = convertVectorToString(tempIntVector, ";");
} catch (...) {
g_log.debug("Muon nexus file does not contain " + FRAMES_PERIOD_REQUESTED);
}
try {
handle.readData(FRAMES_PERIOD_RAW, tempIntVector);
m_framesPeriodsRaw = convertVectorToString(tempIntVector, ";");
} catch (...) {
g_log.debug("Muon nexus file does not contain " + FRAMES_PERIOD_RAW);
}
};
try {
handle.readData(PERIOD_OUTPUT, tempIntVector);
m_periodsOutput = convertVectorToString(tempIntVector, ";");
} catch (...) {
g_log.debug("Muon nexus file does not contain " + PERIOD_OUTPUT);
}
try {
handle.readData(TOTAL_COUNTS_PERIOD, tempFloatVector);
m_periodsCounts = convertVectorToString(tempFloatVector, ";");
} catch (...) {
g_log.debug("Muon nexus file does not contain " + TOTAL_COUNTS_PERIOD);
}
}
// Get time boundary data as in ISISRAW. Simpler here as NeXus stores real times
// Not clear if corrected_time is what is wanted. Assume that values are bin
......
......@@ -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_widget import MuonPeriodInfoWidget, PERIOD_INFO_NOT_FOUND, INFO_DELIM
from Muon.GUI.Common.muon_period_info_widget import MuonPeriodInfoWidget, PERIOD_INFO_NOT_FOUND
CONTEXT_MAP = {"Name": 6,
"Type": 1,
......@@ -267,6 +267,8 @@ class GroupingTabPresenter(object):
self.update_description_text()
self.handle_update_all_clicked()
self.plot_default_groups_or_pairs()
if self.period_info_widget.isVisible():
self._add_period_info_to_widget()
else:
self.on_clear_requested()
......@@ -294,13 +296,36 @@ class GroupingTabPresenter(object):
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]
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)
tags = self._model._data.periods_info[CONTEXT_MAP["Tag"]].split(INFO_DELIM)
period_sequences_log = self._model._data.get_sample_log("period_sequences")
self.period_info_widget.number_of_sequences = str(period_sequences_log.value) if period_sequences_log else None
names_log = self._model._data.get_sample_log("period_labels")
names = names_log.value.split(";") if names_log else []
types_log = self._model._data.get_sample_log("period_type")
types = types_log.value.split(";") if types_log else []
frames_log = self._model._data.get_sample_log("frames_period_requested")
frames = frames_log.value.split(";") if frames_log else []
total_frames_log = self._model._data.get_sample_log("frames_period_raw")
total_frames = total_frames_log.value.split(";") if total_frames_log else []
counts_log = self._model._data.get_sample_log("total_counts_period")
counts = counts_log.value.split(";") if counts_log else []
tags_log = self._model._data.get_sample_log("period_output")
tags = tags_log.value.split(";") if tags_log else []
#
# self.period_info_widget.number_of_sequences = self._model._data.periods_info[0] if \
# self._model._data.periods_info[0] != [''] else None
# names = self._model._data.periods_info[CONTEXT_MAP["Name"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Name"]] != [''] else []
# types = self._model._data.periods_info[CONTEXT_MAP["Type"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Type"]] != [''] else []
# frames = self._model._data.periods_info[CONTEXT_MAP["Frames"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Frames"]] != [''] else []
# total_frames = self._model._data.periods_info[CONTEXT_MAP["Total Good Frames"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Total Good Frames"]] != [''] else []
# counts = self._model._data.periods_info[CONTEXT_MAP["Counts"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Counts"]] != [''] else []
# tags = self._model._data.periods_info[CONTEXT_MAP["Tag"]].split(INFO_DELIM) if \
# self._model._data.periods_info[CONTEXT_MAP["Tag"]] != [''] else []
names, types, frames, total_frames, counts, tags, count = self._fix_up_period_info_lists([names, types, frames,
total_frames, counts,
tags])
......@@ -314,11 +339,10 @@ class GroupingTabPresenter(object):
count = max(lengths_list)
# Then make sure lists are correct size
for i, info in enumerate(info_list):
if len(info) != count:
if info[0] == "":
info_list[i] = [PERIOD_INFO_NOT_FOUND] * count
else:
info_list[i] += [PERIOD_INFO_NOT_FOUND] * (count-len(info))
if info:
info_list[i] += [PERIOD_INFO_NOT_FOUND] * (count - len(info))
else:
info_list[i] = [PERIOD_INFO_NOT_FOUND] * count
return (*info_list, count)
# ------------------------------------------------------------------------------------------------------------------
......
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