From 6880e12c5e993637b2a985f8f04eb41301f917b7 Mon Sep 17 00:00:00 2001 From: Jostein Solaas Date: Mon, 26 Aug 2024 10:11:51 +0200 Subject: [PATCH] chore: run ruff-format all files --- examples/simple_python_model.ipynb | 354 +++++++++--------- examples/simple_yaml_model.ipynb | 63 ++-- src/libecalc/common/errors/exceptions.py | 3 +- src/libecalc/common/graph.py | 3 +- src/libecalc/common/utils/rates.py | 5 +- src/libecalc/core/consumers/base/component.py | 11 +- src/libecalc/core/consumers/factory.py | 3 +- .../consumer_function/results.py | 3 +- .../system/consumer_function.py | 6 +- .../system/operational_setting.py | 6 +- .../legacy_consumer/system/results.py | 6 +- src/libecalc/core/models/base.py | 3 +- .../sampled/compressor_model_sampled_1d.py | 4 +- .../compressor/train/simplified_train.py | 4 +- .../core/models/results/compressor.py | 12 +- src/libecalc/core/models/results/generic.py | 3 +- src/libecalc/core/result/results.py | 3 +- src/libecalc/core/utils/array_type.py | 1 + src/libecalc/domain/stream_conditions.py | 1 + src/libecalc/domain/tabular/tabular.py | 15 +- src/libecalc/dto/base.py | 3 +- .../core_specs/base/operational_settings.py | 3 +- src/libecalc/dto/models/compressor/train.py | 20 +- src/libecalc/dto/utils/validators.py | 4 +- .../exporter/formatters/formatter.py | 9 +- .../presentation/json_result/mapper.py | 2 +- .../json_result/result/results.py | 3 +- .../presentation/yaml/mappers/model.py | 5 +- .../yaml/yaml_models/yaml_model.py | 9 +- ...gle_speed_compressor_train_common_shaft.py | 4 +- ...speed_compressor_train_multiple_streams.py | 8 +- 31 files changed, 278 insertions(+), 301 deletions(-) diff --git a/examples/simple_python_model.ipynb b/examples/simple_python_model.ipynb index 94059f27ed..bc7d248996 100644 --- a/examples/simple_python_model.ipynb +++ b/examples/simple_python_model.ipynb @@ -2,6 +2,9 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# Simple Model Example\n", "\n", @@ -31,13 +34,13 @@ "- compressor_sampled_with_turbine.csv\n", "- pump_sampled.csv\n", "- pump_chart.csv" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "### Python Model\n", "We will now recreate the exact same model, but this time using the libecalc Python library\n", @@ -52,14 +55,18 @@ "- produced_water_reinjection_condition\n", "- produced_water_reinjection_total_system_rate_m3_per_day\n", "- flare_fuel_rate_sm3_day\n" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:23.596846Z", + "start_time": "2023-04-26T14:25:23.572924Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "from libecalc.dto.types import ConsumptionType, EnergyUsageType, ConsumerType, EnergyModelType\n", @@ -87,20 +94,23 @@ " FuelConsumer,\n", " Emission,\n", " FuelType,\n", - " VariablesMap\n", + " VariablesMap,\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:23.572924Z", - "end_time": "2023-04-26T14:25:23.596846Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T13:28:02.948424Z", + "start_time": "2023-04-26T13:28:02.924970Z" + }, + "collapsed": false, + "pycharm": { + "is_executing": true + } + }, "outputs": [], "source": [ "variables = VariablesMap(\n", @@ -289,31 +299,31 @@ " 293000000.0,\n", " ],\n", " },\n", - ")\n" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T13:28:02.924970Z", - "end_time": "2023-04-26T13:28:02.948424Z" - }, - "pycharm": { - "is_executing": true - } - } + ")" + ] }, { "cell_type": "markdown", - "source": [ - "Then we create fuel and emissions that will be used by the model." - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we create fuel and emissions that will be used by the model." + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T13:28:02.948762Z", + "start_time": "2023-04-26T13:28:02.932398Z" + }, + "collapsed": false, + "pycharm": { + "is_executing": true + } + }, "outputs": [], "source": [ "co2 = Emission(\n", @@ -321,33 +331,31 @@ " factor=Expression.setup_from_expression(2.19),\n", ")\n", "\n", - "fuel_gas = FuelType(\n", - " name=\"fuel_gas\", user_defined_category=None, emissions=[co2]\n", - ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T13:28:02.932398Z", - "end_time": "2023-04-26T13:28:02.948762Z" - }, - "pycharm": { - "is_executing": true - } - } + "fuel_gas = FuelType(name=\"fuel_gas\", user_defined_category=None, emissions=[co2])" + ] }, { "cell_type": "markdown", - "source": [ - "Next we create the Flare" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Next we create the Flare" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T13:28:02.949095Z", + "start_time": "2023-04-26T13:28:02.934113Z" + }, + "collapsed": false, + "pycharm": { + "is_executing": true + } + }, "outputs": [], "source": [ "flare = FuelConsumer(\n", @@ -369,30 +377,30 @@ " )\n", " },\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T13:28:02.934113Z", - "end_time": "2023-04-26T13:28:02.949095Z" - }, - "pycharm": { - "is_executing": true - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Then we create a gas export compressor" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we create a gas export compressor" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T13:28:02.966748Z", + "start_time": "2023-04-26T13:28:02.939094Z" + }, + "collapsed": false, + "pycharm": { + "is_executing": true + } + }, "outputs": [], "source": [ "gas_export_compressor = FuelConsumer(\n", @@ -426,34 +434,29 @@ " )\n", " },\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T13:28:02.939094Z", - "end_time": "2023-04-26T13:28:02.966748Z" - }, - "pycharm": { - "is_executing": true - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Then we create the base production load" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we create the base production load" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.117379Z", + "start_time": "2023-04-26T14:25:24.115645Z" + }, + "collapsed": false + }, "outputs": [], "source": [ - "\n", - "\n", "base_production_load = ElectricityConsumer(\n", " component_type=ComponentType.GENERIC,\n", " name=\"Base production load\",\n", @@ -471,28 +474,28 @@ " consumption_rate_type=RateType.STREAM_DAY,\n", " )\n", " },\n", - ")\n" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.115645Z", - "end_time": "2023-04-26T14:25:24.117379Z" - } - } + ")" + ] }, { "cell_type": "markdown", - "source": [ - "Then we create a gas injection compressor" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we create a gas injection compressor" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.120878Z", + "start_time": "2023-04-26T14:25:24.119794Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "gas_injection_compressor = ElectricityConsumer(\n", @@ -542,27 +545,27 @@ " },\n", " component_type=ComponentType.COMPRESSOR,\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.119794Z", - "end_time": "2023-04-26T14:25:24.120878Z" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Then we create a Produced Water Re-injection Pump" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we create a Produced Water Re-injection Pump" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.124429Z", + "start_time": "2023-04-26T14:25:24.123353Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "produced_water_reinjection_pump = ElectricityConsumer(\n", @@ -600,28 +603,28 @@ " fluid_density=Expression.setup_from_expression(1010.0),\n", " )\n", " },\n", - ")\n" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.123353Z", - "end_time": "2023-04-26T14:25:24.124429Z" - } - } + ")" + ] }, { "cell_type": "markdown", - "source": [ - "The we create a Seawater Injection Pump" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "The we create a Seawater Injection Pump" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.127468Z", + "start_time": "2023-04-26T14:25:24.126420Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "seawater_injection_pump = ElectricityConsumer(\n", @@ -653,27 +656,27 @@ " )\n", " },\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.126420Z", - "end_time": "2023-04-26T14:25:24.127468Z" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Then we collect the electricity consumers inside a GeneratorSet" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "Then we collect the electricity consumers inside a GeneratorSet" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.130979Z", + "start_time": "2023-04-26T14:25:24.129956Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "generator_set_a = GeneratorSet(\n", @@ -696,23 +699,20 @@ " seawater_injection_pump,\n", " ],\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.129956Z", - "end_time": "2023-04-26T14:25:24.130979Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.134692Z", + "start_time": "2023-04-26T14:25:24.133559Z" + }, + "collapsed": false + }, "outputs": [], "source": [ - "\n", - "\n", - "\n", "model_dto = Asset(\n", " name=\"model\",\n", " installations=[\n", @@ -730,19 +730,19 @@ " venting_emitters=[],\n", " )\n", " ],\n", - ")\n" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.133559Z", - "end_time": "2023-04-26T14:25:24.134692Z" - } - } + ")" + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.148885Z", + "start_time": "2023-04-26T14:25:24.147857Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "model_graph = model_dto.get_graph()\n", @@ -758,18 +758,18 @@ " variables_map=variables,\n", " emission_results=emission_results,\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.147857Z", - "end_time": "2023-04-26T14:25:24.148885Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.638557Z", + "start_time": "2023-04-26T14:25:24.153021Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -780,33 +780,31 @@ " if identity in result.consumer_results:\n", " component_result = result.consumer_results[identity].component_result\n", " ds = pd.Series(component_result.energy_usage.values, index=component_result.energy_usage.timesteps)\n", - " _ = ds.plot(xlabel=\"time\", ylabel=component_result.energy_usage.unit, title=f\"Component: {component.name} type: {type(component).__name__}\", kind=\"line\")\n", + " _ = ds.plot(\n", + " xlabel=\"time\",\n", + " ylabel=component_result.energy_usage.unit,\n", + " title=f\"Component: {component.name} type: {type(component).__name__}\",\n", + " kind=\"line\",\n", + " )\n", " plt.show(block=False) # block=False in order to run in CI-tests." - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.153021Z", - "end_time": "2023-04-26T14:25:24.638557Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:24.640337Z", + "start_time": "2023-04-26T14:25:24.639622Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "# Dummy test in order to test to assert that this notebook runs in GitHub Actions\n", "def test_notebook_works():\n", " assert True" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:24.639622Z", - "end_time": "2023-04-26T14:25:24.640337Z" - } - } + ] } ], "metadata": { diff --git a/examples/simple_yaml_model.ipynb b/examples/simple_yaml_model.ipynb index 885fa2de4f..45ffc26448 100644 --- a/examples/simple_yaml_model.ipynb +++ b/examples/simple_yaml_model.ipynb @@ -2,6 +2,9 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# Simple Model Example\n", "\n", @@ -39,14 +42,18 @@ "All files for the example can be found in the directory references in the code below.\n", "\n", "Here is how you load and run a YAML-model in eCalcâ„¢" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:25.542990Z", + "start_time": "2023-04-26T14:25:25.462190Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "from pathlib import Path\n", @@ -72,18 +79,18 @@ " variables_map=yaml_model.variables,\n", " emission_results=emission_results,\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:25.462190Z", - "end_time": "2023-04-26T14:25:25.542990Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:26.099329Z", + "start_time": "2023-04-26T14:25:25.559549Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -94,33 +101,31 @@ " if identity in result.consumer_results:\n", " component_result = result.consumer_results[identity].component_result\n", " ds = pd.Series(component_result.energy_usage.values, index=component_result.energy_usage.timesteps)\n", - " _ = ds.plot(xlabel=\"time\", ylabel=component_result.energy_usage.unit, title=f\"Component: {component.name} type: {type(component).__name__}\", kind=\"line\")\n", + " _ = ds.plot(\n", + " xlabel=\"time\",\n", + " ylabel=component_result.energy_usage.unit,\n", + " title=f\"Component: {component.name} type: {type(component).__name__}\",\n", + " kind=\"line\",\n", + " )\n", " plt.show(block=False) # block=False in order to run in CI-tests." - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:25.559549Z", - "end_time": "2023-04-26T14:25:26.099329Z" - } - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2023-04-26T14:25:26.101180Z", + "start_time": "2023-04-26T14:25:26.100018Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "# Dummy test in order to test to assert that this notebook runs in GitHub Actions\n", "def test_notebook_works():\n", " assert True" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "start_time": "2023-04-26T14:25:26.100018Z", - "end_time": "2023-04-26T14:25:26.101180Z" - } - } + ] } ], "metadata": { diff --git a/src/libecalc/common/errors/exceptions.py b/src/libecalc/common/errors/exceptions.py index d0103fb3a4..7a20f59b52 100644 --- a/src/libecalc/common/errors/exceptions.py +++ b/src/libecalc/common/errors/exceptions.py @@ -71,8 +71,7 @@ def __init__(self, message: str): super().__init__("Invalid reference", message, error_type=EcalcErrorType.CLIENT_ERROR) -class InvalidDateException(EcalcError): - ... +class InvalidDateException(EcalcError): ... class InvalidResourceHeaderException(EcalcError): diff --git a/src/libecalc/common/graph.py b/src/libecalc/common/graph.py index 7e1a5f501b..e1ff1ff792 100644 --- a/src/libecalc/common/graph.py +++ b/src/libecalc/common/graph.py @@ -10,8 +10,7 @@ class NodeWithID(Protocol): @property - def id(self) -> NodeID: - ... + def id(self) -> NodeID: ... TNode = TypeVar("TNode", bound=NodeWithID) diff --git a/src/libecalc/common/utils/rates.py b/src/libecalc/common/utils/rates.py index 8ee169167b..d59634fd65 100644 --- a/src/libecalc/common/utils/rates.py +++ b/src/libecalc/common/utils/rates.py @@ -112,7 +112,7 @@ def to_volumes( @staticmethod def compute_cumulative( - volumes: Union[List[float], NDArray[np.float64][float, numpy.dtype[numpy.float64]]] + volumes: Union[List[float], NDArray[np.float64][float, numpy.dtype[numpy.float64]]], ) -> NDArray[np.float64][float, numpy.dtype[numpy.float64]]: """ Compute cumulative volumes from a list of periodic volumes @@ -185,8 +185,7 @@ def __lt__(self, other) -> bool: return all(self_value < other_value for self_value, other_value in zip(self.values, other.values)) @abstractmethod - def resample(self, freq: Frequency, include_start_date: bool, include_end_date: bool) -> Self: - ... + def resample(self, freq: Frequency, include_start_date: bool, include_end_date: bool) -> Self: ... def extend(self, other: TimeSeries) -> Self: if self.unit != other.unit: diff --git a/src/libecalc/core/consumers/base/component.py b/src/libecalc/core/consumers/base/component.py index c1897a5802..c934038aff 100644 --- a/src/libecalc/core/consumers/base/component.py +++ b/src/libecalc/core/consumers/base/component.py @@ -13,17 +13,16 @@ def evaluate( self, variables_map: VariablesMap, temporal_operational_settings, - ) -> EcalcModelResult: - ... + ) -> EcalcModelResult: ... class BaseConsumerWithoutOperationalSettings(ABC): id: str @abstractmethod - def get_max_rate(self, inlet_stream: TimeSeriesStreamConditions, target_pressure: TimeSeriesFloat) -> List[float]: - ... + def get_max_rate( + self, inlet_stream: TimeSeriesStreamConditions, target_pressure: TimeSeriesFloat + ) -> List[float]: ... @abstractmethod - def evaluate(self, **kwargs) -> EcalcModelResult: - ... + def evaluate(self, **kwargs) -> EcalcModelResult: ... diff --git a/src/libecalc/core/consumers/factory.py b/src/libecalc/core/consumers/factory.py index 61dea58622..492da838c0 100644 --- a/src/libecalc/core/consumers/factory.py +++ b/src/libecalc/core/consumers/factory.py @@ -11,8 +11,7 @@ @overload -def create_consumer(consumer: dto.components.CompressorComponent, timestep: datetime) -> Compressor: - ... +def create_consumer(consumer: dto.components.CompressorComponent, timestep: datetime) -> Compressor: ... @overload diff --git a/src/libecalc/core/consumers/legacy_consumer/consumer_function/results.py b/src/libecalc/core/consumers/legacy_consumer/consumer_function/results.py index d66460e893..7b9fc8be16 100644 --- a/src/libecalc/core/consumers/legacy_consumer/consumer_function/results.py +++ b/src/libecalc/core/consumers/legacy_consumer/consumer_function/results.py @@ -37,8 +37,7 @@ class ConsumerFunctionResultBase(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True) @abstractmethod - def extend(self, other: object) -> ConsumerFunctionResultBase: - ... + def extend(self, other: object) -> ConsumerFunctionResultBase: ... class ConsumerFunctionResult(ConsumerFunctionResultBase): diff --git a/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py b/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py index 30fdf60863..674face5d9 100644 --- a/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py +++ b/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py @@ -73,16 +73,14 @@ def number_of_consumers(self) -> int: def evaluate_consumers( self, operational_setting: ConsumerSystemOperationalSetting, - ) -> List[ConsumerSystemComponentResult]: - ... + ) -> List[ConsumerSystemComponentResult]: ... @abstractmethod def evaluate_operational_setting_expressions( self, operational_setting_expressions: ConsumerSystemOperationalSettingExpressions, variables_map: VariablesMap, - ) -> ConsumerSystemOperationalSetting: - ... + ) -> ConsumerSystemOperationalSetting: ... def evaluate( self, diff --git a/src/libecalc/core/consumers/legacy_consumer/system/operational_setting.py b/src/libecalc/core/consumers/legacy_consumer/system/operational_setting.py index 82da7d9fec..906ce854ff 100644 --- a/src/libecalc/core/consumers/legacy_consumer/system/operational_setting.py +++ b/src/libecalc/core/consumers/legacy_consumer/system/operational_setting.py @@ -64,8 +64,7 @@ def _log_error(field: str, field_values: List[Any], n_rates) -> None: return self -class CompressorSystemOperationalSettingExpressions(ConsumerSystemOperationalSettingExpressions): - ... +class CompressorSystemOperationalSettingExpressions(ConsumerSystemOperationalSettingExpressions): ... class PumpSystemOperationalSettingExpressions(ConsumerSystemOperationalSettingExpressions): @@ -144,8 +143,7 @@ def set_rates_after_cross_over( return self.__class__(**data) -class CompressorSystemOperationalSetting(ConsumerSystemOperationalSetting): - ... +class CompressorSystemOperationalSetting(ConsumerSystemOperationalSetting): ... class PumpSystemOperationalSetting(ConsumerSystemOperationalSetting): diff --git a/src/libecalc/core/consumers/legacy_consumer/system/results.py b/src/libecalc/core/consumers/legacy_consumer/system/results.py index 37ded4ec14..e3e50484dc 100644 --- a/src/libecalc/core/consumers/legacy_consumer/system/results.py +++ b/src/libecalc/core/consumers/legacy_consumer/system/results.py @@ -115,9 +115,9 @@ class ConsumerSystemConsumerFunctionResult(ConsumerFunctionResultBase): operational_settings: List[List[ConsumerSystemOperationalSetting]] operational_settings_results: List[List[ConsumerSystemOperationalSettingResult]] consumer_results: List[List[ConsumerSystemComponentResult]] - cross_over_used: Optional[ - PydanticNDArray - ] = None # 0 or 1 whether cross over is used for this result (1=True, 0=False) + cross_over_used: Optional[PydanticNDArray] = ( + None # 0 or 1 whether cross over is used for this result (1=True, 0=False) + ) def extend(self, other) -> ConsumerSystemConsumerFunctionResult: if not isinstance(self, type(other)): diff --git a/src/libecalc/core/models/base.py b/src/libecalc/core/models/base.py index d36b751469..5f61c2efd5 100644 --- a/src/libecalc/core/models/base.py +++ b/src/libecalc/core/models/base.py @@ -1,2 +1 @@ -class BaseModel: - ... +class BaseModel: ... diff --git a/src/libecalc/core/models/compressor/sampled/compressor_model_sampled_1d.py b/src/libecalc/core/models/compressor/sampled/compressor_model_sampled_1d.py index 6966a248d0..cafaf13f3b 100644 --- a/src/libecalc/core/models/compressor/sampled/compressor_model_sampled_1d.py +++ b/src/libecalc/core/models/compressor/sampled/compressor_model_sampled_1d.py @@ -97,7 +97,9 @@ def __init__(self, sampled_data: pd.DataFrame, function_header: str): if not all_variable_values_unique: seen = set() duplicates = [ - x for x in sorted_sampled_data[self._x_column_name] if x in seen or seen.add(x) # type: ignore[func-returns-value] + x + for x in sorted_sampled_data[self._x_column_name] + if x in seen or seen.add(x) # type: ignore[func-returns-value] ] msg = ( f"1D compressor sampled data require unique variable input values. " diff --git a/src/libecalc/core/models/compressor/train/simplified_train.py b/src/libecalc/core/models/compressor/train/simplified_train.py index 6887f5e506..7e02557525 100644 --- a/src/libecalc/core/models/compressor/train/simplified_train.py +++ b/src/libecalc/core/models/compressor/train/simplified_train.py @@ -174,9 +174,7 @@ def calculate_compressor_stage_work_given_outlet_pressure( else: # Static efficiency regardless of rate and head. This happens if Generic chart from input is used. def efficiency_as_function_of_rate_and_head(rates, heads): - return np.full_like( - rates, fill_value=stage.polytropic_efficiency, dtype=float - ) + return np.full_like(rates, fill_value=stage.polytropic_efficiency, dtype=float) polytropic_enthalpy_change_joule_per_kg, polytropic_efficiency = calculate_enthalpy_change_head_iteration( inlet_streams=inlet_streams, diff --git a/src/libecalc/core/models/results/compressor.py b/src/libecalc/core/models/results/compressor.py index fce52bc46b..412548dabd 100644 --- a/src/libecalc/core/models/results/compressor.py +++ b/src/libecalc/core/models/results/compressor.py @@ -81,12 +81,12 @@ class CompressorStageResult(EnergyModelBaseResult): power: Optional[List[Optional[float]]] = None power_unit: Optional[Unit] = None - mass_rate_kg_per_hr: Optional[ - List[Optional[float]] - ] = None # The gross mass rate passing through a compressor stage - mass_rate_before_asv_kg_per_hr: Optional[ - List[Optional[float]] - ] = None # The net mass rate through a compressor stage + mass_rate_kg_per_hr: Optional[List[Optional[float]]] = ( + None # The gross mass rate passing through a compressor stage + ) + mass_rate_before_asv_kg_per_hr: Optional[List[Optional[float]]] = ( + None # The net mass rate through a compressor stage + ) inlet_stream_condition: CompressorStreamCondition outlet_stream_condition: CompressorStreamCondition diff --git a/src/libecalc/core/models/results/generic.py b/src/libecalc/core/models/results/generic.py index 5c76fc402c..ca5a581b50 100644 --- a/src/libecalc/core/models/results/generic.py +++ b/src/libecalc/core/models/results/generic.py @@ -3,5 +3,4 @@ from libecalc.core.models.results.base import EnergyFunctionResult -class EnergyFunctionGenericResult(EnergyFunctionResult): - ... +class EnergyFunctionGenericResult(EnergyFunctionResult): ... diff --git a/src/libecalc/core/result/results.py b/src/libecalc/core/result/results.py index 14dfaa996f..93344efeda 100644 --- a/src/libecalc/core/result/results.py +++ b/src/libecalc/core/result/results.py @@ -116,8 +116,7 @@ class ConsumerModelResultBase(ABC, CommonResultBase): @property @abstractmethod - def component_type(self): - ... + def component_type(self): ... name: str diff --git a/src/libecalc/core/utils/array_type.py b/src/libecalc/core/utils/array_type.py index 01cbd33036..67035e88ba 100644 --- a/src/libecalc/core/utils/array_type.py +++ b/src/libecalc/core/utils/array_type.py @@ -1,6 +1,7 @@ """ Custom pydantic type to allow for serialization and validation of ndarray """ + import numpy as np from pydantic import BeforeValidator, PlainSerializer from typing_extensions import Annotated diff --git a/src/libecalc/domain/stream_conditions.py b/src/libecalc/domain/stream_conditions.py index 63348ff523..8f617dcc8e 100644 --- a/src/libecalc/domain/stream_conditions.py +++ b/src/libecalc/domain/stream_conditions.py @@ -1,6 +1,7 @@ """ Point in time stream conditions """ + from __future__ import annotations import dataclasses diff --git a/src/libecalc/domain/tabular/tabular.py b/src/libecalc/domain/tabular/tabular.py index 8ef903dac6..54936c4559 100644 --- a/src/libecalc/domain/tabular/tabular.py +++ b/src/libecalc/domain/tabular/tabular.py @@ -10,23 +10,19 @@ class Tabular(Protocol[RowIndex, ColumnIndex, TValue]): @property @abc.abstractmethod - def row_ids(self) -> List[RowIndex]: - ... + def row_ids(self) -> List[RowIndex]: ... @property @abc.abstractmethod - def column_ids(self) -> List[ColumnIndex]: - ... + def column_ids(self) -> List[ColumnIndex]: ... @abc.abstractmethod - def get_value(self, row_id: RowIndex, column_id: ColumnIndex) -> TValue: - ... + def get_value(self, row_id: RowIndex, column_id: ColumnIndex) -> TValue: ... class Column(Protocol): @abc.abstractmethod - def get_title(self) -> str: - ... + def get_title(self) -> str: ... TColumn = TypeVar("TColumn", bound=Column, covariant=True) @@ -34,5 +30,4 @@ def get_title(self) -> str: class HasColumns(Protocol[TColumn]): @abc.abstractmethod - def get_column(self, column_id: ColumnIndex) -> TColumn: - ... + def get_column(self, column_id: ColumnIndex) -> TColumn: ... diff --git a/src/libecalc/dto/base.py b/src/libecalc/dto/base.py index fa77cfe335..c0ff214236 100644 --- a/src/libecalc/dto/base.py +++ b/src/libecalc/dto/base.py @@ -84,5 +84,4 @@ class Component(EcalcBaseModel, ABC): @property @abstractmethod - def id(self) -> str: - ... + def id(self) -> str: ... diff --git a/src/libecalc/dto/core_specs/base/operational_settings.py b/src/libecalc/dto/core_specs/base/operational_settings.py index 480682107f..bfe69115bc 100644 --- a/src/libecalc/dto/core_specs/base/operational_settings.py +++ b/src/libecalc/dto/core_specs/base/operational_settings.py @@ -8,5 +8,4 @@ class OperationalSettings(ABC, EcalcBaseModel): @abstractmethod - def get_subset_for_timestep(self, timestep: datetime) -> Self: - ... + def get_subset_for_timestep(self, timestep: datetime) -> Self: ... diff --git a/src/libecalc/dto/models/compressor/train.py b/src/libecalc/dto/models/compressor/train.py index 09a85032aa..3a8253a025 100644 --- a/src/libecalc/dto/models/compressor/train.py +++ b/src/libecalc/dto/models/compressor/train.py @@ -26,9 +26,9 @@ class CompressorTrain(EnergyModel): class CompressorTrainSimplifiedWithKnownStages(CompressorTrain): - typ: Literal[ + typ: Literal[EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_KNOWN_STAGES] = ( EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_KNOWN_STAGES - ] = EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_KNOWN_STAGES + ) # Not in use: pressure_control: Optional[FixedSpeedPressureControl] = None # Not relevant for simplified trains. @@ -50,9 +50,9 @@ class CompressorTrainSimplifiedWithUnknownStages(CompressorTrain): Will be constrained by a maximum pressure ratio per stage. """ - typ: Literal[ + typ: Literal[EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_UNKNOWN_STAGES] = ( EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_UNKNOWN_STAGES - ] = EnergyModelType.COMPRESSOR_TRAIN_SIMPLIFIED_WITH_UNKNOWN_STAGES + ) stage: CompressorStage maximum_pressure_ratio_per_stage: Annotated[float, Field(ge=0)] @@ -74,9 +74,9 @@ def _validate_stages(cls, stage): class SingleSpeedCompressorTrain(CompressorTrain): """Single speed train has a control mechanism for max discharge pressure.""" - typ: Literal[ + typ: Literal[EnergyModelType.SINGLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT] = ( EnergyModelType.SINGLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT - ] = EnergyModelType.SINGLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT + ) maximum_discharge_pressure: Optional[Annotated[float, Field(ge=0)]] = None @field_validator("stages") @@ -92,9 +92,9 @@ def _validate_stages(cls, stages): class VariableSpeedCompressorTrain(CompressorTrain): - typ: Literal[ + typ: Literal[EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT] = ( EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT - ] = EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT + ) @field_validator("stages") @classmethod @@ -129,9 +129,9 @@ class VariableSpeedCompressorTrainMultipleStreamsAndPressures(CompressorTrain): and the dto similar. """ - typ: Literal[ + typ: Literal[EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES] = ( EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES - ] = EnergyModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES + ) streams: List[MultipleStreamsAndPressureStream] stages: List[MultipleStreamsCompressorStage] diff --git a/src/libecalc/dto/utils/validators.py b/src/libecalc/dto/utils/validators.py index 438564faa3..f0f3c74224 100644 --- a/src/libecalc/dto/utils/validators.py +++ b/src/libecalc/dto/utils/validators.py @@ -18,7 +18,7 @@ def convert_expression( - value: Optional[Union[ExpressionType, Dict[date, ExpressionType]]] + value: Optional[Union[ExpressionType, Dict[date, ExpressionType]]], ) -> Optional[Union[Expression, Dict[date, Expression]]]: if value is None or isinstance(value, Expression): return value @@ -28,7 +28,7 @@ def convert_expression( def convert_expressions( - value: Optional[List[Optional[Union[ExpressionType, Dict[date, ExpressionType]]]]] + value: Optional[List[Optional[Union[ExpressionType, Dict[date, ExpressionType]]]]], ) -> Optional[List[Optional[Union[Expression, Dict[date, Expression]]]]]: if value is None: return value diff --git a/src/libecalc/presentation/exporter/formatters/formatter.py b/src/libecalc/presentation/exporter/formatters/formatter.py index d51c66e0af..6b9d334169 100644 --- a/src/libecalc/presentation/exporter/formatters/formatter.py +++ b/src/libecalc/presentation/exporter/formatters/formatter.py @@ -8,15 +8,13 @@ ColumnIndex = Union[str] -class Formattable(Tabular, HasColumns, Protocol): - ... +class Formattable(Tabular, HasColumns, Protocol): ... class FormattableGroup(Protocol): @property @abc.abstractmethod - def groups(self) -> Iterator[Tuple[str, Formattable]]: - ... + def groups(self) -> Iterator[Tuple[str, Formattable]]: ... class Formatter(abc.ABC): @@ -29,8 +27,7 @@ def format(self, table: Formattable) -> List[str]: ... @abc.abstractmethod - def format_group(self, groups: FormattableGroup) -> Dict[str, List[str]]: - ... + def format_group(self, groups: FormattableGroup) -> Dict[str, List[str]]: ... class CSVFormatter: diff --git a/src/libecalc/presentation/json_result/mapper.py b/src/libecalc/presentation/json_result/mapper.py index fa7c4a8e09..37eeb7c0c1 100644 --- a/src/libecalc/presentation/json_result/mapper.py +++ b/src/libecalc/presentation/json_result/mapper.py @@ -158,7 +158,7 @@ def _compute_intensity( def _to_full_result( - emissions: Dict[str, PartialEmissionResult] + emissions: Dict[str, PartialEmissionResult], ) -> Dict[str, libecalc.presentation.json_result.result.EmissionResult]: """ From the partial result, generate cumulatives for the full emissions result per installation diff --git a/src/libecalc/presentation/json_result/result/results.py b/src/libecalc/presentation/json_result/result/results.py index 9f55001baf..7ad591bc90 100644 --- a/src/libecalc/presentation/json_result/result/results.py +++ b/src/libecalc/presentation/json_result/result/results.py @@ -62,8 +62,7 @@ class ComponentResultBase(CommonResultBase, NodeInfo): emissions: Dict[str, EmissionResult] -class EquipmentResultBase(ComponentResultBase): - ... +class EquipmentResultBase(ComponentResultBase): ... class AssetResult(ComponentResultBase): diff --git a/src/libecalc/presentation/yaml/mappers/model.py b/src/libecalc/presentation/yaml/mappers/model.py index 817a140d0f..599065be87 100644 --- a/src/libecalc/presentation/yaml/mappers/model.py +++ b/src/libecalc/presentation/yaml/mappers/model.py @@ -535,7 +535,10 @@ def _simplified_variable_speed_compressor_train_mapper( model_config: Dict, input_models: Dict[str, Any], resources: Resources, -) -> Union[dto.CompressorTrainSimplifiedWithKnownStages, dto.CompressorTrainSimplifiedWithUnknownStages,]: +) -> Union[ + dto.CompressorTrainSimplifiedWithKnownStages, + dto.CompressorTrainSimplifiedWithUnknownStages, +]: fluid_model_reference: str = model_config.get(EcalcYamlKeywords.models_type_fluid_model) fluid_model = input_models.get(fluid_model_reference) if fluid_model is None: diff --git a/src/libecalc/presentation/yaml/yaml_models/yaml_model.py b/src/libecalc/presentation/yaml/yaml_models/yaml_model.py index 770f14d1de..7dda65be90 100644 --- a/src/libecalc/presentation/yaml/yaml_models/yaml_model.py +++ b/src/libecalc/presentation/yaml/yaml_models/yaml_model.py @@ -78,8 +78,7 @@ def dates(self): pass @abc.abstractmethod - def validate(self, context: YamlModelValidationContext) -> YamlAsset: - ... + def validate(self, context: YamlModelValidationContext) -> YamlAsset: ... class YamlReader(abc.ABC): @@ -141,9 +140,9 @@ class YamlModel(YamlReader, YamlDumper, metaclass=abc.ABCMeta): is compatible across, but this must be handled and verified properly. """ - _internal_datamodel: Dict[ - str, Any - ] = None # to temporary store a loaded yaml model. Format is defined by implementation + _internal_datamodel: Dict[str, Any] = ( + None # to temporary store a loaded yaml model. Format is defined by implementation + ) def __init__(self, internal_datamodel: Dict[str, Any]): self._internal_datamodel = internal_datamodel diff --git a/src/tests/libecalc/core/models/compressor_modelling/test_single_speed_compressor_train_common_shaft.py b/src/tests/libecalc/core/models/compressor_modelling/test_single_speed_compressor_train_common_shaft.py index c83e5dea6e..68c52124a1 100644 --- a/src/tests/libecalc/core/models/compressor_modelling/test_single_speed_compressor_train_common_shaft.py +++ b/src/tests/libecalc/core/models/compressor_modelling/test_single_speed_compressor_train_common_shaft.py @@ -129,9 +129,7 @@ def test_adjust_energy_constant_mw( discharge_pressure=target_discharge_pressures, ) - single_speed_compressor_train_common_shaft_downstream_choking.data_transfer_object.energy_usage_adjustment_constant = ( - energy_usage_adjustment_constant - ) + single_speed_compressor_train_common_shaft_downstream_choking.data_transfer_object.energy_usage_adjustment_constant = energy_usage_adjustment_constant result = single_speed_compressor_train_common_shaft_downstream_choking.evaluate_rate_ps_pd( rate=np.asarray([5800000.0, 5800000.0, 1000.0, 8189000.0]), suction_pressure=np.asarray(suction_pressures), diff --git a/src/tests/libecalc/core/models/compressor_modelling/test_variable_speed_compressor_train_multiple_streams.py b/src/tests/libecalc/core/models/compressor_modelling/test_variable_speed_compressor_train_multiple_streams.py index a4b2424c08..2ca3e53b88 100644 --- a/src/tests/libecalc/core/models/compressor_modelling/test_variable_speed_compressor_train_multiple_streams.py +++ b/src/tests/libecalc/core/models/compressor_modelling/test_variable_speed_compressor_train_multiple_streams.py @@ -664,12 +664,8 @@ def test_adjust_energy_usage( ) ) - variable_speed_compressor_train_one_compressor_one_stream_downstream_choke.data_transfer_object.energy_usage_adjustment_constant = ( - energy_usage_adjustment_constant # MW - ) - variable_speed_compressor_train_two_compressors_one_ingoing_and_one_outgoing_stream.data_transfer_object.energy_usage_adjustment_constant = ( - energy_usage_adjustment_constant - ) + variable_speed_compressor_train_one_compressor_one_stream_downstream_choke.data_transfer_object.energy_usage_adjustment_constant = energy_usage_adjustment_constant # MW + variable_speed_compressor_train_two_compressors_one_ingoing_and_one_outgoing_stream.data_transfer_object.energy_usage_adjustment_constant = energy_usage_adjustment_constant result = variable_speed_compressor_train_one_compressor_one_stream_downstream_choke.evaluate_rate_ps_pd( rate=np.asarray([[3000000]]),