From d3e7958ea1237e19be85ba895ac8ebc18bb6dd4e Mon Sep 17 00:00:00 2001 From: Dmitry Yurov <d.yurov@fz-juelich.de> Date: Tue, 19 Feb 2019 14:36:30 +0100 Subject: [PATCH] Implement SimulationResult::axis method. Redmine: #2305 --- Core/Instrument/SimulationResult.cpp | 21 ++- Core/Instrument/SimulationResult.h | 7 +- auto/Wrap/libBornAgainCore.py | 10 ++ auto/Wrap/libBornAgainCore_wrap.cpp | 214 +++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 7 deletions(-) diff --git a/Core/Instrument/SimulationResult.cpp b/Core/Instrument/SimulationResult.cpp index c961340d472..46486d6cbf5 100644 --- a/Core/Instrument/SimulationResult.cpp +++ b/Core/Instrument/SimulationResult.cpp @@ -64,7 +64,7 @@ OutputData<double>* SimulationResult::data(AxesUnits units) const const size_t dim = mP_data->getRank(); std::unique_ptr<OutputData<double>> result(new OutputData<double>); for (size_t i = 0; i < dim; ++i) - result->addAxis(*createConvertedAxis(i, units)); + result->addAxis(*mP_unit_converter->createConvertedAxis(i, units)); result->setRawDataVector(mP_data->getRawDataVector()); return result.release(); } @@ -135,6 +135,20 @@ PyObject* SimulationResult::array() const return mP_data->getArray(); } +std::vector<double> SimulationResult::axis(AxesUnits units) const +{ + return axis(0, units); +} + +std::vector<double> SimulationResult::axis(size_t i_axis, AxesUnits units) const +{ + if (i_axis >= mP_unit_converter->dimension()) + throw std::runtime_error( + "Error in SimulationResult::axis: no axis corresponds to passed index."); + auto axis = mP_unit_converter->createConvertedAxis(i_axis, units); + return axis->getBinCenters(); +} + void SimulationResult::checkDimensions() const { if (mP_data->getRank() != mP_unit_converter->dimension()) @@ -142,8 +156,3 @@ void SimulationResult::checkDimensions() const "dimensions of data and unit converter don't match"); return; } - -std::unique_ptr<IAxis> SimulationResult::createConvertedAxis(size_t i_axis, AxesUnits units) const -{ - return mP_unit_converter->createConvertedAxis(i_axis, units); -} diff --git a/Core/Instrument/SimulationResult.h b/Core/Instrument/SimulationResult.h index 0334a8f4bb5..48d7de8a1de 100644 --- a/Core/Instrument/SimulationResult.h +++ b/Core/Instrument/SimulationResult.h @@ -70,9 +70,14 @@ public: PyObject* array() const; #endif + std::vector<double> axis(AxesUnits units = AxesUnits::DEFAULT) const; + + //! Returns axis coordinates as a numpy array. With no parameters given + //! returns coordinates of x-axis in default units. + std::vector<double> axis(size_t i_axis, AxesUnits units = AxesUnits::DEFAULT) const; + private: void checkDimensions() const; - std::unique_ptr<IAxis> createConvertedAxis(size_t i_axis, AxesUnits units) const; std::unique_ptr<OutputData<double>> mP_data; std::unique_ptr<IUnitConverter> mP_unit_converter; }; diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py index e88ef270ac9..87928c3fefa 100644 --- a/auto/Wrap/libBornAgainCore.py +++ b/auto/Wrap/libBornAgainCore.py @@ -18251,6 +18251,16 @@ class SimulationResult(_object): """ return _libBornAgainCore.SimulationResult_array(self) + + def axis(self, *args): + """ + axis(SimulationResult self, AxesUnits units) -> vdouble1d_t + axis(SimulationResult self) -> vdouble1d_t + axis(SimulationResult self, size_t i_axis, AxesUnits units) -> vdouble1d_t + axis(SimulationResult self, size_t i_axis) -> vdouble1d_t + """ + return _libBornAgainCore.SimulationResult_axis(self, *args) + __swig_destroy__ = _libBornAgainCore.delete_SimulationResult __del__ = lambda self: None SimulationResult_swigregister = _libBornAgainCore.SimulationResult_swigregister diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp index 1204cd33e8e..509779bdcf5 100644 --- a/auto/Wrap/libBornAgainCore_wrap.cpp +++ b/auto/Wrap/libBornAgainCore_wrap.cpp @@ -85987,6 +85987,214 @@ fail: } +SWIGINTERN PyObject *_wrap_SimulationResult_axis__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + AxesUnits arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + std::vector< double,std::allocator< double > > result; + + if (!PyArg_ParseTuple(args,(char *)"OO:SimulationResult_axis",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult_axis" "', argument " "1"" of type '" "SimulationResult const *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + ecode2 = SWIG_AsVal_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SimulationResult_axis" "', argument " "2"" of type '" "AxesUnits""'"); + } + arg2 = static_cast< AxesUnits >(val2); + result = ((SimulationResult const *)arg1)->axis(arg2); + resultobj = swig::from(static_cast< std::vector< double,std::allocator< double > > >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SimulationResult_axis__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + std::vector< double,std::allocator< double > > result; + + if (!PyArg_ParseTuple(args,(char *)"O:SimulationResult_axis",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult_axis" "', argument " "1"" of type '" "SimulationResult const *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + result = ((SimulationResult const *)arg1)->axis(); + resultobj = swig::from(static_cast< std::vector< double,std::allocator< double > > >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SimulationResult_axis__SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + size_t arg2 ; + AxesUnits arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + size_t val2 ; + int ecode2 = 0 ; + int val3 ; + int ecode3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + std::vector< double,std::allocator< double > > result; + + if (!PyArg_ParseTuple(args,(char *)"OOO:SimulationResult_axis",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult_axis" "', argument " "1"" of type '" "SimulationResult const *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + ecode2 = SWIG_AsVal_size_t(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SimulationResult_axis" "', argument " "2"" of type '" "size_t""'"); + } + arg2 = static_cast< size_t >(val2); + ecode3 = SWIG_AsVal_int(obj2, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "SimulationResult_axis" "', argument " "3"" of type '" "AxesUnits""'"); + } + arg3 = static_cast< AxesUnits >(val3); + result = ((SimulationResult const *)arg1)->axis(arg2,arg3); + resultobj = swig::from(static_cast< std::vector< double,std::allocator< double > > >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SimulationResult_axis__SWIG_3(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + size_t arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + size_t val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + std::vector< double,std::allocator< double > > result; + + if (!PyArg_ParseTuple(args,(char *)"OO:SimulationResult_axis",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult_axis" "', argument " "1"" of type '" "SimulationResult const *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + ecode2 = SWIG_AsVal_size_t(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SimulationResult_axis" "', argument " "2"" of type '" "size_t""'"); + } + arg2 = static_cast< size_t >(val2); + result = ((SimulationResult const *)arg1)->axis(arg2); + resultobj = swig::from(static_cast< std::vector< double,std::allocator< double > > >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SimulationResult_axis(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[4] = { + 0 + }; + Py_ssize_t ii; + + if (!PyTuple_Check(args)) SWIG_fail; + argc = args ? PyObject_Length(args) : 0; + for (ii = 0; (ii < 3) && (ii < argc); ii++) { + argv[ii] = PyTuple_GET_ITEM(args,ii); + } + if (argc == 1) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_SimulationResult, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_SimulationResult_axis__SWIG_1(self, args); + } + } + if (argc == 2) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_SimulationResult, 0); + _v = SWIG_CheckState(res); + if (_v) { + { + int res = SWIG_AsVal_int(argv[1], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_SimulationResult_axis__SWIG_0(self, args); + } + } + } + if (argc == 2) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_SimulationResult, 0); + _v = SWIG_CheckState(res); + if (_v) { + { + int res = SWIG_AsVal_size_t(argv[1], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_SimulationResult_axis__SWIG_3(self, args); + } + } + } + if (argc == 3) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_SimulationResult, 0); + _v = SWIG_CheckState(res); + if (_v) { + { + int res = SWIG_AsVal_size_t(argv[1], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + { + int res = SWIG_AsVal_int(argv[2], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_SimulationResult_axis__SWIG_2(self, args); + } + } + } + } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'SimulationResult_axis'.\n" + " Possible C/C++ prototypes are:\n" + " SimulationResult::axis(AxesUnits) const\n" + " SimulationResult::axis() const\n" + " SimulationResult::axis(size_t,AxesUnits) const\n" + " SimulationResult::axis(size_t) const\n"); + return 0; +} + + SWIGINTERN PyObject *_wrap_delete_SimulationResult(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; SimulationResult *arg1 = (SimulationResult *) 0 ; @@ -129989,6 +130197,12 @@ static PyMethodDef SwigMethods[] = { "returns data as Python numpy array \n" "\n" ""}, + { (char *)"SimulationResult_axis", _wrap_SimulationResult_axis, METH_VARARGS, (char *)"\n" + "axis(AxesUnits units) -> vdouble1d_t\n" + "axis() -> vdouble1d_t\n" + "axis(size_t i_axis, AxesUnits units) -> vdouble1d_t\n" + "SimulationResult_axis(SimulationResult self, size_t i_axis) -> vdouble1d_t\n" + ""}, { (char *)"delete_SimulationResult", _wrap_delete_SimulationResult, METH_VARARGS, (char *)"delete_SimulationResult(SimulationResult self)"}, { (char *)"SimulationResult_swigregister", SimulationResult_swigregister, METH_VARARGS, NULL}, { (char *)"delete_IBackground", _wrap_delete_IBackground, METH_VARARGS, (char *)"\n" -- GitLab