18using Mantid::Types::Core::DateAndTime;
32 "An input/output workspace. The new log will be added to it.");
34 "The name that will identify the log entry to perform a derivative.\n"
35 "This log must be a numerical series (double).");
37 "How many derivatives to perform. Default 1.");
38 declareProperty(
"NewLogName",
"",
39 "Name of the newly created log. If not "
40 "specified, the string '_derivativeN' will "
41 "be appended to the original name");
55 const std::string &name,
int numDerivatives) {
56 if (input->
size() < numDerivatives + 1)
59 " to make this derivative.");
61 std::vector<double> values, dVal;
62 std::vector<double> times, dTime;
66 for (
int deriv = 0; deriv < numDerivatives; deriv++) {
70 double y0 = values[0];
71 for (
size_t i = 0; i < times.size() - 1; i++) {
72 double y1 = values[i + 1];
73 double t1 = times[i + 1];
76 double dy = (y1 - y0) / (t1 - t0);
77 double t = (t0 + t1) / 2.0;
78 dVal.emplace_back(dy);
79 dTime.emplace_back(t);
88 progress.report(
"Add Log Derivative");
92 throw std::runtime_error(
"Log " + input->
name() +
93 " did not have enough non-repeated time values to "
94 "make this derivative.");
97 DateAndTime start = input->
nthTime(0);
98 std::vector<DateAndTime> timeFull;
99 timeFull.reserve(times.size());
101 std::transform(times.begin(), times.end(), std::back_inserter(timeFull),
102 [&start](
const double time) { return start + time; });
106 out->addValues(timeFull, values);
121 if (NewLogName.empty())
124 Run &run = ws->mutableRun();
126 throw std::invalid_argument(
"Log " + LogName +
" not found in the workspace sample logs.");
129 throw std::invalid_argument(
"Log " + LogName +
" not found in the workspace sample logs.");
132 throw std::invalid_argument(
"Log " + LogName +
133 " is not a numerical series "
134 "(TimeSeriesProperty<double>"
135 ") so we can't perform its "
145 g_log.
notice() <<
"Added log named " << NewLogName <<
'\n';
#define DECLARE_ALGORITHM(classname)
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.
bool hasProperty(const std::string &name) const
Does the property exist on the object.
Kernel::Property * getProperty(const std::string &name) const
Returns the named property as a pointer.
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Helper class for reporting progress from algorithms.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
Takes an existing sample log, and calculates its first or second derivative, and adds it as a new log...
void exec() override
Run the algorithm.
static Mantid::Kernel::TimeSeriesProperty< double > * makeDerivative(API::Progress &progress, Mantid::Kernel::TimeSeriesProperty< double > *input, const std::string &name, int numDerivatives)
Perform the N^th derivative of a log.
const std::string name() const override
Algorithm's name for identification.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
void notice(const std::string &msg)
Logs at notice level.
Validator to check that a property is not left empty.
Base class for properties.
const std::string & name() const
Get the property's name.
A specialised Property class for holding a series of time-value pairs.
int size() const override
Returns the number of values at UNIQUE time intervals in the time series.
std::vector< TYPE > valuesAsVector() const
Return the time series's values (unfiltered) as a vector<TYPE>
std::vector< double > timesAsVectorSeconds() const
Return the series as list of times, where the time is the number of seconds since the start.
Types::Core::DateAndTime nthTime(int n) const
Returns n-th time. NOTE: Complexity is order(n)! regardless of filter.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string toString(const T &value)
Convert a number to a string.
@ InOut
Both an input & output workspace.