Mantid
Loading...
Searching...
No Matches
ReplaceSpecialValues.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12#include <cmath>
13#include <limits>
14
15using namespace Mantid::API;
16using namespace Mantid::Kernel;
17
18namespace Mantid::Algorithms {
19
20// Register the class into the algorithm factory
21DECLARE_ALGORITHM(ReplaceSpecialValues)
22
24 : UnaryOperation(), m_NaNValue(0.), m_NaNError(0.), m_InfiniteValue(0.), m_InfiniteError(0.), m_bigThreshold(0.),
25 m_bigValue(0.), m_bigError(0.), m_performNaNCheck(false), m_performInfiniteCheck(false), m_performBigCheck(false),
26 m_checkErrors(false) {}
27
29 // NaN properties
31 "The value used to replace occurrences of NaN "
32 "(default: do not check).");
33 declareProperty("NaNError", 0.0, "The error value used when replacing a value of NaN ");
34 // Infinity properties
35 declareProperty("InfinityValue", Mantid::EMPTY_DBL(),
36 "The value used to replace occurrences of positive or negative infinity "
37 "(default: do not check).");
38 declareProperty("InfinityError", 0.0, "The error value used when replacing a value of infinity ");
39 // Big number properties
40 declareProperty("BigNumberThreshold", Mantid::EMPTY_DBL(),
41 "The threshold above which a number (positive or negative) "
42 "should be replaced. "
43 "(default: do not check)");
44 declareProperty("BigNumberValue", 0.0, "The value with which to replace occurrences of 'big' numbers.");
45 declareProperty("BigNumberError", 0.0, "The error value used when replacing a 'big' number");
46 // Small number properties
47 declareProperty("SmallNumberThreshold", Mantid::EMPTY_DBL(),
48 "The threshold below which a number (positive or negative) "
49 "should be replaced. (default: do not check)");
50 declareProperty("SmallNumberValue", 0.0, "The value with which to replace occurrences of 'small' numbers.");
51 declareProperty("SmallNumberError", 0.0, "The error value used when replacing a 'small' number");
52 declareProperty("CheckErrorAxis", false, "Whether or not to also check the error axis values.");
53 declareProperty("UseAbsolute", true, "Whether large and small comparisons should be done on absolute values.");
54}
55
57 m_NaNValue = getProperty("NaNValue");
58 m_NaNError = getProperty("NaNError");
59 m_InfiniteValue = getProperty("InfinityValue");
60 m_InfiniteError = getProperty("InfinityError");
61 m_bigThreshold = getProperty("BigNumberThreshold");
62 m_bigValue = getProperty("BigNumberValue");
63 m_bigError = getProperty("BigNumberError");
64 m_smallThreshold = getProperty("SmallNumberThreshold");
65 m_smallValue = getProperty("SmallNumberValue");
66 m_smallError = getProperty("SmallNumberError");
67 m_checkErrors = getProperty("CheckErrorAxis");
68 m_useAbsolute = getProperty("UseAbsolute");
69
74
76
77 if (!replacement_set) {
78 throw std::invalid_argument("No value was defined for NaN, infinity, "
79 "BigValueThreshold or SmallValueThreshold");
80 }
81}
82
83void ReplaceSpecialValues::performUnaryOperation(const double XIn, const double YIn, const double EIn, double &YOut,
84 double &EOut) {
85 (void)XIn; // Avoid compiler warning
86 YOut = YIn;
87 EOut = EIn;
88
89 if (m_performNaNCheck && (checkIfNan(YIn) || (m_checkErrors && checkIfNan(EIn)))) {
90 YOut = m_NaNValue;
91 EOut = m_NaNError;
92 } else if (m_performInfiniteCheck && (checkIfInfinite(YIn) || (m_checkErrors && checkIfInfinite(EIn)))) {
93 YOut = m_InfiniteValue;
94 EOut = m_InfiniteError;
95 } else if (m_performBigCheck && (checkIfBig(YIn) || (m_checkErrors && checkIfBig(EIn)))) {
96 YOut = m_bigValue;
97 EOut = m_bigError;
98 } else if (m_performSmallCheck && (checkIfSmall(YIn) || (m_checkErrors && checkIfSmall(EIn)))) {
99 YOut = m_smallValue;
100 EOut = m_smallError;
101 }
102}
103
104bool ReplaceSpecialValues::checkIfNan(const double value) const { return (std::isnan(value)); }
105
106bool ReplaceSpecialValues::checkIfInfinite(const double value) const { return (std::isinf(value)); }
107
108bool ReplaceSpecialValues::checkIfBig(const double value) const {
109 return m_useAbsolute ? std::abs(value) > m_bigThreshold : value > m_bigThreshold;
110}
111
114}
115
117 return (std::abs(value - Mantid::EMPTY_DBL()) < 1e-08);
118}
119
120} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double value
The value of the point.
Definition: FitMW.cpp:51
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Replaces instances of NaN and infinity in the workspace with user defined numbers.
void defineProperties() override
A virtual function in which additional properties of an algorithm should be declared.
double m_smallError
The replacement error value for small numbers.
double m_bigError
The replacement error value for big numbers.
void retrieveProperties() override
A virtual function in which additional properties should be retrieved into member variables.
double m_InfiniteError
The replacement error value for infinity.
bool checkIfNan(const double value) const
returns true if the value is NaN
bool m_performNaNCheck
Flag to indicate if the NaN check is to be.
bool checkIfInfinite(const double value) const
returns true if the value if + or - infinity
double m_NaNError
The replacement error value for NaN.
void performUnaryOperation(const double XIn, const double YIn, const double EIn, double &YOut, double &EOut) override
Carries out the Unary operation on the current 'cell'.
double m_smallThreshold
The threshold value below which a value is 'small'.
double m_InfiniteValue
The replacement value for infinity.
bool m_useAbsolute
Flag to indicate if the algorithm should use the absolute value when comparing big and small checks.
double m_NaNValue
The replacement value for NaN.
bool checkifPropertyEmpty(const double value) const
returns true if the value has been set
double m_bigThreshold
The threshold value above which a value is.
double m_smallValue
The replacement value for small numbers.
bool checkIfBig(const double value) const
Returns true if the absolute value is larger than the 'big' threshold.
bool checkIfSmall(const double value) const
Returns true is the absolute value is smaller than the 'small' threshold.
UnaryOperation supports the implementation of a Unary operation on an input workspace.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43