diff --git a/src/libecalc/fixtures/cases/ltp_export/data/sim/max_usage_from_shore.csv b/src/libecalc/fixtures/cases/ltp_export/data/sim/max_usage_from_shore.csv new file mode 100644 index 0000000000..d58b130e4d --- /dev/null +++ b/src/libecalc/fixtures/cases/ltp_export/data/sim/max_usage_from_shore.csv @@ -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 diff --git a/src/libecalc/fixtures/cases/ltp_export/ltp_power_from_shore_yaml.py b/src/libecalc/fixtures/cases/ltp_export/ltp_power_from_shore_yaml.py index bc71db7fb0..ad9eca6bde 100644 --- a/src/libecalc/fixtures/cases/ltp_export/ltp_power_from_shore_yaml.py +++ b/src/libecalc/fixtures/cases/ltp_export/ltp_power_from_shore_yaml.py @@ -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' diff --git a/src/libecalc/presentation/exporter/configs/configs.py b/src/libecalc/presentation/exporter/configs/configs.py index 5f5abb3b6d..0c69189ada 100644 --- a/src/libecalc/presentation/exporter/configs/configs.py +++ b/src/libecalc/presentation/exporter/configs/configs.py @@ -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"], ), diff --git a/src/libecalc/presentation/exporter/queries.py b/src/libecalc/presentation/exporter/queries.py index 8515519210..06420b16ac 100644 --- a/src/libecalc/presentation/exporter/queries.py +++ b/src/libecalc/presentation/exporter/queries.py @@ -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: @@ -532,7 +531,7 @@ def query( fill_length=len(installation_graph.variables_map.time_vector), ) ), - unit=Unit.MEGA_WATT, + unit=unit, timesteps=installation_graph.variables_map.time_vector, ) @@ -540,8 +539,6 @@ def query( max_usage_from_shore, regularity=regularity ).for_period(period) - unit_in = results.unit - for timestep, result in results.datapoints(): aggregated_result[timestep] += result @@ -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)) diff --git a/src/tests/libecalc/output/results/test_ltp.py b/src/tests/libecalc/output/results/test_ltp.py index 8dccbd4d3f..b71c7787b8 100644 --- a/src/tests/libecalc/output/results/test_ltp.py +++ b/src/tests/libecalc/output/results/test_ltp.py @@ -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, + ]