From c537b618bb75697ffdd8bae59d0f3c829ffe3f16 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Tue, 5 Nov 2013 11:51:48 +0100 Subject: [PATCH] Access to AxisDouble vector and changes in intensitydata unittest --- Core/PythonAPI/src/AxisBin.pypp.cpp | 9 +++++++++ Core/PythonAPI/src/AxisDouble.pypp.cpp | 9 +++++++++ Core/Tools/inc/AxisBin.h | 4 ++++ Core/Tools/inc/AxisDouble.h | 3 +++ Tests/FunctionalTests/TestPyCore/intensitydata.py | 12 ++++++++++++ 5 files changed, 37 insertions(+) diff --git a/Core/PythonAPI/src/AxisBin.pypp.cpp b/Core/PythonAPI/src/AxisBin.pypp.cpp index c0c871047c1..d7803664b4f 100644 --- a/Core/PythonAPI/src/AxisBin.pypp.cpp +++ b/Core/PythonAPI/src/AxisBin.pypp.cpp @@ -222,6 +222,15 @@ void register_AxisBin_class(){ , getSize_function_type(&::AxisBin::getSize) , default_getSize_function_type(&AxisBin_wrapper::default_getSize) ); + } + { //::AxisBin::getVector + + typedef ::std::vector< double > ( ::AxisBin::*getVector_function_type )( ) const; + + AxisBin_exposer.def( + "getVector" + , getVector_function_type( &::AxisBin::getVector ) ); + } { //::AxisBin::initBins diff --git a/Core/PythonAPI/src/AxisDouble.pypp.cpp b/Core/PythonAPI/src/AxisDouble.pypp.cpp index 1bc6bde106a..300be999fae 100644 --- a/Core/PythonAPI/src/AxisDouble.pypp.cpp +++ b/Core/PythonAPI/src/AxisDouble.pypp.cpp @@ -202,6 +202,15 @@ void register_AxisDouble_class(){ , getUpperBoundIndex_function_type( &::AxisDouble::getUpperBoundIndex ) , ( bp::arg("value") ) ); + } + { //::AxisDouble::getVector + + typedef ::std::vector< double > ( ::AxisDouble::*getVector_function_type )( ) const; + + AxisDouble_exposer.def( + "getVector" + , getVector_function_type( &::AxisDouble::getVector ) ); + } { //::AxisDouble::initElements diff --git a/Core/Tools/inc/AxisBin.h b/Core/Tools/inc/AxisBin.h index ec262d3dcb0..8e6b63271f9 100644 --- a/Core/Tools/inc/AxisBin.h +++ b/Core/Tools/inc/AxisBin.h @@ -57,6 +57,10 @@ public: // //! find the bin that contains the given value // Bin1D findMatchingBin(double value) const; + + //! returns vector containing the bin limits + std::vector<double> getVector() const { return m_value_vector; } + protected: virtual bool equals(const IAxis& other) const; private: diff --git a/Core/Tools/inc/AxisDouble.h b/Core/Tools/inc/AxisDouble.h index d3832d66b6f..1999adfcb47 100644 --- a/Core/Tools/inc/AxisDouble.h +++ b/Core/Tools/inc/AxisDouble.h @@ -69,6 +69,9 @@ public: //! find the index that corresponds to the given upper bound (index is inclusive) size_t getUpperBoundIndex(double value) const; + //! returns vector containing the axis points + std::vector<double> getVector() const { return m_sample_vector; } + protected: virtual bool equals(const IAxis& other) const; diff --git a/Tests/FunctionalTests/TestPyCore/intensitydata.py b/Tests/FunctionalTests/TestPyCore/intensitydata.py index 83d266493c9..2785fac5abb 100644 --- a/Tests/FunctionalTests/TestPyCore/intensitydata.py +++ b/Tests/FunctionalTests/TestPyCore/intensitydata.py @@ -3,6 +3,7 @@ import sys import os import unittest +import numpy sys.path.append(os.path.abspath( os.path.join(os.path.split(__file__)[0], @@ -59,6 +60,17 @@ class IntensityDataTest(unittest.TestCase): self.assertEqual(0.0, data.getAxis(1).getMin()) self.assertEqual(2.0, data.getAxis(1).getMax()) + self.assertEqual(11, len(data.getAxis(0).getVector())) + + def test_numpy_array(self): + data = IntensityData() + data.addAxis("axis0", 10, 0.0, 10.0) + data.addAxis("axis1", 20, 0.0, 20.0) + data.setAllTo(1) + arr = data.getArray() + self.assertEqual( (10,20), data.getArray().shape) + self.assertEqual( (data.totalSum()), numpy.sum(data.getArray()) ) + if __name__ == '__main__': unittest.main() -- GitLab