From 12fd4794d45c98c4c2279940d67504d61349b92d Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 2 Jun 2015 09:46:56 +0100 Subject: [PATCH] Fix issue with vertical axis Refs #11873 --- .../MantidCurveFitting/SplineInterpolation.h | 5 ++-- .../CurveFitting/src/SplineInterpolation.cpp | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SplineInterpolation.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SplineInterpolation.h index fc5f6cb273e1..b75259124c0c 100644 --- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SplineInterpolation.h +++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/SplineInterpolation.h @@ -66,8 +66,9 @@ class DLLExport SplineInterpolation : public API::Algorithm { /// setup an output workspace using meta data from inws and taking a number of /// spectra - API::MatrixWorkspace_sptr setupOutputWorkspace(API::MatrixWorkspace_sptr inws, - int size) const; + API::MatrixWorkspace_sptr + setupOutputWorkspace(API::MatrixWorkspace_sptr mws, + API::MatrixWorkspace_sptr iws) const; /// convert a binned workspace to point data. Uses mean of the bins as point API::MatrixWorkspace_sptr diff --git a/Code/Mantid/Framework/CurveFitting/src/SplineInterpolation.cpp b/Code/Mantid/Framework/CurveFitting/src/SplineInterpolation.cpp index c15c40e41a5f..06f098090762 100644 --- a/Code/Mantid/Framework/CurveFitting/src/SplineInterpolation.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/SplineInterpolation.cpp @@ -1,4 +1,5 @@ #include "MantidAPI/TextAxis.h" +#include "MantidAPI/NumericAxis.h" #include "MantidAPI/Progress.h" #include "MantidKernel/BoundedValidator.h" #include "MantidCurveFitting/SplineInterpolation.h" @@ -90,7 +91,7 @@ void SplineInterpolation::exec() { MatrixWorkspace_sptr mwspt = convertBinnedData(mws); MatrixWorkspace_const_sptr iwspt = convertBinnedData(iws); - MatrixWorkspace_sptr outputWorkspace = setupOutputWorkspace(mws, histNo); + MatrixWorkspace_sptr outputWorkspace = setupOutputWorkspace(mws, iws); Progress pgress(this, 0.0, 1.0, histNo); @@ -107,12 +108,17 @@ void SplineInterpolation::exec() { // check if we want derivatives if (order > 0) { + derivs[i] = WorkspaceFactory::Instance().create(mws, order); + NumericAxis *vAxis = new API::NumericAxis(order); + // calculate the derivatives for each order chosen - derivs[i] = setupOutputWorkspace(mws, order); for (int j = 0; j < order; ++j) { + vAxis->setValue(j, j + 1); derivs[i]->setX(j, mws->readX(0)); calculateDerivatives(mwspt, derivs[i], j + 1); } + + derivs[i]->replaceAxis(1, vAxis); } pgress.report(); @@ -136,15 +142,20 @@ void SplineInterpolation::exec() { *it with the desired number of spectra. * Also labels the axis of each spectra with Yi, where i is the index * - * @param inws :: The input workspace - * @param size :: The number of spectra the workspace should be created with + * @param mws :: The input workspace to match + * @param iws :: The input workspace to interpolate * @return The pointer to the newly created workspace */ API::MatrixWorkspace_sptr -SplineInterpolation::setupOutputWorkspace(API::MatrixWorkspace_sptr inws, - int size) const { +SplineInterpolation::setupOutputWorkspace(API::MatrixWorkspace_sptr mws, + API::MatrixWorkspace_sptr iws) const { + size_t numSpec = iws->getNumberHistograms(); MatrixWorkspace_sptr outputWorkspace = - WorkspaceFactory::Instance().create(inws, size); + WorkspaceFactory::Instance().create(mws, numSpec); + + // Use the vertical axis form the workspace to interpolate on the output WS + Axis *vAxis = iws->getAxis(1); + outputWorkspace->replaceAxis(1, vAxis); return outputWorkspace; }