Skip to content
Snippets Groups Projects
Commit 34ae78ef authored by Anthony Lim's avatar Anthony Lim
Browse files

refs #27634 rought version of PSI muon data in muon GUI

parent c68dbe02
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,7 @@ private:
void readInHeader(Mantid::Kernel::BinaryStreamReader &streamReader);
void readInHistograms(Mantid::Kernel::BinaryStreamReader &streamReader);
void generateUnknownAxis();
void makeDeadTimeTable(const size_t &numSpec);
// Temperature file processing
void readInTemperatureFile(DataObjects::Workspace2D_sptr &ws);
......
......@@ -10,6 +10,9 @@
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidHistogramData/Histogram.h"
......@@ -107,10 +110,12 @@ void LoadPSIMuonBin::init() {
declareProperty("TimeZero", 0.0, "The TimeZero of the OutputWorkspace",
Kernel::Direction::Output);
declareProperty("DataDeadTimeTable", 0,
"This property should not be set and is present to work with "
"the Muon GUI preprocessor.",
Kernel::Direction::Output);
declareProperty(
std::make_unique<Mantid::API::WorkspaceProperty<Mantid::API::Workspace>>(
"DeadTimeTable", "", Mantid::Kernel::Direction::Output,
Mantid::API::PropertyMode::Optional),
"This property should only be set in the GUI and is present to work with "
"the Muon GUI preprocessor.");
declareProperty("MainFieldDirection", 0,
"The field direction of the magnetic field on the instrument",
......@@ -166,13 +171,12 @@ void LoadPSIMuonBin::exec() {
// Set up for the Muon PreProcessor
setProperty("OutputWorkspace", outputWorkspace);
// create empty dead time table
makeDeadTimeTable(m_histograms.size());
auto largestBinValue =
outputWorkspace->x(0)[outputWorkspace->x(0).size() - 1];
auto firstGoodDataSpecIndex = static_cast<int>(
*std::max_element(m_header.firstGood, m_header.firstGood + 16));
setProperty("FirstGoodData", outputWorkspace->x(0)[firstGoodDataSpecIndex]);
// Since the arrray is all 0s before adding them this can't get min
// element so just get first element
auto lastGoodDataSpecIndex = static_cast<int>(m_header.lastGood[0]);
......@@ -189,12 +193,46 @@ void LoadPSIMuonBin::exec() {
// If timeZero is bigger than the largest bin assume it refers to a bin's
// value
double absTimeZero = timeZero;
if (timeZero > largestBinValue) {
setProperty("TimeZero",
outputWorkspace->x(0)[static_cast<int>(std::floor(timeZero))]);
} else {
setProperty("TimeZero", timeZero);
absTimeZero = outputWorkspace->x(0)[static_cast<int>(std::floor(timeZero))];
}
setProperty("TimeZero", absTimeZero);
auto firstGoodDataSpecIndex = static_cast<int>(
*std::max_element(m_header.firstGood, m_header.firstGood + 16));
setProperty("FirstGoodData",
outputWorkspace->x(0)[firstGoodDataSpecIndex]);
// Time zero is when the pulse starts.
// The pulse should be at t=0 to be like ISIS data
// manually offset the data
for (auto specNum = 0u; specNum < m_histograms.size(); ++specNum) {
auto xData = outputWorkspace->mutableX(specNum);
for (auto j = 0; j < xData.size();j++) {
xData[j] = xData[j] - absTimeZero;
}
outputWorkspace->mutableX(specNum) = xData;
}
}
void LoadPSIMuonBin::makeDeadTimeTable(const size_t &numSpec) {
if (getPropertyValue("DeadTimeTable").empty())
return;
Mantid::DataObjects::TableWorkspace_sptr deadTimeTable =
boost::dynamic_pointer_cast<Mantid::DataObjects::TableWorkspace>(
Mantid::API::WorkspaceFactory::Instance().createTable(
"TableWorkspace"));
deadTimeTable->addColumn("int", "spectrum");
deadTimeTable->addColumn("double", "dead-time");
for (int i = 0; i < numSpec; i++) {
Mantid::API::TableRow row = deadTimeTable->appendRow();
row << i + 1 << 0.0;
}
setProperty("DeadTimeTable", deadTimeTable);
}
std::string LoadPSIMuonBin::getFormattedDateTime(std::string date,
......@@ -481,8 +519,8 @@ void LoadPSIMuonBin::assignOutputWorkspaceParticulars(
g_log.warning("The date in the .bin file was invalid");
}
addToSampleLog("run_end", startDate, outputWorkspace);
addToSampleLog("run_start", endDate, outputWorkspace);
addToSampleLog("run_end", endDate, outputWorkspace);
addToSampleLog("run_start", startDate, outputWorkspace);
// Assume unit is at the end of the temperature
boost::trim_right(m_header.temp);
......@@ -552,8 +590,14 @@ void LoadPSIMuonBin::assignOutputWorkspaceParticulars(
for (auto i = 0u; i < sizeOfLabels; ++i) {
if (m_header.labelsOfHistograms[i] == "")
break;
std::string name = m_header.labelsOfHistograms[i];
std::string label =
(name.size() > 0 && name.find_first_not_of(" ") == std::string::npos)
? "group_" + std::to_string(i+1)
: m_header.labelsOfHistograms[i];
addToSampleLog("Label Spectra " + std::to_string(i),
m_header.labelsOfHistograms[i], outputWorkspace);
label, outputWorkspace);
}
addToSampleLog("Orientation", m_header.orientation, outputWorkspace);
......
......@@ -25,6 +25,8 @@ Any temperature data loaded in from a separate file will be available
from the resultant workspace's sample logs, as a number series that
is plottable.
The times are automatically offset by the value for first good data, such that the pulse is at approximatly time equals zero. This is to be consistant with ISIS measurment data.
Errors
######
......
......@@ -41,7 +41,7 @@ class MuonWorkspaceWrapper(object):
self._workspace = None
self._directory_structure = ""
self._workspace_name = ""
print(workspace, "moo")
if isinstance(workspace, Workspace):
self.workspace = workspace
else:
......
......@@ -63,6 +63,7 @@ def _get_pre_processing_params(context, run, rebin):
if context.gui_context['TimeZeroFromFile']:
time_offset = 0.0
else:
print("baa",context.data_context.get_loaded_data_for_run(run)["TimeZero"] ,context.gui_context['TimeZero'],context.data_context.get_loaded_data_for_run(run)["TimeZero"] - context.gui_context['TimeZero'] )
time_offset = context.data_context.get_loaded_data_for_run(run)["TimeZero"] - context.gui_context['TimeZero']
pre_process_params["TimeOffset"] = time_offset
except KeyError:
......@@ -83,7 +84,6 @@ def _get_pre_processing_params(context, run, rebin):
pre_process_params["DeadTimeTable"] = dead_time_table
except KeyError:
pass
return pre_process_params
......@@ -121,6 +121,7 @@ def _get_MuonGroupingCounts_parameters(context, group_name, run):
group = context.group_pair_context[group_name]
if group:
params["GroupName"] = group_name
print("dsaf", group_name)
params["Grouping"] = ",".join([str(i) for i in group.detectors])
return params
......
......@@ -52,8 +52,11 @@ def get_default_grouping(workspace, instrument, main_field_direction):
try:
if isinstance(workspace, WorkspaceGroup):
grouping_file = workspace[0].getInstrument().getStringParameter(parameter_name)[0]
print("d", grouping_file)
else:
grouping_file = workspace.getInstrument().getStringParameter(parameter_name)[0]
print("e", grouping_file)
except IndexError:
return [], [], ''
else:
......
......@@ -105,6 +105,7 @@ class GroupingTablePresenter(object):
self._view.disable_updates()
assert isinstance(group, MuonGroup)
entry = [str(group.name), state, run_utils.run_list_to_string(group.detectors, False), str(group.n_detectors)]
self._view.warning_popup("moo")
self._view.add_entry_to_table(entry)
self._view.enable_updates()
......
......@@ -206,7 +206,9 @@ def load_workspace_from_filename(filename,
alg.execute()
workspace = AnalysisDataService.retrieve(alg.getProperty("OutputWorkspace").valueAsStr)
print("fsdaf", workspace)
if is_workspace_group(workspace):
print("multi")
# handle multi-period data
load_result = _get_algorithm_properties(alg, output_properties)
load_result["OutputWorkspace"] = [MuonWorkspaceWrapper(ws) for ws in workspace.getNames()]
......@@ -227,17 +229,16 @@ def load_workspace_from_filename(filename,
load_result["DataDeadTimeTable"] = None
load_result["FirstGoodData"] = round(load_result["FirstGoodData"], 2)
else:
print("single", output_properties)
# single period data
load_result = _get_algorithm_properties(alg, output_properties)
load_result["OutputWorkspace"] = [MuonWorkspaceWrapper(load_result["OutputWorkspace"])]
run = int(workspace.getRunNumber())
if not psi_data:
load_result["DataDeadTimeTable"] = load_result["DeadTimeTable"]
load_result["DeadTimeTable"] = None
load_result["FirstGoodData"] = round(load_result["FirstGoodData"] - load_result['TimeZero'], 2)
else:
load_result["DataDeadTimeTable"] = None
load_result["FirstGoodData"] = round(load_result["FirstGoodData"], 2)
load_result["DataDeadTimeTable"] = load_result["DeadTimeTable"]
load_result["DeadTimeTable"] = None
load_result["FirstGoodData"] = round(load_result["FirstGoodData"] - load_result['TimeZero'], 2)
return load_result, run, filename, psi_data
......@@ -256,7 +257,7 @@ def create_load_algorithm(filename, property_dictionary):
else:
alg = mantid.AlgorithmManager.create("LoadMuonNexus")
alg.setProperties(property_dictionary)
alg.setProperty("DeadTimeTable", output_filename + '_deadtime_table')
alg.setProperty("DeadTimeTable", output_filename + '_deadtime_table')
alg.initialize()
alg.setAlwaysStoreInADS(True)
......
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