diff --git a/Framework/Kernel/inc/MantidKernel/ITimeSeriesProperty.h b/Framework/Kernel/inc/MantidKernel/ITimeSeriesProperty.h index d6e1f06dd67bd010754cc46ca1b82257f075f6ac..b0302297ce741b8b58b2fdcddfb8f49beeb47be7 100644 --- a/Framework/Kernel/inc/MantidKernel/ITimeSeriesProperty.h +++ b/Framework/Kernel/inc/MantidKernel/ITimeSeriesProperty.h @@ -61,8 +61,6 @@ public: virtual std::vector<Types::Core::DateAndTime> timesAsVector() const = 0; /// Returns the calculated time weighted average value virtual double timeAverageValue() const = 0; - /// Returns the calculated time weighted average value and standard deviation - virtual std::pair<double, double> timeAverageValueAndStdDev() const = 0; /// Returns the real size of the time series property map: virtual int realSize() const = 0; /// Deletes the series of values in the property diff --git a/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h b/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h index 1e2b4aa0de2affb3d0e7ed1ec8cd9ad77661a921..9a94c9bd8398f5df898d91dab83b64bc3f76a1f8 100644 --- a/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h +++ b/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h @@ -39,6 +39,10 @@ struct TimeSeriesPropertyStatistics { double median; /// standard_deviation of the values double standard_deviation; + /// time weighted average + double time_mean; + /// time weighted standard deviation + double time_standard_deviation; /// Duration in seconds double duration; }; @@ -185,10 +189,8 @@ public: /// @copydoc Mantid::Kernel::ITimeSeriesProperty::averageAndStdDevInFilter() std::pair<double, double> averageAndStdDevInFilter( const std::vector<SplittingInterval> &filter) const override; - /// Calculate the time-weighted average of a property + /// @copydoc Mantid::Kernel::ITimeSeriesProperty::timeAverageValue() double timeAverageValue() const override; - /// @copydoc Mantid::Kernel::ITimeSeriesProperty::timeAverageValueAndStdDev() - std::pair<double, double> timeAverageValueAndStdDev() const override; /// generate constant time-step histogram from the property values void histogramData(const Types::Core::DateAndTime &tMin, const Types::Core::DateAndTime &tMax, @@ -339,6 +341,8 @@ private: std::string setValueFromProperty(const Property &right) override; /// Find if time lies in a filtered region bool isTimeFiltered(const Types::Core::DateAndTime &time) const; + /// Time weighted mean and standard deviation + std::pair<double, double> timeAverageValueAndStdDev() const; /// Holds the time series data mutable std::vector<TimeValueUnit<TYPE>> m_values; diff --git a/Framework/Kernel/src/TimeSeriesProperty.cpp b/Framework/Kernel/src/TimeSeriesProperty.cpp index e0f5ff30b0ca5c797416bb4fe49a4610074f50ed..187f4930bad2ad03021dce13adaad8873fdf94fb 100644 --- a/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -2002,7 +2002,12 @@ TimeSeriesPropertyStatistics TimeSeriesProperty<TYPE>::getStatistics() const { duration_sec += interval.duration(); } out.duration = duration_sec; + const auto time_weighted = this->timeAverageValueAndStdDev(); + out.time_mean = time_weighted.first; + out.time_standard_deviation = time_weighted.second; } else { + out.time_mean = std::numeric_limits<double>::quiet_NaN(); + out.time_standard_deviation = std::numeric_limits<double>::quiet_NaN(); out.duration = std::numeric_limits<double>::quiet_NaN(); } diff --git a/Framework/Kernel/test/TimeSeriesPropertyTest.h b/Framework/Kernel/test/TimeSeriesPropertyTest.h index c6c77858cbd249b507223a8ec3e9e9c2ad9de5df..0f04be47d98c4962ac164f95b993ab3a60dec323 100644 --- a/Framework/Kernel/test/TimeSeriesPropertyTest.h +++ b/Framework/Kernel/test/TimeSeriesPropertyTest.h @@ -619,14 +619,6 @@ public: const double intMean = intLog->timeAverageValue(); TS_ASSERT_DELTA(intMean, 2.5, .0001); - // average is unchanged, standard deviation within tolerance - const auto dblPair = dblLog->timeAverageValueAndStdDev(); - TS_ASSERT_EQUALS(dblPair.first, dblMean); - TS_ASSERT_DELTA(dblPair.second, 1.8156, .0001); - const auto intPair = intLog->timeAverageValueAndStdDev(); - TS_ASSERT_EQUALS(intPair.first, intMean); - TS_ASSERT_DELTA(intPair.second, 1.1180, .0001); - // Clean up delete dblLog; delete intLog; @@ -1055,6 +1047,8 @@ public: TS_ASSERT_DELTA(stats.duration, 100.0, 1e-3); TS_ASSERT_DELTA(stats.standard_deviation, 3.1622, 1e-3); TS_ASSERT_DELTA(log->timeAverageValue(), 5.5, 1e-3); + TS_ASSERT_DELTA(stats.time_mean, 5.5, 1e-3); + TS_ASSERT_DELTA(stats.time_standard_deviation, 2.872, 1e-3); delete log; } @@ -1068,6 +1062,8 @@ public: TS_ASSERT(std::isnan(stats.median)); TS_ASSERT(std::isnan(stats.mean)); TS_ASSERT(std::isnan(stats.standard_deviation)); + TS_ASSERT(std::isnan(stats.time_mean)); + TS_ASSERT(std::isnan(stats.time_standard_deviation)); TS_ASSERT(std::isnan(stats.duration)); delete log; diff --git a/Framework/PythonInterface/mantid/kernel/src/Exports/TimeSeriesProperty.cpp b/Framework/PythonInterface/mantid/kernel/src/Exports/TimeSeriesProperty.cpp index 9ed50890dba09b818b3904b4bc308a6b075158e2..cd2138efd0d8b064325b62ea2682780b4aa6dea0 100644 --- a/Framework/PythonInterface/mantid/kernel/src/Exports/TimeSeriesProperty.cpp +++ b/Framework/PythonInterface/mantid/kernel/src/Exports/TimeSeriesProperty.cpp @@ -37,12 +37,6 @@ void addPyTimeValue(TimeSeriesProperty<TYPE> &self, self.addValue(*dateandtime, value); } -template <typename TYPE> -tuple pyTimeAverageValueAndStdDev(const TimeSeriesProperty<TYPE> &self) { - const std::pair<double, double> value = self.timeAverageValueAndStdDev(); - return make_tuple(value.first, value.second); -} - // Call the dtype helper function template <typename TYPE> std::string dtype(TimeSeriesProperty<TYPE> &self) { return Mantid::PythonInterface::Converters::dtype(self); @@ -94,8 +88,6 @@ template <typename TYPE> std::string dtype(TimeSeriesProperty<TYPE> &self) { "returns :class:`mantid.kernel.TimeSeriesPropertyStatistics`") \ .def("timeAverageValue", &TimeSeriesProperty<TYPE>::timeAverageValue, \ arg("self")) \ - .def("timeAverageValueAndStdDev", &pyTimeAverageValueAndStdDev<TYPE>, \ - arg("self"), "Time average value and standard deviation") \ .def("dtype", &dtype<TYPE>, arg("self")); } // namespace @@ -131,6 +123,11 @@ void export_TimeSeriesPropertyStatistics() { .add_property( "standard_deviation", &Mantid::Kernel::TimeSeriesPropertyStatistics::standard_deviation) + .add_property("time_mean", + &Mantid::Kernel::TimeSeriesPropertyStatistics::time_mean) + .add_property("time_standard_deviation", + &Mantid::Kernel::TimeSeriesPropertyStatistics:: + time_standard_deviation) .add_property("duration", &Mantid::Kernel::TimeSeriesPropertyStatistics::duration); } diff --git a/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py b/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py index d162fc3f5b44c8d0ab9ef1ce8b3fbb03183d38a5..265cec042163963dc593dbb1030c5bb7965754f2 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py @@ -95,5 +95,15 @@ class TimeSeriesPropertyTest(unittest.TestCase): self.assertTrue(isinstance(values, values_type)) self.assertEquals(log.size(), len(values)) + # check the statistics + stats = log.getStatistics() + self.assertTrue(hasattr(stats, 'mean')) + self.assertTrue(hasattr(stats, 'median')) + self.assertTrue(hasattr(stats, 'minimum')) + self.assertTrue(hasattr(stats, 'maximum')) + self.assertTrue(hasattr(stats, 'standard_deviation')) + self.assertTrue(hasattr(stats, 'time_mean')) + self.assertTrue(hasattr(stats, 'time_standard_deviation')) + if __name__ == '__main__': unittest.main() diff --git a/MantidPlot/src/Mantid/SampleLogDialogBase.cpp b/MantidPlot/src/Mantid/SampleLogDialogBase.cpp index ff1be5af55faa170f108153e89d6931c9d3b8908..1e7361a41063549f657592ecc33fc0ff419987b0 100644 --- a/MantidPlot/src/Mantid/SampleLogDialogBase.cpp +++ b/MantidPlot/src/Mantid/SampleLogDialogBase.cpp @@ -138,17 +138,14 @@ void SampleLogDialogBase::showLogStatisticsOfItem( dynamic_cast<TimeSeriesProperty<double> *>(logData); Mantid::Kernel::TimeSeriesProperty<int> *tspi = dynamic_cast<TimeSeriesProperty<int> *>(logData); - std::pair<double, double> timeAvgStdDev{0., 0.}; LogFilterGenerator generator(filter, m_ei->run()); const auto &logFilter = generator.generateFilter(logName); if (tspd) { ScopedFilter<double> applyFilter(tspd, std::move(logFilter)); stats = tspd->getStatistics(); - timeAvgStdDev = tspd->timeAverageValueAndStdDev(); } else if (tspi) { ScopedFilter<int> applyFilter(tspi, std::move(logFilter)); stats = tspi->getStatistics(); - timeAvgStdDev = tspi->timeAverageValueAndStdDev(); } else return; @@ -158,8 +155,8 @@ void SampleLogDialogBase::showLogStatisticsOfItem( statValues[2]->setText(QString::number(stats.mean)); statValues[3]->setText(QString::number(stats.median)); statValues[4]->setText(QString::number(stats.standard_deviation)); - statValues[5]->setText(QString::number(timeAvgStdDev.first)); - statValues[6]->setText(QString::number(timeAvgStdDev.second)); + statValues[5]->setText(QString::number(stats.time_mean)); + statValues[6]->setText(QString::number(stats.time_standard_deviation)); statValues[7]->setText(QString::number(stats.duration)); return; break;