diff --git a/Core/PythonAPI/src/AxisBin.pypp.cpp b/Core/PythonAPI/src/AxisBin.pypp.cpp index c0c871047c18fb94bc849568be09c8940b064e1a..d7803664b4fcd249729648094d50df19b3e8ecb4 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 1bc6bde106a00e3006b1766ceda5787ca2ae2360..300be999fae50e538a44392edbd3c49a5667437c 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 ec262d3dcb00453fdfc89fb20757cd0ae860cd85..8e6b63271f917e6504860db3cfb6a03333894347 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 d3832d66b6ff297f05662b6cfb0018d685649871..1999adfcb478ee48001804cda1b21a7c1e9e7cc5 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 83d266493c9c2ed6a3d02521a767b03d0ff1ebbe..2785fac5abb8fe108d5e2dd0983fe04152c4d350 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()