Commit 5bc97190 authored by Savici, Andrei T's avatar Savici, Andrei T
Browse files

Re #27704 Expose getting time averaged std to python

parent cea9bbd9
......@@ -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
......@@ -179,7 +182,6 @@ public:
bool keepOpen = false);
/// Clear the logs
void clearLogs();
protected:
/// Load the run from a NeXus file with a given group name
void loadNexus(::NeXus::File *file,
......
......@@ -337,6 +337,22 @@ 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 {
auto prop=this->getProperty(name);
auto tsp = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(prop);
if (!tsp) {
throw std::runtime_error(
"Could not retrieve a double time series property for the property name " +
name);
}
return tsp->getStatistics().time_standard_deviation;
}
/**
* Get the value of a property as the requested type. Throws if the type is not
* correct
......
......@@ -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)
......
......@@ -178,6 +178,11 @@ 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.")
......
......@@ -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
......
......@@ -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>`
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