Mantid
Loading...
Searching...
No Matches
TimeSeriesProperty.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13#include "MantidKernel/DllConfig.h"
17#include <cstdint>
18#include <utility>
19
20// Forward declare
21namespace NeXus {
22class File;
23}
24
25namespace Mantid {
26namespace Kernel {
27class DataItem;
28class SplittingInterval;
29
31
32//=========================================================================
38 double minimum;
40 double maximum;
42 double mean;
44 double median;
48 double time_mean;
52 double duration;
53};
54
55//================================================================================================
59template <class TYPE> class TimeValueUnit {
60private:
61 Types::Core::DateAndTime mtime;
63
64public:
65 TimeValueUnit(const Types::Core::DateAndTime &time, const TYPE &value) : mtime(time), mvalue(value) {}
66
67 ~TimeValueUnit() = default;
68
69 bool operator>(const TimeValueUnit &rhs) { return (mtime > rhs.mtime); }
70
71 friend bool operator>(const TimeValueUnit &lhs, const TimeValueUnit &rhs) { return (lhs.mtime > rhs.mtime); }
72
73 bool operator==(const TimeValueUnit &rhs) { return (mtime == rhs.mtime); }
74
75 friend bool operator==(const TimeValueUnit &lhs, const TimeValueUnit &rhs) { return (lhs.mtime == rhs.mtime); }
76
77 bool operator<(const TimeValueUnit &rhs) { return (mtime < rhs.mtime); }
78
79 friend bool operator<(const TimeValueUnit &lhs, const TimeValueUnit &rhs) { return (lhs.mtime < rhs.mtime); }
80
81 Types::Core::DateAndTime time() const { return mtime; }
82
83 void setTime(Types::Core::DateAndTime newtime) { mtime = newtime; }
84
85 TYPE value() const { return mvalue; }
86
87 static bool valueCmp(const TimeValueUnit &lhs, const TimeValueUnit &rhs) { return (lhs.mvalue < rhs.mvalue); }
88};
89//========================================================================================================
90
94template <typename TYPE> class DLLExport TimeSeriesProperty : public Property, public ITimeSeriesProperty {
95public:
97 explicit TimeSeriesProperty(const std::string &name);
98 TimeSeriesProperty(const std::string &name, const std::vector<Types::Core::DateAndTime> &times,
99 const std::vector<TYPE> &values);
100
104 TimeSeriesProperty<TYPE> *clone() const override;
105 //
108 std::unique_ptr<TimeSeriesProperty<double>> getDerivative() const;
109
110 void saveProperty(::NeXus::File *file) override;
111 Json::Value valueAsJson() const override;
112
114 Property *cloneWithTimeShift(const double timeShift) const override;
116 size_t getMemorySize() const override;
118 TimeSeriesProperty<TYPE> &merge(Property *rhs) override;
119
120 //--------------------------------------------------------------------------------------
124 virtual bool operator==(const TimeSeriesProperty<TYPE> &right) const;
126 virtual bool operator!=(const TimeSeriesProperty<TYPE> &right) const;
128 virtual bool operator==(const Property &right) const;
130 virtual bool operator!=(const Property &right) const;
131
133 void setName(const std::string &name);
134
136 void filterByTime(const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &stop) override;
138 void filterByTimes(const std::vector<SplittingInterval> &splittervec);
139
141 void splitByTime(std::vector<SplittingInterval> &splitter, std::vector<Property *> outputs,
142 bool isPeriodic) const override;
143
145 void splitByTimeVector(const std::vector<Types::Core::DateAndTime> &splitter_time_vec,
146 const std::vector<int> &target_vec, const std::vector<TimeSeriesProperty *> &outputs);
147
149 void makeFilterByValue(std::vector<SplittingInterval> &split, double min, double max, double TimeTolerance = 0.0,
150 bool centre = false) const override;
152 void expandFilterToRange(std::vector<SplittingInterval> &split, double min, double max,
153 const TimeInterval &range) const override;
155 double averageValueInFilter(const std::vector<SplittingInterval> &filter) const override;
157 std::pair<double, double> averageAndStdDevInFilter(const std::vector<SplittingInterval> &filter) const override;
159 double timeAverageValue() const override;
161 void histogramData(const Types::Core::DateAndTime &tMin, const Types::Core::DateAndTime &tMax,
162 std::vector<double> &counts) const;
163
166 std::map<Types::Core::DateAndTime, TYPE> valueAsCorrectMap() const;
168 std::vector<TYPE> valuesAsVector() const;
171 std::multimap<Types::Core::DateAndTime, TYPE> valueAsMultiMap() const;
173 std::vector<TYPE> filteredValuesAsVector() const;
174
176 std::vector<Types::Core::DateAndTime> timesAsVector() const override;
178 std::vector<Types::Core::DateAndTime> filteredTimesAsVector() const;
181 std::vector<double> timesAsVectorSeconds() const;
182
184 void addValue(const Types::Core::DateAndTime &time, const TYPE &value);
186 void addValue(const std::string &time, const TYPE &value);
188 void addValue(const std::time_t &time, const TYPE &value);
191 void addValues(const std::vector<Types::Core::DateAndTime> &times, const std::vector<TYPE> &values);
193 void replaceValues(const std::vector<Types::Core::DateAndTime> &times, const std::vector<TYPE> &values);
194
196 Types::Core::DateAndTime lastTime() const;
198 TYPE firstValue() const;
200 Types::Core::DateAndTime firstTime() const;
202 TYPE lastValue() const;
203
205 TYPE minValue() const;
207 TYPE maxValue() const;
209 double mean() const;
210
212 int size() const override;
214 int realSize() const override;
215
216 // ==== The following functions are specific to the odd mechanism of
217 // FilterByLogValue =========
219 std::string value() const override;
221 std::vector<std::string> time_tValue() const;
223 std::map<Types::Core::DateAndTime, TYPE> valueAsMap() const;
224 // ============================================================================================
225
227 std::string setValue(const std::string &) override;
229 std::string setValueFromJson(const Json::Value &) override;
231 std::string setDataItem(const std::shared_ptr<DataItem> &) override;
232
234 void clear() override;
236 void clearOutdated() override;
238 void create(const Types::Core::DateAndTime &start_time, const std::vector<double> &time_sec,
239 const std::vector<TYPE> &new_values);
241 void create(const std::vector<Types::Core::DateAndTime> &new_times, const std::vector<TYPE> &new_values);
242
244 TYPE getSingleValue(const Types::Core::DateAndTime &t) const;
246 TYPE getSingleValue(const Types::Core::DateAndTime &t, int &index) const;
247
249 TimeInterval nthInterval(int n) const;
251 TYPE nthValue(int n) const;
253 Types::Core::DateAndTime nthTime(int n) const;
254
257 void filterWith(const TimeSeriesProperty<bool> *filter);
259 void clearFilter();
260 // Returns whether the time series has been filtered
261 bool isFiltered() const { return m_filterApplied; }
262
264 void countSize() const;
265
267 static bool isTimeString(const std::string &str);
268
270 std::string isValid() const override;
272 std::string getDefault() const override;
274 bool isDefault() const override;
275
278
281 void eliminateDuplicates();
282
284 std::string toString() const;
285
289 void reserve(size_t size) { m_values.reserve(size); };
290
292 std::vector<Mantid::Kernel::SplittingInterval> getSplittingIntervals() const;
293
294private:
295 //----------------------------------------------------------------------------------------------
297 void saveTimeVector(::NeXus::File *file);
299 void sortIfNecessary() const;
301 int findIndex(Types::Core::DateAndTime t) const;
303 int upperBound(Types::Core::DateAndTime t, int istart, int iend) const;
305 void applyFilter() const;
308 size_t findNthIndexFromQuickRef(int n) const;
310 std::string setValueFromProperty(const Property &right) override;
312 bool isTimeFiltered(const Types::Core::DateAndTime &time) const;
314 std::pair<double, double> timeAverageValueAndStdDev() const;
315
317 mutable std::vector<TimeValueUnit<TYPE>> m_values;
318
321 mutable int m_size;
322
325
327 mutable std::vector<std::pair<Types::Core::DateAndTime, bool>> m_filter;
329 mutable std::vector<std::pair<size_t, size_t>> m_filterQuickRef;
331 mutable bool m_filterApplied;
332};
333
336double DLLExport filterByStatistic(TimeSeriesProperty<double> const *const propertyToFilter,
337 Kernel::Math::StatisticType statisticType);
338
339} // namespace Kernel
340} // namespace Mantid
const std::vector< double > & rhs
double maxValue
double minValue
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
double right
Definition: LineProfile.cpp:81
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
A non-templated interface to a TimeSeriesProperty.
Base class for properties.
Definition: Property.h:94
Represents a time interval.
Definition: DateAndTime.h:25
A specialised Property class for holding a series of time-value pairs.
bool m_filterApplied
True if a filter has been applied.
TimeSeriesSortStatus m_propSortedFlag
Flag to state whether mP is sorted or not.
~TimeSeriesProperty() override
Virtual destructor.
int m_size
The number of values (or time intervals) in the time series.
std::vector< std::pair< size_t, size_t > > m_filterQuickRef
Quick reference regions for filter.
std::vector< TimeValueUnit< TYPE > > m_values
Holds the time series data.
void reserve(size_t size)
Reserve memory for efficient adding values to existing property makes sense only when you have reason...
std::vector< std::pair< Types::Core::DateAndTime, bool > > m_filter
The filter.
Class to hold unit value (DateAndTime, T)
bool operator>(const TimeValueUnit &rhs)
TimeValueUnit(const Types::Core::DateAndTime &time, const TYPE &value)
friend bool operator==(const TimeValueUnit &lhs, const TimeValueUnit &rhs)
Types::Core::DateAndTime mtime
friend bool operator<(const TimeValueUnit &lhs, const TimeValueUnit &rhs)
void setTime(Types::Core::DateAndTime newtime)
bool operator==(const TimeValueUnit &rhs)
Types::Core::DateAndTime time() const
friend bool operator>(const TimeValueUnit &lhs, const TimeValueUnit &rhs)
static bool valueCmp(const TimeValueUnit &lhs, const TimeValueUnit &rhs)
bool operator<(const TimeValueUnit &rhs)
MatrixWorkspace_sptr MANTID_API_DLL operator+=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
StatisticType
Maps a "statistic" to a number.
Definition: Statistics.h:18
Statistics getStatistics(const std::vector< TYPE > &data, const unsigned int flags=StatOptions::AllStats)
Return a statistics object for the given data set.
Definition: Statistics.cpp:167
double DLLExport filterByStatistic(TimeSeriesProperty< double > const *const propertyToFilter, Kernel::Math::StatisticType statisticType)
Function filtering double TimeSeriesProperties according to the requested statistics.
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
Struct holding some useful statistics for a TimeSeriesProperty.
double time_standard_deviation
time weighted standard deviation
double standard_deviation
standard_deviation of the values