26using namespace Kernel;
30std::string
const INPUT_WKSP(
"Workspace");
31std::string
const LOG_INTERP(
"LogToInterpolate");
32std::string
const LOG_MATCH(
"LogToMatch");
33std::string
const NEW_LOG_NAME(
"NewLogName");
44 "An input/output workspace containing the log to interpolate. The new log will be added to it.");
47 "The name of the log entry to be interpolated. This log must be a numerical series (double).");
51 "The name of the log entry defining the interpolation points. This log must be a numerical series (double).");
54 "Name of the newly created log. If not specified, the string '_interpolated' will be appended to the "
62 std::map<std::string, std::string> issues;
72 Run const &run = ws->run();
75 issues[PropertyNames::LOG_INTERP] =
"Log " + logInterp +
" not found in the workspace sample logs.";
79 issues[PropertyNames::LOG_MATCH] =
"Log " + logMatch +
" not found in the workspace sample logs.";
81 if (!issues.empty()) {
88 issues[PropertyNames::LOG_MATCH] =
"Log " + logMatch +
" must be a numerical time series (TimeSeries<double>).";
92 issues[PropertyNames::LOG_INTERP] =
"Log " + logInterp +
" must be a numerical time series (TimeSeries<double>).";
95 issues[PropertyNames::LOG_INTERP] =
"Log " + logInterp +
96 " has insufficient number of points: " +
std::to_string(tspInterp->size()) +
112 if (newLogName.empty())
113 newLogName = logInterp +
"_interpolated";
116 Run &run = ws->mutableRun();
119 std::vector<double> timesInterp = tspInterp->timesAsVectorSeconds();
126 std::span<double const> newTimesInRange(newTimes.cbegin() + range.first, range.second - range.first);
127 std::vector<DateAndTime> datetimes = tspMatch->timesAsVector();
128 std::vector<DateAndTime> newDatetimesInRange(datetimes.cbegin() + range.first, datetimes.cbegin() + range.second);
131 auto tspOutput = std::make_unique<TimeSeriesProperty<double>>(newLogName);
132 std::vector<double> newValues =
134 tspOutput->addValues(newDatetimesInRange, newValues);
138 g_log.
notice() <<
"Added log named " << newLogName <<
" to " << ws->getName() <<
'\n';
149 std::vector<double>
const &xAxisOut)
const {
150 size_t firstIndex = 0;
151 size_t lastIndex = xAxisOut.size();
153 if (xAxisOut.empty() || xAxisIn.empty()) {
156 if (xAxisOut.front() >= xAxisIn.back()) {
157 lastIndex = firstIndex;
158 }
else if (xAxisOut.back() <= xAxisIn.front()) {
159 firstIndex = lastIndex;
162 std::find_if(xAxisOut.cbegin(), xAxisOut.cend(), [&xAxisIn](
double x) { return x >= xAxisIn.front(); });
163 firstIndex = std::distance(xAxisOut.begin(), start);
164 auto stop = std::find_if(start, xAxisOut.cend(), [&xAxisIn](
double x) { return x > xAxisIn.back(); });
165 lastIndex = std::distance(xAxisOut.begin(), stop);
168 return std::make_pair(firstIndex, lastIndex);
#define DECLARE_ALGORITHM(classname)
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.
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.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
std::pair< size_t, size_t > findInterpolationRange(std::vector< double > const &, std::vector< double > const &) const
Find the overlap region of the two axes, given as two indices within xAxisOut.
std::map< std::string, std::string > validateInputs() override
Validate input parameters.
void exec() override
Run the algorithm.
void init() override
Initialise the properties.
static std::vector< Y > getSplinedYValues(std::span< X const > newX, std::span< X const > x, std::span< Y const > y)
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Validator to check that a property is not left empty.
A specialised Property class for holding a series of time-value pairs.
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.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr unsigned int MIN_CSPLINE_POINTS
Minimum number of points needed to fit a cubic spline in GSL.
const std::string INPUT_WKSP("InputWorkspace")
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.