Commit 21d133fd authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add python type for TimeSeriesProperty<int>. Refs #5488

parent 23894fee
...@@ -204,14 +204,27 @@ namespace Mantid ...@@ -204,14 +204,27 @@ namespace Mantid
return getNanStatistics(); return getNanStatistics();
} }
/// Getting statistics of a boolean array should just give a bunch of NaNs
template<>
DLLExport Statistics getStatistics<bool> (const vector<bool>& data, const bool sorted)
{
UNUSED_ARG(sorted);
UNUSED_ARG(data);
return getNanStatistics();
}
// -------------------------- concrete instantiations // -------------------------- concrete instantiations
template DLLExport Statistics getStatistics<double> (const vector<double> &, const bool); template DLLExport Statistics getStatistics<double> (const vector<double> &, const bool);
template DLLExport Statistics getStatistics<int32_t> (const vector<int32_t> &, const bool); template DLLExport Statistics getStatistics<int32_t> (const vector<int32_t> &, const bool);
template DLLExport Statistics getStatistics<int64_t> (const vector<int64_t> &, const bool);
template DLLExport std::vector<double> getZscore<double> (const vector<double> &, const bool); template DLLExport std::vector<double> getZscore<double> (const vector<double> &, const bool);
template DLLExport std::vector<double> getZscore<int32_t> (const vector<int32_t> &, const bool); template DLLExport std::vector<double> getZscore<int32_t> (const vector<int32_t> &, const bool);
template DLLExport std::vector<double> getZscore<int64_t> (const vector<int64_t> &, const bool);
template DLLExport std::vector<double> getModifiedZscore<double> (const vector<double> &, const bool); template DLLExport std::vector<double> getModifiedZscore<double> (const vector<double> &, const bool);
template DLLExport std::vector<double> getModifiedZscore<int32_t> (const vector<int32_t> &, const bool); template DLLExport std::vector<double> getModifiedZscore<int32_t> (const vector<int32_t> &, const bool);
template DLLExport std::vector<double> getModifiedZscore<int64_t> (const vector<int64_t> &, const bool);
} // namespace Kernel } // namespace Kernel
} // namespace Mantid } // namespace Mantid
...@@ -200,6 +200,42 @@ namespace PythonAPI ...@@ -200,6 +200,42 @@ namespace PythonAPI
.def("nthTime", &TimeSeriesProperty<double>::nthTime) .def("nthTime", &TimeSeriesProperty<double>::nthTime)
; ;
register_ptr_to_python<TimeSeriesProperty<int32_t>*>();
register_ptr_to_python<const TimeSeriesProperty<int32_t>*>();
class_<Mantid::Kernel::TimeSeriesProperty<int32_t>, \
bases<Mantid::Kernel::Property>, boost::noncopyable>("TimeSeriesProperty_int32_t", no_init)
.def("getStatistics", &Mantid::Kernel::TimeSeriesProperty<int32_t>::getStatistics)
.add_property("value", &Mantid::Kernel::TimeSeriesProperty<int32_t>::valuesAsVector)
.add_property("times", &Mantid::Kernel::TimeSeriesProperty<int32_t>::timesAsVector)
.def("valueAsString", &TimeSeriesProperty<int32_t>::value)
.def("size", &TimeSeriesProperty<int32_t>::size)
.def("firstTime", &TimeSeriesProperty<int32_t>::firstTime)
.def("firstValue", &TimeSeriesProperty<int32_t>::firstValue)
.def("lastTime", &TimeSeriesProperty<int32_t>::lastTime)
.def("lastValue", &TimeSeriesProperty<int32_t>::lastValue)
.def("nthValue", &TimeSeriesProperty<int32_t>::nthValue)
.def("nthTime", &TimeSeriesProperty<int32_t>::nthTime)
;
register_ptr_to_python<TimeSeriesProperty<int64_t>*>();
register_ptr_to_python<const TimeSeriesProperty<int64_t>*>();
class_<Mantid::Kernel::TimeSeriesProperty<int64_t>, \
bases<Mantid::Kernel::Property>, boost::noncopyable>("TimeSeriesProperty_int64_t", no_init)
.def("getStatistics", &Mantid::Kernel::TimeSeriesProperty<int64_t>::getStatistics)
.add_property("value", &Mantid::Kernel::TimeSeriesProperty<int64_t>::valuesAsVector)
.add_property("times", &Mantid::Kernel::TimeSeriesProperty<int64_t>::timesAsVector)
.def("valueAsString", &TimeSeriesProperty<int64_t>::value)
.def("size", &TimeSeriesProperty<int64_t>::size)
.def("firstTime", &TimeSeriesProperty<int64_t>::firstTime)
.def("firstValue", &TimeSeriesProperty<int64_t>::firstValue)
.def("lastTime", &TimeSeriesProperty<int64_t>::lastTime)
.def("lastValue", &TimeSeriesProperty<int64_t>::lastValue)
.def("nthValue", &TimeSeriesProperty<int64_t>::nthValue)
.def("nthTime", &TimeSeriesProperty<int64_t>::nthTime)
;
class_<time_duration>("time_duration", no_init) class_<time_duration>("time_duration", no_init)
.def("hours", &time_duration::hours, "Returns the normalized number of hours") .def("hours", &time_duration::hours, "Returns the normalized number of hours")
.def("minutes", &time_duration::minutes, "Returns the normalized number of minutes +/-(0..59)") .def("minutes", &time_duration::minutes, "Returns the normalized number of minutes +/-(0..59)")
......
...@@ -12,9 +12,9 @@ namespace ...@@ -12,9 +12,9 @@ namespace
/// Defines the getStatistics member for various types /// Defines the getStatistics member for various types
#define DEF_GET_STATS(TYPE) DEF_GET_STATS_##TYPE #define DEF_GET_STATS(TYPE) DEF_GET_STATS_##TYPE
/// Doubles have a get stats member /// Doubles have a get stats member
#define DEF_GET_STATS_double .def("getStatistics", &TimeSeriesProperty<double>::getStatistics) #define DEF_GET_STATS_double
/// booleans do not have a get stats member /// booleans do not have a get stats member
#define DEF_GET_STATS_bool #define DEF_GET_STATS_bool
/// Macro to reduce copy-and-paste /// Macro to reduce copy-and-paste
#define EXPORT_TIMESERIES_PROP(TYPE, Prefix)\ #define EXPORT_TIMESERIES_PROP(TYPE, Prefix)\
...@@ -33,7 +33,7 @@ namespace ...@@ -33,7 +33,7 @@ namespace
.def("lastValue", &TimeSeriesProperty<TYPE>::lastValue) \ .def("lastValue", &TimeSeriesProperty<TYPE>::lastValue) \
.def("nthValue", &TimeSeriesProperty<TYPE>::nthValue) \ .def("nthValue", &TimeSeriesProperty<TYPE>::nthValue) \
.def("nthTime", &TimeSeriesProperty<TYPE>::nthTime) \ .def("nthTime", &TimeSeriesProperty<TYPE>::nthTime) \
DEF_GET_STATS(TYPE) \ .def("getStatistics", &TimeSeriesProperty<double>::getStatistics) \
; ;
; ;
} }
...@@ -48,6 +48,22 @@ void export_TimeSeriesProperty_Bool() ...@@ -48,6 +48,22 @@ void export_TimeSeriesProperty_Bool()
EXPORT_TIMESERIES_PROP(bool, Bool); EXPORT_TIMESERIES_PROP(bool, Bool);
} }
void export_TimeSeriesProperty_Int32()
{
EXPORT_TIMESERIES_PROP(int32_t, Int32);
}
void export_TimeSeriesProperty_Int64()
{
EXPORT_TIMESERIES_PROP(int64_t, Int64);
}
void export_TimeSeriesProperty_String()
{
EXPORT_TIMESERIES_PROP(std::string, String);
}
void export_TimeSeriesPropertyStatistics() void export_TimeSeriesPropertyStatistics()
{ {
class_<Mantid::Kernel::TimeSeriesPropertyStatistics>("TimeSeriesPropertyStatistics", no_init) class_<Mantid::Kernel::TimeSeriesPropertyStatistics>("TimeSeriesPropertyStatistics", no_init)
......
...@@ -3,13 +3,36 @@ from testhelpers import run_algorithm ...@@ -3,13 +3,36 @@ from testhelpers import run_algorithm
class TimeSeriesPropertyTest(unittest.TestCase): class TimeSeriesPropertyTest(unittest.TestCase):
def test_time_series_can_be_extracted(self): _test_ws = None
alg = run_algorithm("Load", Filename="CNCS_7860_event.nxs", child=True)
ws = alg.getProperty("OutputWorkspace").value def setUp(self):
log_series = ws.getRun()["Phase1"] if self._test_ws is None:
self.assertTrue(hasattr(log_series, "value")) alg = run_algorithm("Load", Filename="LOQ49886.nxs", child=True)
self.assertTrue(hasattr(log_series, "times")) self.__class__._test_ws = alg.getProperty("OutputWorkspace").value
self.assertTrue(hasattr(log_series, "getStatistics"))
def test_time_series_double_can_be_extracted(self):
log_series = self._test_ws.getRun()["TEMP1"]
self._check_has_time_series_attributes(log_series)
self.assertEquals(log_series.size(), 63)
self.assertAlmostEqual(log_series.nthValue(0), -0.00161)
def test_time_series_int_can_be_extracted(self):
log_series = self._test_ws.getRun()["raw_frames"]
self._check_has_time_series_attributes(log_series)
self.assertEquals(log_series.size(), 172)
self.assertEquals(log_series.nthValue(0), 17)
def test_time_series_string_can_be_extracted(self):
log_series = self._test_ws.getRun()["icp_event"]
self._check_has_time_series_attributes(log_series)
self.assertEquals(log_series.size(), 11)
self.assertEquals(log_series.nthValue(0).strip(), 'CHANGE_PERIOD 1')
def _check_has_time_series_attributes(self, log):
self.assertTrue(hasattr(log, "value"))
self.assertTrue(hasattr(log, "times"))
self.assertTrue(hasattr(log, "getStatistics"))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
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