Skip to content

Commit

Permalink
fix: max power from shore values and units (#492)
Browse files Browse the repository at this point in the history
* fix: wrong unit max power from shore (#491)

ECALC-1190

(cherry picked from commit f881335)

* fix: max power from shore values (#490)

ECALC-1189

(cherry picked from commit 1c7a4a1)
  • Loading branch information
frodehk authored May 22, 2024
1 parent 29998df commit 887a698
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DATE,MAX_USAGE_FROM_SHORE
01.01.2021,283
01.01.2022,283
01.01.2023,283
01.01.2024,283
01.01.2025,283
01.01.2026,283
01.12.2026,250
01.06.2027,290
01.01.2028,283
01.01.2029,283
01.01.2030,283
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def _ltp_pfs_yaml_factory(
- NAME: CABLE_LOSS
TYPE: DEFAULT
FILE: data/sim/cable_loss.csv
- NAME: MAX_USAGE_FROM_SHORE
TYPE: DEFAULT
FILE: data/sim/max_usage_from_shore.csv
FACILITY_INPUTS:
- NAME: generator_energy_function
FILE: 'data/einput/genset_17MW.csv'
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/presentation/exporter/configs/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def aggregator(frequency: Frequency) -> Aggregator:
Applier(
name="fromShorePeakMaximum",
title="Max Usage from Shore",
unit=Unit.GIGA_WATT_HOURS,
unit=Unit.MEGA_WATT,
query=MaxUsageFromShoreQuery(
producer_categories=["POWER-FROM-SHORE"],
),
Expand Down
12 changes: 6 additions & 6 deletions src/libecalc/presentation/exporter/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def query(

aggregated_result: DefaultDict[datetime, float] = defaultdict(float)
aggregated_result_volume = {}
unit_in = None

if self.installation_category is None or installation_dto.user_defined_category == self.installation_category:
for fuel_consumer in installation_dto.fuel_consumers:
Expand All @@ -532,16 +531,14 @@ def query(
fill_length=len(installation_graph.variables_map.time_vector),
)
),
unit=Unit.MEGA_WATT,
unit=unit,
timesteps=installation_graph.variables_map.time_vector,
)

results = TimeSeriesRate.from_timeseries_stream_day_rate(
max_usage_from_shore, regularity=regularity
).for_period(period)

unit_in = results.unit

for timestep, result in results.datapoints():
aggregated_result[timestep] += result

Expand All @@ -550,11 +547,14 @@ def query(
sorted_result = {**dict.fromkeys(installation_time_steps, 0.0), **sorted_result}
date_keys = list(sorted_result.keys())

# Max usage from shore is time series float (values), and contains one more item
# than time steps for volumes. Number of values for max usage from shore should
# be the same as number of volume-time steps, hence [:-1]
reindexed_result = (
TimeSeriesVolumes(timesteps=date_keys, values=list(sorted_result.values())[:-1], unit=unit_in)
TimeSeriesFloat(timesteps=date_keys, values=list(sorted_result.values()), unit=unit)
.reindex(time_steps)
.fill_nan(0)
)
)[:-1]

aggregated_result_volume = {
reindexed_result.timesteps[i]: reindexed_result.values[i] for i in range(len(reindexed_result))
Expand Down
39 changes: 39 additions & 0 deletions src/tests/libecalc/output/results/test_ltp.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,42 @@ def test_power_from_shore(ltp_pfs_yaml_factory):

# Check that reading cable loss from csv-file gives same result as using constant
assert power_supply_onshore == power_supply_onshore_csv

# Verify correct unit for max usage from shore
assert ltp_result.query_results[0].query_results[3].unit == Unit.MEGA_WATT


def test_max_usage_from_shore(ltp_pfs_yaml_factory):
"""Test power from shore output for LTP export."""

time_vector_yearly = pd.date_range(datetime(2025, 1, 1), datetime(2030, 1, 1), freq="YS").to_pydatetime().tolist()

dto.VariablesMap(time_vector=time_vector_yearly, variables={})
regularity = 0.2
load = 10
cable_loss = 0.1

dto_case_csv = ltp_pfs_yaml_factory(
regularity=regularity,
cable_loss=cable_loss,
max_usage_from_shore="MAX_USAGE_FROM_SHORE;MAX_USAGE_FROM_SHORE",
load_direct_consumer=load,
path=Path(ltp_export.__path__[0]),
)

ltp_result_csv = get_consumption(
model=dto_case_csv.ecalc_model, variables=dto_case_csv.variables, time_vector=time_vector_yearly
)

max_usage_from_shore_2027 = float(ltp_result_csv.query_results[0].query_results[3].values[datetime(2027, 1, 1)])

# In the input csv-file max usage from shore is 250 (1.12.2026), 290 (1.6.2027), 283 (1.1.2028)
# and 283 (1.1.2029). Ensure that the correct value is set for January 2027:
assert max_usage_from_shore_2027 == 250.0

# Ensure that values in 2027, 2028 and 2029 are correct, based on input file:
assert [float(max_pfs) for max_pfs in ltp_result_csv.query_results[0].query_results[3].values.values()][2:5] == [
250,
283,
283,
]

0 comments on commit 887a698

Please sign in to comment.