Mantid
Loading...
Searching...
No Matches
InterpolationOption.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidHistogramData/Interpolate.h"
11
12#include <cassert>
13
14namespace {
15// The name of the interpolation property
16std::string PROP_NAME("Interpolation");
17std::string LINEAR_OPT("Linear");
18std::string CSPLINE_OPT("CSpline");
19std::vector<std::string> OPTIONS{LINEAR_OPT, CSPLINE_OPT};
20} // namespace
21
22namespace Mantid {
23using HistogramData::interpolateCSplineInplace;
24using HistogramData::interpolateLinearInplace;
25using HistogramData::minSizeForCSplineInterpolation;
26using HistogramData::minSizeForLinearInterpolation;
27using Kernel::Property;
28
29namespace Algorithms {
30
38void InterpolationOption::set(const InterpolationOption::Value &kind, const bool calculateErrors,
39 const bool independentErrors) {
40 m_value = kind;
41 m_calculateErrors = calculateErrors;
42 m_independentErrors = independentErrors;
43}
44
52void InterpolationOption::set(const std::string &kind, const bool calculateErrors, const bool independentErrors) {
53 if (kind == LINEAR_OPT) {
55 } else if (kind == CSPLINE_OPT) {
57 } else {
58 throw std::invalid_argument("InterpolationOption::set() - Unknown interpolation method '" + kind + "'");
59 }
60 m_calculateErrors = calculateErrors;
61 m_independentErrors = independentErrors;
62}
63
69std::unique_ptr<Property> InterpolationOption::property() const {
71 using StringProperty = Kernel::PropertyWithValue<std::string>;
72
73 return std::make_unique<StringProperty>(PROP_NAME, LINEAR_OPT, std::make_shared<StringListValidator>(OPTIONS));
74}
75
80 return "Method of interpolation used to compute unsimulated values.";
81}
82
88std::string InterpolationOption::validateInputSize(const size_t size) const {
89 size_t nMin;
90 switch (m_value) {
91 case Value::Linear:
92 nMin = minSizeForLinearInterpolation();
93 if (size < nMin) {
94 return "Linear interpolation requires at least " + std::to_string(nMin) + " points.";
95 }
96 break;
97 case Value::CSpline:
98 nMin = minSizeForCSplineInterpolation();
99 if (size < nMin) {
100 return "CSpline interpolation requires at least " + std::to_string(nMin) + " points.";
101 }
102 break;
103 }
104 return std::string();
105}
106
112void InterpolationOption::applyInplace(HistogramData::Histogram &inOut, size_t stepSize) const {
113 switch (m_value) {
114 case Value::Linear:
115 interpolateLinearInplace(inOut, stepSize, m_calculateErrors, m_independentErrors);
116 return;
117 case Value::CSpline:
118 interpolateCSplineInplace(inOut, stepSize, m_calculateErrors, m_independentErrors);
119 return;
120 default:
121 throw std::runtime_error("InterpolationOption::applyInplace() - "
122 "Unimplemented interpolation method.");
123 }
124}
125
132void InterpolationOption::applyInPlace(const HistogramData::Histogram &in, HistogramData::Histogram &out) const {
133 switch (m_value) {
134 case Value::Linear:
135 interpolateLinearInplace(in, out, m_calculateErrors, m_independentErrors);
136 return;
137 case Value::CSpline:
138 interpolateCSplineInplace(in, out, m_calculateErrors, m_independentErrors);
139 return;
140 default:
141 throw std::runtime_error("InterpolationOption::applyInplace() - "
142 "Unimplemented interpolation method.");
143 }
144}
145
146} // namespace Algorithms
147} // namespace Mantid
Kind kind
The kind of the point: either openning or closing the range.
Definition: FitMW.cpp:49
std::unique_ptr< Kernel::Property > property() const
Create a property suitable to attach to an algorithm to support interpolation.
std::string validateInputSize(const size_t size) const
Validate the size of input histogram.
void applyInPlace(const HistogramData::Histogram &in, HistogramData::Histogram &out) const
Apply the interpolation method to the output histogram.
void set(const Value &kind, const bool calculateErrors, const bool independentErrors)
Set the interpolation option.
void applyInplace(HistogramData::Histogram &inOut, size_t stepSize) const
Apply the interpolation method to the given histogram.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
Definition: ListValidator.h:29
The concrete, templated class for properties.
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)