diff --git a/Framework/API/inc/MantidAPI/LogManager.h b/Framework/API/inc/MantidAPI/LogManager.h index ee209b5029c31f690c14fa84c8e9ff42a6f3f717..f1148286640908c10340bf7602a5af85cab21206 100644 --- a/Framework/API/inc/MantidAPI/LogManager.h +++ b/Framework/API/inc/MantidAPI/LogManager.h @@ -166,6 +166,9 @@ public: return getPropertyAsSingleValue(name, statistic); } + /// Get the time averaged standard deviation for a log + double getTimeAveragedStd(const std::string &name) const; + /// Empty the values out of all TimeSeriesProperty logs void clearTimeSeriesLogs(); /// Empty all but the last value out of all TimeSeriesProperty logs diff --git a/Framework/API/src/LogManager.cpp b/Framework/API/src/LogManager.cpp index cbbb143a181fb8853a01b5eda468fda88d9122bb..877c09f82a9177f22c7ce5edd40678dbd1f64116 100644 --- a/Framework/API/src/LogManager.cpp +++ b/Framework/API/src/LogManager.cpp @@ -337,6 +337,17 @@ LogManager::getTimeSeriesProperty(const std::string &name) const { } } +/** + * Returns the time dependent standard deviation + * @param name :: The name of the property + * @return A single double value + */ +double LogManager::getTimeAveragedStd(const std::string &name) const { + return getTimeSeriesProperty<double>(name) + ->getStatistics() + .time_standard_deviation; +} + /** * Get the value of a property as the requested type. Throws if the type is not * correct diff --git a/Framework/API/test/LogManagerTest.h b/Framework/API/test/LogManagerTest.h index b546982ae936a0974b67cd89b09023f96b9d8a40..a6e5733416fa7ed810f8da2a572333b193ff323b 100644 --- a/Framework/API/test/LogManagerTest.h +++ b/Framework/API/test/LogManagerTest.h @@ -407,6 +407,14 @@ public: TS_ASSERT_EQUALS(runInfo.getPropertyAsSingleValue(name), value); } + void test_getTimeAveragedStd() { + LogManager run; + const std::string name = "series"; + addTestTimeSeries<double>(run, name); + + TS_ASSERT_DELTA(run.getTimeAveragedStd(name), 8.5239, 0.001); + } + void test_clear() { // Set up a Run object with 3 properties in it (1 time series, 2 single // value) diff --git a/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp b/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp index 2e9b34ea84b02a90fafa0342afaeae5fe02dc2cf..3a1f7aae4753a20ee0ef8c74228d5928827bdc36 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp @@ -178,6 +178,10 @@ void export_Run() { "Return a log as a single float value. Time series values are " "averaged.") + .def("getTimeAveragedStd", &Run::getTimeAveragedStd, + (arg("self"), arg("name")), + "Returns the time averaged standard deviation") + .def("getProperties", &Run::getProperties, arg("self"), return_internal_reference<>(), "Return the list of run properties managed by this object.") diff --git a/Framework/PythonInterface/test/python/mantid/api/RunTest.py b/Framework/PythonInterface/test/python/mantid/api/RunTest.py index 2a51c6be8b5774dbe94445aeaecc576ac7760777..f6fe7ea957f0ddbd8452208dfb82461cffb77ee6 100644 --- a/Framework/PythonInterface/test/python/mantid/api/RunTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/RunTest.py @@ -9,8 +9,9 @@ from __future__ import (absolute_import, division, print_function) import unittest import copy from mantid.geometry import Goniometer -from mantid.kernel import DateAndTime +from mantid.kernel import DateAndTime, FloatTimeSeriesProperty from mantid.api import Run +import numpy as np class RunTest(unittest.TestCase): @@ -35,7 +36,7 @@ class RunTest(unittest.TestCase): run = self._run charge = run.getProtonCharge() self.assertEqual(type(charge), float) - self.assertAlmostEquals(charge, 10.05, 2) + self.assertAlmostEqual(charge, 10.05) def test_run_hasProperty(self): self.assertTrue(self._run.hasProperty('start_time')) @@ -123,6 +124,22 @@ class RunTest(unittest.TestCase): ) # The space at the end is to get around an IPython bug (#8351) self.assertTrue(isinstance(runend, DateAndTime)) + def test_timestd(self): + """ + """ + run = Run() + start_time = DateAndTime("2008-12-18T17:58:38") + nanosec = 1000000000 + # === Float type === + temp1 = FloatTimeSeriesProperty("TEMP1") + vals = np.arange(10) * 2. + for i in range(10): + temp1.addValue(start_time + i*nanosec, vals[i]) + run.addProperty(temp1.name, temp1,True) + # ignore the last value + expected = vals[:-1].std() + self.assertEqual(run.getTimeAveragedStd("TEMP1"), expected) + def do_test_copyable(self, copy_op): original = self._run # make copy diff --git a/docs/source/release/v4.3.0/framework.rst b/docs/source/release/v4.3.0/framework.rst index 2f8d5dff4a12d8aab440dc47ece5f5dd01d4253b..c16892e48e19fc369c48fea187fde9ffa9f0db95 100644 --- a/docs/source/release/v4.3.0/framework.rst +++ b/docs/source/release/v4.3.0/framework.rst @@ -52,4 +52,6 @@ Improvements Python ------ +- added :py:meth:`mantid.api.Run.getTimeAveragedStd` method to the :py:obj:`mantid.api.Run` object + :ref:`Release 4.3.0 <v4.3.0>`