From 328ce1287cd5fab524357ac98b8429b2e20d4656 Mon Sep 17 00:00:00 2001 From: Jostein Solaas Date: Tue, 24 Sep 2024 19:13:09 +0200 Subject: [PATCH] refactor!: use yaml objects in mapper BREAKING CHANGE: H2O no longer supported in fluid composition, use 'water' --- .../ltp_export/loading_storage_ltp_yaml.py | 65 ------------------- .../legacy/energy_usage_model/common.py | 2 +- .../presentation/exporter/test_ltp.py | 65 ------------------- 3 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 src/libecalc/fixtures/cases/ltp_export/loading_storage_ltp_yaml.py diff --git a/src/libecalc/fixtures/cases/ltp_export/loading_storage_ltp_yaml.py b/src/libecalc/fixtures/cases/ltp_export/loading_storage_ltp_yaml.py deleted file mode 100644 index f074e58ca4..0000000000 --- a/src/libecalc/fixtures/cases/ltp_export/loading_storage_ltp_yaml.py +++ /dev/null @@ -1,65 +0,0 @@ -from typing import List - -import yaml - -from libecalc.common.utils.rates import RateType -from libecalc.dto import Asset -from libecalc.presentation.yaml.parse_input import map_yaml_to_dto -from libecalc.presentation.yaml.yaml_models.pyyaml_yaml_model import PyYamlYamlModel - - -def ltp_oil_loaded_yaml_factory( - emission_factor: float, - rate_types: List[RateType], - fuel_rates: List[float], - emission_name: str, - regularity: float, - categories: List[str], - consumer_names: List[str], -) -> Asset: - input_text = f""" - FUEL_TYPES: - - NAME: fuel - EMISSIONS: - - NAME: {emission_name} - FACTOR: {emission_factor} - - INSTALLATIONS: - - NAME: minimal_installation - HCEXPORT: 0 - FUEL: fuel - CATEGORY: FIXED - REGULARITY: {regularity} - - FUELCONSUMERS: - {create_direct_consumers_yaml(categories, fuel_rates, rate_types, consumer_names)} - - """ - - create_direct_consumers_yaml(categories, fuel_rates, rate_types, consumer_names) - yaml_text = yaml.safe_load(input_text) - configuration = PyYamlYamlModel( - internal_datamodel=yaml_text, - name="test", - instantiated_through_read=True, - ) - yaml_model = map_yaml_to_dto(configuration=configuration, resources={}) - return yaml_model - - -def create_direct_consumers_yaml( - categories: List[str], fuel_rates: List[float], rate_types: List[RateType], consumer_names: List[str] -) -> str: - consumers = "" - for category, fuel_rate, rate_type, consumer_name in zip(categories, fuel_rates, rate_types, consumer_names): - consumer = f""" - - NAME: {consumer_name} - CATEGORY: {category} - FUEL: fuel - ENERGY_USAGE_MODEL: - TYPE: DIRECT - FUELRATE: {fuel_rate} - CONSUMPTION_RATE_TYPE: {rate_type.value} - """ - consumers = consumers + consumer - return consumers diff --git a/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/common.py b/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/common.py index 1f0bab40b4..b082a09ff0 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/common.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/common.py @@ -18,7 +18,7 @@ class EnergyUsageModelCommon(YamlBase): None, title="CONDITIONS", description="Logical conditions for the consumer to be used.\n\n$ECALC_DOCS_KEYWORDS_URL/CONDITION", - ) + ) # TODO: Validate either or between conditions and condition power_loss_factor: YamlExpressionType = Field( None, title="POWERLOSSFACTOR", diff --git a/src/tests/libecalc/presentation/exporter/test_ltp.py b/src/tests/libecalc/presentation/exporter/test_ltp.py index 5106454dfa..41c6d77939 100644 --- a/src/tests/libecalc/presentation/exporter/test_ltp.py +++ b/src/tests/libecalc/presentation/exporter/test_ltp.py @@ -38,9 +38,6 @@ no_el_consumption, simple_direct_el_consumer, ) -from libecalc.fixtures.cases.ltp_export.loading_storage_ltp_yaml import ( - ltp_oil_loaded_yaml_factory, -) from libecalc.fixtures.cases.ltp_export.utilities import ( get_consumption, get_sum_ltp_column, @@ -417,68 +414,6 @@ def test_no_emitters_or_fuelconsumers(): assert f"It is required to specify at least one of the keywords {EcalcYamlKeywords.fuel_consumers}, {EcalcYamlKeywords.generator_sets} or {EcalcYamlKeywords.installation_venting_emitters} in the model." -def test_total_oil_loaded_old_method(): - """Test total oil loaded/stored for LTP export. Using original method where direct/venting emitters are - modelled as FUELSCONSUMERS using DIRECT. - - Verify correct volume when model includes emissions related to both storage and loading of oil, - and when model includes only loading. - """ - time_vector = [ - datetime(2027, 1, 1), - datetime(2028, 1, 1), - ] - variables = VariablesMap(time_vector=time_vector, variables={}) - - regularity = 0.6 - emission_factor = 2 - fuel_rate = 100 - - # Create model with both loading and storage - asset_loading_storage = ltp_oil_loaded_yaml_factory( - emission_factor=emission_factor, - rate_types=[RateType.STREAM_DAY, RateType.STREAM_DAY], - fuel_rates=[fuel_rate, fuel_rate], - emission_name="ch4", - regularity=regularity, - categories=["LOADING", "STORAGE"], - consumer_names=["loading", "storage"], - ) - - # Create model with only loading, not storage - asset_loading_only = ltp_oil_loaded_yaml_factory( - emission_factor=emission_factor, - rate_types=[RateType.STREAM_DAY], - fuel_rates=[fuel_rate], - emission_name="ch4", - regularity=regularity, - categories=["LOADING"], - consumer_names=["loading"], - ) - - ltp_result_loading_storage = get_consumption( - model=asset_loading_storage, variables=variables, time_vector=time_vector_yearly - ) - ltp_result_loading_only = get_consumption( - model=asset_loading_only, variables=variables, time_vector=time_vector_yearly - ) - - loaded_and_stored_oil_loading_and_storage = get_sum_ltp_column( - ltp_result_loading_storage, installation_nr=0, ltp_column_nr=2 - ) - 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 - - # Verify correct volume for oil loaded/stored - assert loaded_and_stored_oil_loading_and_storage == fuel_rate * 365 * regularity - - # Verify that total oil loaded/stored is the same if only loading is specified, - # compared to a model with both loading and storage. - assert loaded_and_stored_oil_loading_and_storage == loaded_and_stored_oil_loading_only - - def test_electrical_and_mechanical_power_installation(): """Check that new total power includes the sum of electrical- and mechanical power at installation level""" variables = VariablesMap(time_vector=time_vector_installation, variables={})