Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Mar 6, 2025
1 parent 7fd36ee commit 4359b4b
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,52 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
import pytest

import re

import numpy as np
import pandas as pd

from antares.craft.model.thermal import ThermalClusterPropertiesUpdate


class TestThermalTsGeneration:
def set_up_matrices(self, local_study_w_thermals):
prepro_data_matrix = np.zeros((365, 6))
prepro_data_matrix[:, :2] = 1

prepro_modulation_matrix = np.ones((8760, 4))
prepro_modulation_matrix[:, 3] = 0

cluster_1 = local_study_w_thermals.get_areas()["fr"].get_thermals()["test thermal cluster"]
cluster_2 = local_study_w_thermals.get_areas()["fr"].get_thermals()["thermal_fr_2"]
cluster_3 = local_study_w_thermals.get_areas()["it"].get_thermals()["thermal_it"]
for cluster in [cluster_1, cluster_2, cluster_3]:
cluster.update_prepro_data_matrix(pd.DataFrame(prepro_data_matrix))
cluster.update_prepro_modulation_matrix(pd.DataFrame(prepro_modulation_matrix))

def test_nominal_case(self, local_study_w_thermals):
pass
self.set_up_matrices(local_study_w_thermals)
# Change nominal capacity
cluster_1 = local_study_w_thermals.get_areas()["fr"].get_thermals()["test thermal cluster"]
cluster_2 = local_study_w_thermals.get_areas()["fr"].get_thermals()["thermal_fr_2"]
cluster_3 = local_study_w_thermals.get_areas()["it"].get_thermals()["thermal_it"]
for k, cluster in enumerate([cluster_1, cluster_2, cluster_3]):
new_properties = ThermalClusterPropertiesUpdate(nominal_capacity=100 * (k + 1))
cluster.update_properties(new_properties)
# Generate new TS
local_study_w_thermals.generate_thermal_timeseries(4)
# Checks TS generated
for k, cluster in enumerate([cluster_1, cluster_2, cluster_3]):
series = cluster.get_series_matrix()
expected_series = pd.DataFrame(np.full((8760, 4), (k + 1) * 100))
assert series.equals(expected_series)

def test_error_case(self, local_study_w_thermals):
local_study_w_thermals.generate_thermal_timeseries(4)
self.set_up_matrices(local_study_w_thermals)
with pytest.raises(
ValueError,
match=re.escape("Area fr, cluster test thermal cluster: Nominal power must be strictly positive, got 0."),
):
local_study_w_thermals.generate_thermal_timeseries(4)

0 comments on commit 4359b4b

Please sign in to comment.