Skip to content

Commit

Permalink
Refs #4650. Add the missing TimeSeriesProperty export.
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jan 25, 2012
1 parent 9957b56 commit ac75800
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/PythonInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ set ( TEST_PY_FILES
test/python/PythonAlgorithmTest.py
test/python/RunTest.py
test/python/SimpleAPITest.py
test/python/TimeSeriesPropertyTest.py
test/python/QuatTest.py
test/python/V3DTest.py
test/python/UnitCellTest.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set ( EXPORT_FILES
src/Unit.cpp
src/IValidator.cpp
src/BoundedValidator.cpp
src/TimeSeriesProperty.cpp
src/DateAndTime.cpp
)

set ( SRC_FILES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "MantidKernel/DateAndTime.h"
#include <boost/python/class.hpp>
#include <boost/python/operators.hpp> // Also provides self

using Mantid::Kernel::DateAndTime;
using namespace boost::python;

void export_DateAndTime()
{

class_<DateAndTime>("DateAndTime", no_init)
.def("total_nanoseconds", &DateAndTime::total_nanoseconds)
.def("__str__", &Mantid::Kernel::DateAndTime::to_ISO8601_string)
// cppcheck-suppress duplicateExpression
.def(self == self)
// cppcheck-suppress duplicateExpression
.def(self != self)
// cppcheck-suppress duplicateExpression
.def(self < self)
.def(self + int64_t())
.def(self += int64_t())
.def(self - int64_t())
.def(self -= int64_t());

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MantidPythonInterface/kernel/StlExportDefinitions.h"

#include "MantidKernel/DateAndTime.h"

using Mantid::PythonInterface::std_vector_exporter;
using Mantid::PythonInterface::std_set_exporter;

Expand All @@ -13,7 +15,8 @@ void exportStlContainers()
std_vector_exporter<double>::wrap("std_vector_dbl");
std_vector_exporter<bool>::wrap("std_vector_bool");
std_vector_exporter<std::string>::wrap("std_vector_str");

std_vector_exporter<Mantid::Kernel::DateAndTime>::wrap("std_vector_dateandtime");
//std::set
std_set_exporter<int>::wrap("std_set_int");
std_set_exporter<std::string>::wrap("std_set_str");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "MantidKernel/TimeSeriesProperty.h"
#include <boost/python/class.hpp>

using Mantid::Kernel::TimeSeriesProperty;
using Mantid::Kernel::Property;
using namespace boost::python;

void export_TimeSeriesProperty_Double()
{
class_<TimeSeriesProperty<double>, bases<Property>, boost::noncopyable>("TimeSeriesProperty_dbl", no_init)
.def("getStatistics", &Mantid::Kernel::TimeSeriesProperty<double>::getStatistics)
.add_property("value", &Mantid::Kernel::TimeSeriesProperty<double>::valuesAsVector)
.add_property("times", &Mantid::Kernel::TimeSeriesProperty<double>::timesAsVector)
;
}

void export_TimeSeriesPropertyStatistics()
{
class_<Mantid::Kernel::TimeSeriesPropertyStatistics>("TimeSeriesPropertyStatistics", no_init)
.add_property("minimum", &Mantid::Kernel::TimeSeriesPropertyStatistics::minimum)
.add_property("maximum", &Mantid::Kernel::TimeSeriesPropertyStatistics::maximum)
.add_property("mean", &Mantid::Kernel::TimeSeriesPropertyStatistics::mean)
.add_property("median", &Mantid::Kernel::TimeSeriesPropertyStatistics::median)
.add_property("standard_deviation", &Mantid::Kernel::TimeSeriesPropertyStatistics::standard_deviation)
.add_property("duration", &Mantid::Kernel::TimeSeriesPropertyStatistics::duration)
;
}
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/PythonInterface/mantid/simpleapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import kernel
from kernel import funcreturns as _funcreturns

# Make mtd available if a user just types from mantid.simpleapi import *
from mantid import mtd

_ads = api.AnalysisDataService.Instance()
_framework = api.FrameworkManager.Instance()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
from testhelpers import run_algorithm

class TimeSeriesPropertyTest(unittest.TestCase):

def test_time_series_can_be_extracted(self):
alg = run_algorithm("Load", Filename="CNCS_7860_event.nxs", child=True)
ws = alg.getProperty("OutputWorkspace").value
log_series = ws.getRun()["Phase1"]
self.assertTrue(hasattr(log_series, "value"))
self.assertTrue(hasattr(log_series, "times"))
self.assertTrue(hasattr(log_series, "getStatistics"))

if __name__ == '__main__':
unittest.main()

0 comments on commit ac75800

Please sign in to comment.