Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor time series #1677

Merged
merged 43 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
032aa92
[DEV] Add classes TimeSeriesNumbers TimeSeries
payetvin Oct 4, 2023
ca77e5c
[DEV] Add classes to cpp
payetvin Oct 4, 2023
49782d9
[DEV] getTSNumber
payetvin Oct 4, 2023
e83b6bd
[DEV] getCoeff getColumn
payetvin Oct 4, 2023
d61970d
[FIX] Windows CI
payetvin Oct 5, 2023
ba47967
[DEV] Use matrix<> instead of vector
payetvin Oct 5, 2023
7031cea
[DEV] Add timeSeriesLoadFromFolder
payetvin Oct 5, 2023
c242069
[DEV]
payetvin Oct 5, 2023
1d20d99
[DEV] Wind compiling
payetvin Oct 5, 2023
18cf5fc
[DEV] remove old wind series files
payetvin Oct 5, 2023
cb3f385
[FIX] crash
payetvin Oct 5, 2023
78cd79f
[FIX] getSeriesIndex
payetvin Oct 5, 2023
4be03ca
[DEV] load series
payetvin Oct 6, 2023
8a76389
[DEV] remove load series files
payetvin Oct 6, 2023
3227753
[FIX] compile
payetvin Oct 6, 2023
1c79002
[DEV] Comments
payetvin Oct 6, 2023
a0fc02c
[DEV] revert reset()
payetvin Oct 6, 2023
fb1caae
[DEV] solar series
payetvin Oct 6, 2023
cc65e53
[DEV] remove solar series files
payetvin Oct 6, 2023
aeae022
[FIX] Tests crashes
payetvin Oct 9, 2023
83a04ea
[DEV] Add static member emptyColumn
payetvin Oct 9, 2023
1c91c83
[DEV] remove useless if
payetvin Oct 9, 2023
ab6deaf
Use generic class for load series (#1686)
payetvin Oct 9, 2023
4cafa88
Merge branch 'feature/series' of https://github.com/AntaresSimulatorT…
payetvin Oct 9, 2023
70a5cf9
Merge branch 'feature/series-solar' into feature/series
payetvin Oct 9, 2023
0fa4190
[DEV] Comments
payetvin Oct 9, 2023
01d0616
[DEV] using TScoefficients
payetvin Oct 9, 2023
77d2df4
Refactor thermal & renewable series (#1693)
payetvin Oct 16, 2023
9067974
[DEV] Comments and use series.reset()
payetvin Oct 16, 2023
356ef42
Refactor hydro series (#1705)
payetvin Oct 19, 2023
c052f8f
[MERGE] Develop + conflicts in management and utils
payetvin Oct 19, 2023
e10fadd
[FIX] Compile
payetvin Oct 20, 2023
2977a2d
[FIX] Code smells
payetvin Oct 20, 2023
a8be478
[FIX] Code smells
payetvin Oct 23, 2023
6acd647
[DEV] valueAtTimeStep uses year hour now
payetvin Oct 23, 2023
d645ab8
Unit tests for timeseries (#1713)
payetvin Oct 24, 2023
7dc7570
[DEV] Fix include path
payetvin Oct 25, 2023
3fc1ad0
Merge branch 'feature/series' of https://github.com/AntaresSimulatorT…
payetvin Oct 25, 2023
d28a611
[DEV] move folder series
payetvin Oct 26, 2023
b350143
[DEV] Use timestep instead of hour
payetvin Oct 26, 2023
170b603
[FIX] several comments for class series
payetvin Oct 26, 2023
c1ebd28
[FIX] more comments
payetvin Oct 26, 2023
d93a67b
[FIX] try fix windows CI
payetvin Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_subdirectory(stdcxx)
add_subdirectory(utils)
add_subdirectory(paths)
add_subdirectory(mersenne-twister)
add_subdirectory(series)

add_library(antares-core
antares.h
Expand Down
5 changes: 3 additions & 2 deletions src/libs/antares/checks/checkLoadedInputData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <antares/exception/LoadingError.hpp>
#include <antares/study/version.h>

#include <antares/series/series.h>
#include <antares/checks/checkLoadedInputData.h>
#include <antares/study/area/area.h>

Expand Down Expand Up @@ -161,7 +162,7 @@ void checkMinStablePower(bool tsGenThermal, const Antares::Data::AreaList& areas
// TS
template<class ExceptionT>
static void checkThermalColumnNumber(const Antares::Data::AreaList& areas,
Matrix<double> Antares::Data::EconomicInputData::*matrix)
Antares::Data::TimeSeries::TS Antares::Data::EconomicInputData::*matrix)
{
ExceptionT exception;
bool error = false;
Expand All @@ -174,7 +175,7 @@ static void checkThermalColumnNumber(const Antares::Data::AreaList& areas,
if (cluster.costgeneration == Antares::Data::setManually)
continue;
const uint otherMatrixWidth = (cluster.ecoInput.*matrix).width;
uint tsWidth = cluster.series->timeSeries.width;
uint tsWidth = cluster.series.timeSeries.width;
if (otherMatrixWidth != 1 && otherMatrixWidth != tsWidth)
{
logs.warning() << "Area: " << area.name << ". Cluster name: " << cluster.name()
Expand Down
15 changes: 15 additions & 0 deletions src/libs/antares/series/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_library(series)
add_library(Antares::series ALIAS series)

set(SRC_STUDY_PART_SERIES
include/antares/series/series.h
series.cpp
)
target_sources(series PUBLIC ${SRC_STUDY_PART_SERIES})

target_link_libraries(series PUBLIC Antares::array)

target_include_directories(series
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
96 changes: 96 additions & 0 deletions src/libs/antares/series/include/antares/series/series.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#ifndef __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__
#define __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__

#include <antares/array/matrix.h>

namespace Antares::Data
{

class TimeSeries
{
/*!
** \brief This class is used to represent the generic time series
**
** The goal is to handle indexing with the time series numbers: getCoefficient()
** and also providing a wrapper for all the Matrix<> functions such as resize()
*/

public:
using numbers = Matrix<uint32_t>;
using TS = Matrix<double>;

explicit TimeSeries(numbers& tsNumbers);
/*!
** \brief Load series from a file
**
** \param path path of the file
** \param dataBuffer yuni dependency to use loadFromCSV
** \param average used to average timeseries
** \return A non-zero value if the operation succeeded, 0 otherwise
*/
bool loadFromFile(const std::string& path,
Matrix<>::BufferType dataBuffer,
const bool average);
/*!
** \brief Save time series to a file
** \ingroup windseries
**
** \param areaID The ID of the area associated to the data series
** \param folder The target folder
** \param prefix the prefix for the filename
** \return A non-zero value if the operation succeeded, 0 otherwise
*/
int saveToFolder(const AreaName& areaID,
const std::string& folder,
const std::string& prefix) const;

double getCoefficient(uint32_t year, uint32_t timestep) const;
const double* getColumn(uint32_t year) const;
uint32_t getSeriesIndex(uint32_t year) const;

double* operator[](uint32_t index);

void reset();
void unloadFromMemory() const;
void roundAllEntries();
void resize(uint32_t timeSeriesCount, uint32_t timestepCount);
void averageTimeseries();

bool forceReload(bool reload = false) const;
void markAsModified() const;
uint64_t memoryUsage() const;

TS timeSeries;
numbers& timeseriesNumbers;

static const double emptyColumn[HOURS_PER_YEAR];
};

} // namespace Antares::Data
#endif /* __ANTARES_LIBS_STUDY_PARTS_COMMON_TIMESERIES_H__ */
140 changes: 140 additions & 0 deletions src/libs/antares/series/series.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
** Copyright 2007-2023 RTE
** Authors: Antares_Simulator Team
**
** This file is part of Antares_Simulator.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** There are special exceptions to the terms and conditions of the
** license as they are applied to this software. View the full text of
** the exceptions in file COPYING.txt in the directory of this software
** distribution
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/

#include <yuni/yuni.h>
#include <yuni/io/file.h>
#include <yuni/io/directory.h>
#include "antares/series/series.h"

using namespace Yuni;

#define SEP IO::Separator


namespace Antares::Data
{

const double TimeSeries::emptyColumn[] = {0};

TimeSeries::TimeSeries(numbers& tsNumbers) : timeseriesNumbers(tsNumbers)
{}

bool TimeSeries::loadFromFile(const std::string& path,
Matrix<>::BufferType dataBuffer,
const bool average)
{
bool ret = true;
ret = timeSeries.loadFromCSVFile(path, 1, HOURS_PER_YEAR, &dataBuffer) && ret;

if (average)
timeSeries.averageTimeseries();

timeseriesNumbers.clear();

return ret;
}

int TimeSeries::saveToFolder(const AreaName& areaID,
const std::string& folder,
const std::string& prefix) const
{
Clob buffer;
buffer.clear() << folder << SEP << prefix << areaID << ".txt";
return timeSeries.saveToCSVFile(buffer, 0);
}


double TimeSeries::getCoefficient(uint32_t year, uint32_t timestep) const
{
if (timeSeries.width == 0)
return 0;
return timeSeries[getSeriesIndex(year)][timestep];
}

const double* TimeSeries::getColumn(uint32_t year) const
{
if (timeSeries.width == 0)
return emptyColumn;
return timeSeries[getSeriesIndex(year)];
}

uint32_t TimeSeries::getSeriesIndex(uint32_t year) const
{
if (timeSeries.width == 1)
return 0;
else
return timeseriesNumbers[0][year];
}

double* TimeSeries::operator[](uint32_t index)
{
if (timeSeries.width <= index)
return nullptr;
return timeSeries[index];
}

void TimeSeries::reset()
{
timeSeries.reset(1, HOURS_PER_YEAR);
}

void TimeSeries::resize(uint32_t timeSeriesCount, uint32_t timestepCount)
{
timeSeries.resize(timeSeriesCount, timestepCount);
}

void TimeSeries::roundAllEntries()
{
timeSeries.roundAllEntries();
}

void TimeSeries::averageTimeseries()
{
timeSeries.averageTimeseries();
}

void TimeSeries::unloadFromMemory() const
{
timeSeries.unloadFromMemory();
}

bool TimeSeries::forceReload(bool reload) const
{
return timeSeries.forceReload(reload);
}

void TimeSeries::markAsModified() const
{
timeSeries.markAsModified();
}

uint64_t TimeSeries::memoryUsage() const
{
return timeSeries.memoryUsage();
}

} // namespace Antares::Data
13 changes: 1 addition & 12 deletions src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ source_group("study\\area\\ui" FILES ${SRC_STUDY_AREA_UI})


set(SRC_STUDY_PART_COMMON
parts/common/series.h
parts/common/series.cpp
parts/common/cluster.cpp
parts/common/cluster.h
parts/common/cluster_list.h
Expand Down Expand Up @@ -114,9 +112,6 @@ source_group("study\\part\\short-term-storage" FILES ${SRC_STUDY_PART_SHORT_TERM
set(SRC_STUDY_PART_WIND
parts/wind/container.h
parts/wind/container.cpp
parts/wind/series.h
parts/wind/series.hxx
parts/wind/series.cpp
parts/wind/prepro.h
parts/wind/prepro.hxx
parts/wind/prepro.cpp
Expand All @@ -127,7 +122,6 @@ set(SRC_STUDY_PART_HYDRO
parts/hydro/container.h
parts/hydro/container.cpp
parts/hydro/series.h
parts/hydro/series.hxx
parts/hydro/series.cpp
parts/hydro/prepro.h
parts/hydro/prepro.cpp
Expand Down Expand Up @@ -202,19 +196,13 @@ set(SRC_STUDY
# Load
parts/load/container.h
parts/load/container.cpp
parts/load/series.h
parts/load/series.hxx
parts/load/series.cpp
parts/load/prepro.cpp
parts/load/prepro.h
parts/load/prepro.hxx

# Solar
parts/solar/container.h
parts/solar/container.cpp
parts/solar/series.h
parts/solar/series.hxx
parts/solar/series.cpp
parts/solar/prepro.cpp
parts/solar/prepro.h
parts/solar/prepro.hxx
Expand Down Expand Up @@ -312,6 +300,7 @@ target_link_libraries(study
Antares::mersenne
Antares::result_writer #study.h
Antares::object
Antares::series
PRIVATE
Antares::exception
Antares::benchmarking
Expand Down
23 changes: 6 additions & 17 deletions src/libs/antares/study/area/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,8 @@ void Area::createMissingData()

void Area::createMissingTimeSeries()
{
if (!load.series)
load.series = new DataSeriesLoad();
if (!solar.series)
solar.series = new DataSeriesSolar();
if (!wind.series)
wind.series = new DataSeriesWind();
if (!hydro.series)
hydro.series = new DataSeriesHydro();
thermal.list.ensureDataTimeSeries();
renewable.list.ensureDataTimeSeries();
}
void Area::createMissingPrepros()
{
Expand Down Expand Up @@ -269,16 +261,13 @@ void Area::resizeAllTimeseriesNumbers(uint n)
assert(n < 200000); // arbitrary number

// asserts
assert(load.series and "load.series must not be nullptr !");
assert(solar.series and "solar.series must not be nullptr !");
assert(wind.series and "wind.series must not be nullptr !");
assert(hydro.series and "series must not be nullptr !");

if (!n)
{
load.series->timeseriesNumbers.clear();
solar.series->timeseriesNumbers.clear();
wind.series->timeseriesNumbers.clear();
load.series.timeseriesNumbers.clear();
solar.series.timeseriesNumbers.clear();
wind.series.timeseriesNumbers.clear();
hydro.series->timeseriesNumbers.clear();
for (auto& namedLink : links)
{
Expand All @@ -288,9 +277,9 @@ void Area::resizeAllTimeseriesNumbers(uint n)
}
else
{
load.series->timeseriesNumbers.resize(1, n);
solar.series->timeseriesNumbers.resize(1, n);
wind.series->timeseriesNumbers.resize(1, n);
load.series.timeseriesNumbers.resize(1, n);
solar.series.timeseriesNumbers.resize(1, n);
wind.series.timeseriesNumbers.resize(1, n);
hydro.series->timeseriesNumbers.resize(1, n);
for (auto& namedLink : links)
{
Expand Down
Loading