20#include <boost/algorithm/string/detail/classification.hpp>
21#include <boost/algorithm/string/split.hpp>
28using namespace Kernel;
32enum class FilterType { ZERO, BUTTERWORTH, enum_count };
33const std::vector<std::string>
filterTypes{
"Zeroing",
"Butterworth"};
47 FFTParamsProperty(std::string
const &
name, std::vector<param_t>
const &defaultValue)
49 std::string setValue(std::string
const &
value)
override {
50 std::string valueCopy(
value);
51 boost::trim(valueCopy);
55 std::vector<param_t> result;
65 static char constexpr m_sep =
',';
66 static char constexpr m_delims[] = {
'\t',
' ',
':',
';'};
74 "The name of the input workspace.");
77 "The name of the output workspace.");
79 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
80 mustBePositive->setLower(0);
84 "The type of the applied filter");
87 "The filter parameters:\n"
88 "For Zeroing, 1 parameter: 'n' - an integer greater than 1 "
89 "meaning that the Fourier coefficients with frequencies "
90 "outside the 1/n of the original range will be set to zero.\n"
91 "For Butterworth, 2 parameters: 'n' and 'order', giving the "
92 "1/n truncation and the smoothing order.\n");
95 "Ignores the requirement that X bins be linear and of the same size.\n"
96 "Set this to true if you are using log binning.\n"
97 "The output X axis will be the same as the input either way.");
102 std::map<std::string, std::string> issues;
105 if (groupWS !=
nullptr) {
106 for (std::size_t idx = 0; idx < groupWS->size(); idx++) {
108 for (
auto const &[key,
value] : subissues) {
110 issues[new_key] =
value;
120 std::map<std::string, std::string> issues;
130 if (wi >=
static_cast<int>(inWS->getNumberHistograms())) {
139 const auto &
X = inWS->x(wi);
140 double dx = (
X.back() -
X.front()) /
static_cast<double>(
X.size() - 1);
141 for (
size_t i = 0; i <
X.size() - 2; i++) {
142 if (std::abs(dx -
X[i + 1] +
X[i]) / dx > 1e-7) {
144 "IgnoreXBins is set to true.";
153 std::string
const trunc_err =
"Cutoff parameter must be an integer > 1. ";
154 std::string
const order_err =
"Butterworth filter order must be an integer >= 1. ";
156 if (params.size() > 0 && params[0] <= 1) {
157 err_msg += trunc_err;
159 if (params.size() > 1 && params[1] < 1) {
160 err_msg += order_err;
162 if (params.size() > 2) {
163 err_msg +=
"Too many parameters passed";
165 if (!err_msg.empty()) {
177 std::size_t
n = 2, order = 2;
179 if (params.size() == 1) {
181 }
else if (params.size() == 2) {
186 std::size_t dn = inWS->y(0).size();
190 std::function<std::vector<double>(std::vector<double>
const &)> smoothMethod;
192 case FilterType::ZERO: {
200 unsigned adjusted_cutoff = (
n > dn ? 1 :
static_cast<unsigned>((dn + 1) /
n));
201 smoothMethod = [adjusted_cutoff](std::vector<double>
const &
y) {
206 case FilterType::BUTTERWORTH: {
208 unsigned adjusted_cutoff = (
n > dn ? 1 :
static_cast<unsigned>((dn + 1) /
n));
209 smoothMethod = [adjusted_cutoff, order](std::vector<double>
const &
y) {
215 smoothMethod = [](std::vector<double>
const &
y) {
return y; };
222 std::size_t send = s0 + 1;
225 send = inWS->getNumberHistograms();
233 for (std::size_t spec = s0; spec < send; spec++) {
245 std::vector<double> symY(2 * dn);
246 for (std::size_t i = 0; i < dn; i++) {
247 symY[dn + i] = inWS->y(spec)[i];
248 symY[dn - i] = inWS->y(spec)[i];
250 symY.front() = inWS->y(spec).back();
254 std::vector<double> tmpY = smoothMethod(symY);
258 outWS->setSharedX(spec, inWS->sharedX(spec));
259 outWS->mutableY(spec).assign(tmpY.cbegin() + dn, tmpY.cend());
261 outWS->setSharedX(0, inWS->sharedX(spec));
262 outWS->mutableY(0).assign(tmpY.cbegin() + dn, tmpY.cend());
#define DECLARE_ALGORITHM(classname)
static char constexpr m_sep
static char constexpr m_delims[]
const std::vector< std::string > filterTypes
double value
The value of the point.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Base MatrixWorkspace Abstract Class.
Helper class for reporting progress from algorithms.
Class to hold a set of workspaces.
A property class for workspaces.
void init() override
Initialisation method. Declares properties to be used in algorithm.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
void exec() override
Executes the algorithm.
std::map< std::string, std::string > actuallyValidateInputs(API::Workspace_sptr const &)
Mantid::Kernel::EnumeratedString< FilterType, &filterTypes > FILTER
Support for a property that holds an array of values.
A concrete property based on user options of a finite list of strings.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string const OUTPUT_WKSP("OutputWorkspace")
std::string const INPUT_WKSP("InputWorkspace")
std::string const FILTER("Filter")
std::string const IGNORE_X_BINS("IgnoreXBins")
std::string const ALL_SPECTRA("AllSpectra")
std::string const WKSP_INDEX("WorkspaceIndex")
std::string const PARAMS("Params")
std::vector< Y > fftButterworthSmooth(std::vector< Y > const &input, unsigned const cutoff, unsigned const order)
Performs FFT smoothing on the input data, using a Butterworth filter NOTE: the input data MUST be def...
std::vector< Y > fftSmooth(std::vector< Y > const &input, unsigned const cutoff)
Performs FFT smoothing on the input data, with high frequencies set to zero NOTE: the input data MUST...
MANTID_KERNEL_DLL std::string replaceAll(std::string const &input, char const to_replace, char const substitute)
Return a string with all occurrences of indicated character replaced by the new character.
void toValue(const std::string &strvalue, T &value)
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.