Skip to content
Snippets Groups Projects
Unverified Commit 5f3650af authored by Peterson, Peter's avatar Peterson, Peter Committed by GitHub
Browse files

Merge pull request #27733 from mantidproject/27704_time_stddev_python

Re Expose getting time averaged std to python
parents 8c5bfe82 ca7a9213
No related branches found
No related tags found
No related merge requests found
...@@ -166,6 +166,9 @@ public: ...@@ -166,6 +166,9 @@ public:
return getPropertyAsSingleValue(name, statistic); 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 /// Empty the values out of all TimeSeriesProperty logs
void clearTimeSeriesLogs(); void clearTimeSeriesLogs();
/// Empty all but the last value out of all TimeSeriesProperty logs /// Empty all but the last value out of all TimeSeriesProperty logs
......
...@@ -337,6 +337,17 @@ LogManager::getTimeSeriesProperty(const std::string &name) const { ...@@ -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 * Get the value of a property as the requested type. Throws if the type is not
* correct * correct
......
...@@ -407,6 +407,14 @@ public: ...@@ -407,6 +407,14 @@ public:
TS_ASSERT_EQUALS(runInfo.getPropertyAsSingleValue(name), value); 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() { void test_clear() {
// Set up a Run object with 3 properties in it (1 time series, 2 single // Set up a Run object with 3 properties in it (1 time series, 2 single
// value) // value)
......
...@@ -178,6 +178,10 @@ void export_Run() { ...@@ -178,6 +178,10 @@ void export_Run() {
"Return a log as a single float value. Time series values are " "Return a log as a single float value. Time series values are "
"averaged.") "averaged.")
.def("getTimeAveragedStd", &Run::getTimeAveragedStd,
(arg("self"), arg("name")),
"Returns the time averaged standard deviation")
.def("getProperties", &Run::getProperties, arg("self"), .def("getProperties", &Run::getProperties, arg("self"),
return_internal_reference<>(), return_internal_reference<>(),
"Return the list of run properties managed by this object.") "Return the list of run properties managed by this object.")
......
...@@ -9,8 +9,9 @@ from __future__ import (absolute_import, division, print_function) ...@@ -9,8 +9,9 @@ from __future__ import (absolute_import, division, print_function)
import unittest import unittest
import copy import copy
from mantid.geometry import Goniometer from mantid.geometry import Goniometer
from mantid.kernel import DateAndTime from mantid.kernel import DateAndTime, FloatTimeSeriesProperty
from mantid.api import Run from mantid.api import Run
import numpy as np
class RunTest(unittest.TestCase): class RunTest(unittest.TestCase):
...@@ -35,7 +36,7 @@ class RunTest(unittest.TestCase): ...@@ -35,7 +36,7 @@ class RunTest(unittest.TestCase):
run = self._run run = self._run
charge = run.getProtonCharge() charge = run.getProtonCharge()
self.assertEqual(type(charge), float) self.assertEqual(type(charge), float)
self.assertAlmostEquals(charge, 10.05, 2) self.assertAlmostEqual(charge, 10.05)
def test_run_hasProperty(self): def test_run_hasProperty(self):
self.assertTrue(self._run.hasProperty('start_time')) self.assertTrue(self._run.hasProperty('start_time'))
...@@ -123,6 +124,22 @@ class RunTest(unittest.TestCase): ...@@ -123,6 +124,22 @@ class RunTest(unittest.TestCase):
) # The space at the end is to get around an IPython bug (#8351) ) # The space at the end is to get around an IPython bug (#8351)
self.assertTrue(isinstance(runend, DateAndTime)) 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): def do_test_copyable(self, copy_op):
original = self._run original = self._run
# make copy # make copy
......
...@@ -52,4 +52,6 @@ Improvements ...@@ -52,4 +52,6 @@ Improvements
Python 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>` :ref:`Release 4.3.0 <v4.3.0>`
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