Commit 25b646c5 authored by Whitfield, Ross's avatar Whitfield, Ross Committed by Peterson, Peter
Browse files

Change some logs from LoadWANDSCD to be TimeSeriesProperties

This will allows them to work correctly with SetGoniometer. Differences in testing output are just due to small floating point differences.
parent 08db854a
......@@ -197,8 +197,9 @@ void ConvertHFIRSCDtoMDE::exec() {
}
}
} else { // HB2C
s1 = (*(dynamic_cast<Kernel::PropertyWithValue<std::vector<double>> *>(
expInfo.getLog("s1"))))();
auto s1Log = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(
expInfo.run().getLogData("s1"));
s1 = s1Log->valuesAsVector();
azimuthal =
(*(dynamic_cast<Kernel::PropertyWithValue<std::vector<double>> *>(
expInfo.getLog("azimuthal"))))();
......
......@@ -5,7 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import PythonAlgorithm, AlgorithmFactory, PropertyMode, WorkspaceProperty, Progress, MultipleFileProperty, FileAction, mtd
from mantid.kernel import Direction, Property, IntArrayProperty, StringListValidator
from mantid.kernel import Direction, Property, IntArrayProperty, StringListValidator, FloatTimeSeriesProperty
from mantid.simpleapi import LoadEventNexus, RemoveLogs, DeleteWorkspace, ConvertToMD, Rebin, CreateGroupingWorkspace, GroupDetectors, SetUB
import numpy as np
import h5py
......@@ -116,6 +116,8 @@ class LoadWANDSCD(PythonAlgorithm):
'run_title,start_time,experiment_identifier,HB2C:CS:CrystalAlign:UBMatrix',
EnableLogging=False)
time_ns_array = _tmp_ws.run().startTime().totalNanoseconds() + np.append(0, np.cumsum(duration_array)*1e9)[:-1]
try:
ub = np.array(re.findall(r'-?\d+\.*\d*', _tmp_ws.run().getProperty('HB2C:CS:CrystalAlign:UBMatrix').value[0]),
dtype=np.float).reshape(3,3)
......@@ -162,16 +164,23 @@ class LoadWANDSCD(PythonAlgorithm):
DeleteWorkspace('__PreprocessedDetectorsWS', EnableLogging=False)
# end Hack
outWS.getExperimentInfo(0).run().addProperty('s1', s1_array, True)
add_time_series_property('s1', outWS.getExperimentInfo(0).run(), time_ns_array, s1_array)
outWS.getExperimentInfo(0).run().getProperty('s1').units = 'deg'
outWS.getExperimentInfo(0).run().addProperty('duration', duration_array, True)
add_time_series_property('duration', outWS.getExperimentInfo(0).run(), time_ns_array, duration_array)
outWS.getExperimentInfo(0).run().getProperty('duration').units = 'second'
outWS.getExperimentInfo(0).run().addProperty('run_number', run_number_array, True)
outWS.getExperimentInfo(0).run().addProperty('monitor_count', monitor_count_array, True)
add_time_series_property('monitor_count', outWS.getExperimentInfo(0).run(), time_ns_array, monitor_count_array)
outWS.getExperimentInfo(0).run().addProperty('twotheta', twotheta, True)
outWS.getExperimentInfo(0).run().addProperty('azimuthal', azimuthal, True)
self.setProperty("OutputWorkspace", outWS)
def add_time_series_property(name, run, times, values):
log = FloatTimeSeriesProperty(name)
for t, v in zip(times, values):
log.addValue(t, v)
run[name] = log
AlgorithmFactory.subscribe(LoadWANDSCD)
......@@ -4,7 +4,7 @@
# 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 mantid.simpleapi import LoadWANDSCD
from mantid.simpleapi import LoadWANDSCD, SetGoniometer
import unittest
......@@ -56,6 +56,9 @@ class LoadWANDTest(unittest.TestCase):
self.assertAlmostEqual(duration[0], 40.05, 5)
self.assertAlmostEqual(duration[1], 40.05, 5)
# test that you can run SetGoniometer, testing the s1 log
SetGoniometer(LoadWANDTest_ws, Axis0='s1,0,1,0,1')
LoadWANDTest_ws.delete()
......
486a2e500a75b47d857cb9c8ef7cb973
8085e1d3c2fc746bc4bb5bc9167f9f64
......@@ -30,7 +30,7 @@ class ConvertHFIRSCDtoMDETest(systemtesting.MantidSystemTest):
self.assertDelta(peak.getWavelength(), 1.488, 1e-5)
peak = ConvertHFIRSCDtoMDETest_peaks.getPeak(13)
np.testing.assert_allclose(peak.getQSampleFrame(), [6.754011, 0.001306865, 1.918834], rtol=1e-05)
np.testing.assert_allclose(peak.getQSampleFrame(), [6.754011, 0.003572579, 1.918834], rtol=1e-05)
self.assertDelta(peak.getWavelength(), 1.488, 1e-5)
......
......@@ -25,11 +25,11 @@ class ConvertWANDSCDtoQTest(systemtesting.MantidSystemTest):
self.assertEqual(ConvertWANDSCDtoQTest_peaks.getNumberPeaks(), 14)
peak = ConvertWANDSCDtoQTest_peaks.getPeak(0)
self.assertTrue(np.allclose(peak.getQSampleFrame(), [2.40072, 0.00357258, 4.32033]))
np.testing.assert_allclose(peak.getQSampleFrame(), [2.400721, 0.001306865, 4.320331], rtol=1e-5)
self.assertDelta(peak.getWavelength(), 1.488, 1e-5)
peak = ConvertWANDSCDtoQTest_peaks.getPeak(13)
self.assertTrue(np.allclose(peak.getQSampleFrame(), [6.56011, 0.00357258, -2.52058]))
np.testing.assert_allclose(peak.getQSampleFrame(), [6.560115, 0.001306865, -2.520578], rtol=1e-5)
self.assertDelta(peak.getWavelength(), 1.488, 1e-5)
SetUB('ConvertWANDSCDtoQTest_data',
......
......@@ -24,6 +24,7 @@ Engineering Diffraction
Single Crystal Diffraction
--------------------------
- New version of algorithm :ref:`SCDCalibratePanels <algm-SCDCalibratePanels-v2>` provides more accurate calibration results for CORELLI instrument.
- Modified some logs in output workspace from :ref:`LoadWANDSCD <algm-LoadWANDSCD>` to be TimeSeriesProperty so they work with :ref:`SetGoniometer <algm-SetGoniometer>`.
Improvements
############
......
......@@ -17,6 +17,7 @@ from mantid.api import MultipleExperimentInfos
from mantid.kernel import PropertyManager
from qtpy.QtGui import QStandardItemModel, QStandardItem, QColor
from qtpy.QtCore import Qt
import numpy as np
TimeSeriesProperties = (BoolTimeSeriesProperty,
FloatTimeSeriesProperty, Int32TimeSeriesProperty,
......@@ -58,10 +59,11 @@ def get_value(log):
# otherwise just show the number of values
return entry_descr
else:
return log.value
# convert to numpy array to fix some issues converting _kernel.std_vector_dbl to string
return str(np.array(log.value))
class SampleLogsModel(object):
class SampleLogsModel():
"""This class stores the workspace object and return log values when
requested
"""
......@@ -224,7 +226,7 @@ class SampleLogsModel(object):
size = log.size() if hasattr(log, 'size') else 0
name = create_table_item("Name", key, invalid_value_count, size, lambda: log.name)
log_type = create_table_item("Type", key, invalid_value_count, size, get_type, log)
value = create_table_item("Value", key, invalid_value_count, size, lambda log: str(get_value(log)), log)
value = create_table_item("Value", key, invalid_value_count, size, lambda log: get_value(log), log)
unit = create_table_item("Units", key, invalid_value_count, size, lambda: log.units)
model.appendRow((name, log_type, value, unit))
......
......@@ -11,7 +11,7 @@ from .model import SampleLogsModel
from .view import SampleLogsView
class SampleLogs(object):
class SampleLogs():
"""
"""
def __init__(self, ws, parent=None, model=None, view=None):
......
......@@ -68,7 +68,7 @@ class SampleLogsModelTest(unittest.TestCase):
values = model.get_log_display_values("Beam.sample_pressure")
self.assertEqual(values[0], "Beam.sample_pressure")
self.assertEqual(values[1], "number")
self.assertEqual(values[2], 0.0)
self.assertEqual(values[2], "0.0")
self.assertEqual(values[3], "Pa")
self.assertFalse(model.is_log_plottable("Beam.sample_pressure"))
......@@ -122,7 +122,7 @@ class SampleLogsModelTest(unittest.TestCase):
values = model.get_log_display_values("duration")
self.assertEqual(values[0], "duration")
self.assertEqual(values[1], "number")
self.assertEqual(values[2], 120.0)
self.assertEqual(values[2], "120.0")
self.assertEqual(values[3], "Sec")
# Change exp
......@@ -131,7 +131,7 @@ class SampleLogsModelTest(unittest.TestCase):
values = model.get_log_display_values("rb_proposal")
self.assertEqual(values[0], "rb_proposal")
self.assertEqual(values[1], "number")
self.assertEqual(values[2], 1455001)
self.assertEqual(values[2], "1455001")
self.assertEqual(values[3], "")
def test_Invalid_data_logs(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