Antares Simulator
Power System Simulator
series.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__
22 #define __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__
23 
24 #include <map>
25 #include <optional>
26 #include <string>
27 
28 #include <antares/array/matrix.h>
29 
30 namespace Antares::Data
31 {
39 class TimeSeries;
40 
41 class TimeSeriesNumbers final
42 {
43 public:
44  void registerSeries(const TimeSeries* s, std::string label);
45  // Return a description of the error in case of inconsistent number of columns, std::nullopt
46  // otherwis
47  std::optional<std::string> checkSeriesNumberOfColumnsConsistency() const;
48 
49  uint32_t operator[](uint y) const;
50  uint32_t& operator[](uint y);
51 
52  void clear();
53  void reset(uint h);
54 
55  uint height() const;
56 
57  void saveToBuffer(std::string& data) const;
58 
59 private:
60  Matrix<uint32_t> tsNumbers;
61  std::map<std::string, const TimeSeries*> series;
62 };
63 
64 class TimeSeries final
65 {
66 public:
67  using TS = Matrix<double>;
68 
69  explicit TimeSeries(TimeSeriesNumbers& tsNumbers);
77  bool loadFromFile(const std::filesystem::path& path,
78  const bool average,
79  unsigned options = Matrix<>::optNone);
88  int saveToFolder(const std::string& areaID,
89  const std::string& folder,
90  const std::string& prefix) const;
91 
92  int saveToFile(const std::string& filename, bool saveEvenIfAllZero) const;
93 
94  double getCoefficient(uint32_t year, uint32_t timestep) const;
95  const double* getColumn(uint32_t year) const;
96  uint32_t getSeriesIndex(uint32_t year) const;
97 
100  double* operator[](uint32_t index);
101 
102  void reset();
103  void reset(uint32_t width, uint32_t height);
104  uint32_t numberOfColumns() const;
105  void unloadFromMemory() const;
106  void roundAllEntries();
107  void resize(uint32_t timeSeriesCount, uint32_t timestepCount);
108  void fill(double value);
109  void averageTimeseries();
110 
111  bool forceReload(bool reload = false) const;
112  void markAsModified() const;
113 
114  TS timeSeries;
115  TimeSeriesNumbers& timeseriesNumbers;
116 
117  static const std::vector<double> emptyColumn;
118 };
119 
120 } // namespace Antares::Data
121 #endif /* __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__ */
Definition: series.h:42
This class is used to represent the generic time series.
Definition: series.h:65
static const std::vector< double > emptyColumn
used in getColumn if timeSeries empty
Definition: series.h:117
bool loadFromFile(const std::filesystem::path &path, const bool average, unsigned options=Matrix<>::optNone)
Load series from a file.
Definition: series.cpp:107
double * operator[](uint32_t index)
overload operator to return a column Unlike getColumn() it uses direct indexing and not timeseriesNum...
Definition: series.cpp:158
int saveToFolder(const std::string &areaID, const std::string &folder, const std::string &prefix) const
Save time series to a file.
Definition: series.cpp:123