diff --git a/src/libecalc/fixtures/cases/ltp_export/utilities.py b/src/libecalc/fixtures/cases/ltp_export/utilities.py index 52a8c08b00..ca1d3a1931 100644 --- a/src/libecalc/fixtures/cases/ltp_export/utilities.py +++ b/src/libecalc/fixtures/cases/ltp_export/utilities.py @@ -7,9 +7,12 @@ from libecalc.common.variables import VariablesMap from libecalc.dto import Asset, Installation from libecalc.presentation.exporter.configs.configs import LTPConfig +from libecalc.presentation.exporter.dto.dtos import FilteredResult -def get_consumption(model: Union[Installation, Asset], variables: VariablesMap, time_vector: List[datetime]): +def get_consumption( + model: Union[Installation, Asset], variables: VariablesMap, time_vector: List[datetime] +) -> FilteredResult: model = model graph = model.get_graph() energy_calculator = EnergyCalculator(graph=graph) @@ -30,8 +33,9 @@ def get_consumption(model: Union[Installation, Asset], variables: VariablesMap, return ltp_result -def get_sum_ltp_column(ltp_result, installation_nr, ltp_column_nr) -> float: - ltp_sum = sum( - float(v) for (k, v) in ltp_result.query_results[installation_nr].query_results[ltp_column_nr].values.items() - ) +def get_sum_ltp_column(ltp_result: FilteredResult, installation_nr, ltp_column: str) -> float: + installation_query_results = ltp_result.query_results[installation_nr].query_results + column = [column for column in installation_query_results if column.id == ltp_column][0] + + ltp_sum = sum(float(v) for (k, v) in column.values.items()) return ltp_sum diff --git a/src/tests/libecalc/presentation/exporter/test_ltp.py b/src/tests/libecalc/presentation/exporter/test_ltp.py index 5106454dfa..c3942fd2b2 100644 --- a/src/tests/libecalc/presentation/exporter/test_ltp.py +++ b/src/tests/libecalc/presentation/exporter/test_ltp.py @@ -107,17 +107,19 @@ def test_emissions_diesel_fixed_and_mobile(): ltp_result = get_consumption(model=asset, variables=variables, time_vector=time_vector_yearly) - co2_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=1) - co2_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column_nr=1) + co2_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselCo2Mass") + co2_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column="engineNoCo2TaxDieselCo2Mass") - nox_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=2) - nox_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column_nr=2) + nox_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselNoxMass") + nox_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column="engineNoCo2TaxDieselNoxMass") - nmvoc_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=3) - nmvoc_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column_nr=3) + nmvoc_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselNmvocMass") + nmvoc_from_diesel_mobile = get_sum_ltp_column( + ltp_result, installation_nr=1, ltp_column="engineNoCo2TaxDieselNmvocMass" + ) - ch4_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=4) - ch4_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column_nr=4) + ch4_from_diesel_fixed = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselCh4Mass") + ch4_from_diesel_mobile = get_sum_ltp_column(ltp_result, installation_nr=1, ltp_column="engineNoCo2TaxDieselCh4Mass") assert co2_from_diesel_fixed == expected_co2_from_diesel() assert co2_from_diesel_mobile == expected_co2_from_diesel() @@ -143,14 +145,16 @@ def test_temporal_models_detailed(): model=installation_direct_consumer_dto(), variables=variables, time_vector=time_vector_yearly ) - turbine_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=0) - engine_diesel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=1) + turbine_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="turbineFuelGasConsumption") + engine_diesel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselConsumption") - gas_turbine_el_generated = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=4) - pfs_el_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=5) + gas_turbine_el_generated = get_sum_ltp_column( + ltp_result, installation_nr=0, ltp_column="gasTurbineGeneratorConsumption" + ) + pfs_el_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="fromShoreConsumption") - co2_from_fuel = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=2) - co2_from_diesel = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=3) + co2_from_fuel = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="turbineFuelGasCo2Mass") + co2_from_diesel = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="engineDieselCo2Mass") # FuelQuery: Check that turbine fuel consumption is included, # even if the temporal model starts with diesel every year @@ -192,7 +196,9 @@ def test_temporal_models_offshore_wind(): model=installation_offshore_wind_dto(), variables=variables, time_vector=time_vector_yearly ) - offshore_wind_el_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=3) + offshore_wind_el_consumption = get_sum_ltp_column( + ltp_result, installation_nr=0, ltp_column="offshoreWindConsumption" + ) # ElConsumerPowerConsumptionQuery: Check that offshore wind el-consumption is correct. assert offshore_wind_el_consumption == expected_offshore_wind_el_consumption() @@ -210,7 +216,9 @@ def test_temporal_models_compressor(): model=installation_compressor_dto([no_el_consumption()]), variables=variables, time_vector=time_vector_yearly ) - gas_turbine_compressor_el_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=3) + gas_turbine_compressor_el_consumption = get_sum_ltp_column( + ltp_result, installation_nr=0, ltp_column="gasTurbineCompressorConsumption" + ) # FuelConsumerPowerConsumptionQuery. Check gas turbine compressor el consumption. assert gas_turbine_compressor_el_consumption == expected_gas_turbine_compressor_el_consumption() @@ -223,10 +231,10 @@ def test_boiler_heater_categories(): model=installation_boiler_heater_dto(), variables=variables, time_vector=time_vector_yearly ) - boiler_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=0) - heater_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=1) - co2_from_boiler = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=2) - co2_from_heater = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=3) + boiler_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="boilerFuelGasConsumption") + heater_fuel_consumption = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="heaterFuelGasConsumption") + co2_from_boiler = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="boilerFuelGasCo2Mass") + co2_from_heater = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="heaterFuelGasCo2Mass") # FuelConsumerPowerConsumptionQuery. Check gas turbine compressor el consumption. assert boiler_fuel_consumption == expected_boiler_fuel_consumption() @@ -292,13 +300,13 @@ def test_venting_emitters(): ) emission_input_sd_kg_per_day = get_sum_ltp_column( - ltp_result_input_sd_kg_per_day, installation_nr=0, ltp_column_nr=0 + ltp_result_input_sd_kg_per_day, installation_nr=0, ltp_column="storageCh4Mass" ) emission_input_sd_tons_per_day = get_sum_ltp_column( - ltp_result_input_sd_tons_per_day, installation_nr=0, ltp_column_nr=0 + ltp_result_input_sd_tons_per_day, installation_nr=0, ltp_column="storageCh4Mass" ) emission_input_cd_kg_per_day = get_sum_ltp_column( - ltp_result_input_cd_kg_per_day, installation_nr=0, ltp_column_nr=0 + ltp_result_input_cd_kg_per_day, installation_nr=0, ltp_column="storageCh4Mass" ) # Verify correct emissions when input is kg per day. Output should be in tons per day - hence dividing by 1000 @@ -352,7 +360,7 @@ def test_only_venting_emitters_no_fuelconsumers(): ) # Verify correct emissions: - emissions_ch4 = get_sum_ltp_column(venting_emitter_results, installation_nr=0, ltp_column_nr=0) + emissions_ch4 = get_sum_ltp_column(venting_emitter_results, installation_nr=0, ltp_column="storageCh4Mass") assert emissions_ch4 == (emission_rate / 1000) * 365 * regularity # Installation with only fuel consumers: @@ -387,7 +395,7 @@ def test_only_venting_emitters_no_fuelconsumers(): # Check that the results are the same: For the case with only one installation (only venting emitters), # compared to the multi-installation case with two installations. The fuel-consumer installation should # give no CH4-contribution (only CO2) - emissions_ch4_asset = get_sum_ltp_column(asset_ltp_result, installation_nr=0, ltp_column_nr=0) + emissions_ch4_asset = get_sum_ltp_column(asset_ltp_result, installation_nr=0, ltp_column="storageCh4Mass") assert emissions_ch4 == emissions_ch4_asset @@ -464,9 +472,11 @@ def test_total_oil_loaded_old_method(): ) loaded_and_stored_oil_loading_and_storage = get_sum_ltp_column( - ltp_result_loading_storage, installation_nr=0, ltp_column_nr=2 + ltp_result_loading_storage, installation_nr=0, ltp_column="loadedAndStoredOil" + ) + loaded_and_stored_oil_loading_only = get_sum_ltp_column( + ltp_result_loading_only, installation_nr=0, ltp_column="loadedAndStoredOil" ) - loaded_and_stored_oil_loading_only = get_sum_ltp_column(ltp_result_loading_only, installation_nr=0, ltp_column_nr=1) # Verify output for total oil loaded/stored, if only loading is specified. assert loaded_and_stored_oil_loading_only is not None @@ -600,11 +610,17 @@ def test_power_from_shore(ltp_pfs_yaml_factory): model=dto_case_csv.ecalc_model, variables=dto_case.variables, time_vector=time_vector_yearly ) - power_from_shore_consumption = get_sum_ltp_column(ltp_result=ltp_result, installation_nr=0, ltp_column_nr=1) - power_supply_onshore = get_sum_ltp_column(ltp_result=ltp_result, installation_nr=0, ltp_column_nr=2) - max_usage_from_shore = get_sum_ltp_column(ltp_result=ltp_result, installation_nr=0, ltp_column_nr=3) + power_from_shore_consumption = get_sum_ltp_column( + ltp_result=ltp_result, installation_nr=0, ltp_column="fromShoreConsumption" + ) + power_supply_onshore = get_sum_ltp_column(ltp_result=ltp_result, installation_nr=0, ltp_column="powerSupplyOnshore") + max_usage_from_shore = get_sum_ltp_column( + ltp_result=ltp_result, installation_nr=0, ltp_column="fromShorePeakMaximum" + ) - power_supply_onshore_csv = get_sum_ltp_column(ltp_result=ltp_result_csv, installation_nr=0, ltp_column_nr=2) + power_supply_onshore_csv = get_sum_ltp_column( + ltp_result=ltp_result_csv, installation_nr=0, ltp_column="powerSupplyOnshore" + ) # In the temporal model, the category is POWER_FROM_SHORE the last three years, within the period 2025 - 2030: delta_days = calculate_delta_days(time_vector_yearly)[2:5] diff --git a/src/tests/libecalc/presentation/yaml/test_venting_emitter.py b/src/tests/libecalc/presentation/yaml/test_venting_emitter.py index d654691429..2801c784fa 100644 --- a/src/tests/libecalc/presentation/yaml/test_venting_emitter.py +++ b/src/tests/libecalc/presentation/yaml/test_venting_emitter.py @@ -202,8 +202,8 @@ def test_venting_emitters_direct_multiple_emissions_ltp(): model=dto_case.ecalc_model, variables=dto_case.variables, time_vector=dto_case.variables.time_vector ) - ch4_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=0) - co2_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=1) + ch4_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="co2VentingMass") + co2_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="coldVentAndFugitivesCh4Mass") assert ch4_emissions == sum(emission_rates[0] * days * regularity / 1000 for days in delta_days) assert co2_emissions == sum(emission_rates[1] * days * regularity / 1000 for days in delta_days) @@ -262,11 +262,13 @@ def test_venting_emitters_volume_multiple_emissions_ltp(): time_vector=dto_case_stream_day.variables.time_vector, ) - ch4_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=0) - nmvoc_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=1) - oil_volume = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column_nr=2) + ch4_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="loadingNmvocMass") + nmvoc_emissions = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="loadingCh4Mass") + oil_volume = get_sum_ltp_column(ltp_result, installation_nr=0, ltp_column="loadedAndStoredOil") - oil_volume_stream_day = get_sum_ltp_column(ltp_result_stream_day, installation_nr=0, ltp_column_nr=2) + oil_volume_stream_day = get_sum_ltp_column( + ltp_result_stream_day, installation_nr=0, ltp_column="loadedAndStoredOil" + ) assert ch4_emissions == sum(oil_rates[0] * days * emission_factors[0] / 1000 for days in delta_days) assert nmvoc_emissions == sum(oil_rates[0] * days * emission_factors[1] / 1000 for days in delta_days)