Skip to content

Commit

Permalink
Rebin parameters don't all apply to InterpolatingRebin
Browse files Browse the repository at this point in the history
Also amalgamates code to accept single bin width as input rebin parameter.
Refs #9574
  • Loading branch information
martyngigg committed Jun 6, 2014
1 parent 7024251 commit 13540f0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 deletions.
Expand Up @@ -5,7 +5,6 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/Rebin.h"
#include "MantidDataObjects/Histogram1D.h"

namespace Mantid
{
Expand Down Expand Up @@ -59,17 +58,17 @@ namespace Algorithms
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport InterpolatingRebin : public Algorithms::Rebin
class DLLExport InterpolatingRebin : public Rebin
{
public:
/// Default constructor
InterpolatingRebin() : Algorithms::Rebin() {};
InterpolatingRebin() : Rebin() {}
/// Destructor
virtual ~InterpolatingRebin() {};
virtual ~InterpolatingRebin() {}
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "InterpolatingRebin";}
///Summary of algorithms purpose
virtual const std::string summary() const {return "Creates a workspace with different x-value bin boundaries where the new y-values are estimated using cubic splines.";}
///Summary of algorithms purpose
virtual const std::string summary() const {return "Creates a workspace with different x-value bin boundaries where the new y-values are estimated using cubic splines.";}

/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1;}
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h
Expand Up @@ -66,6 +66,10 @@ class DLLExport Rebin : public API::Algorithm
/// Algorithm's aliases
virtual const std::string alias() const { return "rebin"; }

static std::vector<double> rebinParamsFromInput(const std::vector<double> & inParams,
const API::MatrixWorkspace & inputWS,
Kernel::Logger & logger);

protected:

const std::string workspaceMethodName() const { return "rebin"; }
Expand Down
26 changes: 21 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/InterpolatingRebin.cpp
Expand Up @@ -2,6 +2,8 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/InterpolatingRebin.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/RebinParamsValidator.h"
#include "MantidKernel/VectorHelper.h"
#include <gsl/gsl_errno.h>
#include <gsl/gsl_interp.h>
Expand All @@ -24,7 +26,21 @@ namespace Mantid
*/
void InterpolatingRebin::init()
{
Rebin::init();
declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"Workspace containing the input data");
declareProperty(
new WorkspaceProperty<>("OutputWorkspace","",Direction::Output),
"The name to give the output workspace");

declareProperty(
new ArrayProperty<double>("Params", boost::make_shared<RebinParamsValidator>()),
"A comma separated list of first bin boundary, width, last bin boundary. Optionally "
"this can be followed by a comma and more widths and last boundary pairs. "
"Optionally this can also be a single number, which is the bin width. "
"In this case, the boundary of binning will be determined by minimum and maximum TOF "
"values among all events, or previous binning boundary, in case of event Workspace, or "
"non-event Workspace, respectively. Negative width values indicate logarithmic binning. ");
}

/** Executes the rebin algorithm
Expand All @@ -33,16 +49,16 @@ namespace Mantid
*/
void InterpolatingRebin::exec()
{
// retrieve the properties
std::vector<double> rb_params=getProperty("Params");
// Get the input workspace
MatrixWorkspace_sptr inputW = getProperty("InputWorkspace");

// retrieve the properties
std::vector<double> rb_params = Rebin::rebinParamsFromInput(getProperty("Params"), *inputW, g_log);
MantidVecPtr XValues_new;
// create new output X axis
const int ntcnew =
VectorHelper::createAxisFromRebinParams(rb_params,XValues_new.access());

// Get the input workspace
MatrixWorkspace_sptr inputW = getProperty("InputWorkspace");
const int nHists = static_cast<int>(inputW->getNumberHistograms());
// make output Workspace the same type as the input but with the new axes
MatrixWorkspace_sptr outputW =
Expand Down
67 changes: 43 additions & 24 deletions Code/Mantid/Framework/Algorithms/src/Rebin.cpp
Expand Up @@ -18,14 +18,54 @@ namespace Mantid
// Register the class into the algorithm factory
DECLARE_ALGORITHM(Rebin)


using namespace Kernel;
using namespace API;
using DataObjects::EventList;
using DataObjects::EventWorkspace;
using DataObjects::EventWorkspace_sptr;
using DataObjects::EventWorkspace_const_sptr;

//---------------------------------------------------------------------------------------------
// Public static methods
//---------------------------------------------------------------------------------------------

/**
* Return the rebin parameters from a user input
* @params inParams Input vector from user
* @params inputWS Input workspace from user
* logger A reference to a logger
* @returns A new vector containing the rebin parameters
*/
std::vector<double> Rebin::rebinParamsFromInput(const std::vector<double> & inParams,
const API::MatrixWorkspace & inputWS,
Kernel::Logger & logger)
{
std::vector<double> rbParams;
// The validator only passes parameters with size 1, or 3xn. No need to check again here
if (inParams.size() >= 3)
{
// Input are min, delta, max
rbParams = inParams;
}
else if (inParams.size() == 1)
{
double xmin = 0.;
double xmax = 0.;
inputWS.getXMinMax(xmin, xmax);

logger.information() << "Using the current min and max as default " << xmin << ", " << xmax << std::endl;
rbParams.resize(3);
rbParams[0] = xmin;
rbParams[1] = inParams[0];
rbParams[2] = xmax;
}
return rbParams;
}

//---------------------------------------------------------------------------------------------
// Public methods
//---------------------------------------------------------------------------------------------

/** Initialisation method. Declares properties to be used in algorithm.
*
*/
Expand Down Expand Up @@ -72,30 +112,9 @@ namespace Mantid
// Rebinning in-place
bool inPlace = (inputWS == outputWS);

// retrieve the properties
const std::vector<double> in_params=getProperty("Params");
std::vector<double> rb_params;

// The validator only passes parameters with size 1, or 3xn. No need to check again here
if (in_params.size() >= 3){
// Input are min, delta, max
rb_params = in_params;

} else if (in_params.size() == 1){
double xmin = 0.;
double xmax = 0.;
inputWS->getXMinMax(xmin, xmax);

g_log.information() << "Using the current min and max as default " << xmin << ", " << xmax << std::endl;

rb_params.push_back(xmin);
rb_params.push_back(in_params[0]);
rb_params.push_back(xmax);

}
std::vector<double> rbParams = rebinParamsFromInput(getProperty("Params"), *inputWS, g_log);

const bool dist = inputWS->isDistribution();

const bool isHist = inputWS->isHistogramData();

// workspace independent determination of length
Expand All @@ -105,7 +124,7 @@ namespace Mantid

MantidVecPtr XValues_new;
// create new output X axis
const int ntcnew = VectorHelper::createAxisFromRebinParams(rb_params, XValues_new.access(),
const int ntcnew = VectorHelper::createAxisFromRebinParams(rbParams, XValues_new.access(),
true, fullBinsOnly);

//---------------------------------------------------------------------------------
Expand Down

0 comments on commit 13540f0

Please sign in to comment.