Skip to content

Commit

Permalink
chore: run ruff-format all files
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Aug 26, 2024
1 parent d02b41b commit 6880e12
Show file tree
Hide file tree
Showing 31 changed files with 278 additions and 301 deletions.
354 changes: 176 additions & 178 deletions examples/simple_python_model.ipynb

Large diffs are not rendered by default.

63 changes: 34 additions & 29 deletions examples/simple_yaml_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# Simple Model Example\n",
"\n",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions src/libecalc/common/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions src/libecalc/common/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

class NodeWithID(Protocol):
@property
def id(self) -> NodeID:
...
def id(self) -> NodeID: ...


TNode = TypeVar("TNode", bound=NodeWithID)
Expand Down
5 changes: 2 additions & 3 deletions src/libecalc/common/utils/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions src/libecalc/core/consumers/base/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
3 changes: 1 addition & 2 deletions src/libecalc/core/consumers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -144,8 +143,7 @@ def set_rates_after_cross_over(
return self.__class__(**data)


class CompressorSystemOperationalSetting(ConsumerSystemOperationalSetting):
...
class CompressorSystemOperationalSetting(ConsumerSystemOperationalSetting): ...


class PumpSystemOperationalSetting(ConsumerSystemOperationalSetting):
Expand Down
6 changes: 3 additions & 3 deletions src/libecalc/core/consumers/legacy_consumer/system/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
3 changes: 1 addition & 2 deletions src/libecalc/core/models/base.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
class BaseModel:
...
class BaseModel: ...
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/libecalc/core/models/results/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/libecalc/core/models/results/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
from libecalc.core.models.results.base import EnergyFunctionResult


class EnergyFunctionGenericResult(EnergyFunctionResult):
...
class EnergyFunctionGenericResult(EnergyFunctionResult): ...
3 changes: 1 addition & 2 deletions src/libecalc/core/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ class ConsumerModelResultBase(ABC, CommonResultBase):

@property
@abstractmethod
def component_type(self):
...
def component_type(self): ...

name: str

Expand Down
1 change: 1 addition & 0 deletions src/libecalc/core/utils/array_type.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/libecalc/domain/stream_conditions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Point in time stream conditions
"""

from __future__ import annotations

import dataclasses
Expand Down
15 changes: 5 additions & 10 deletions src/libecalc/domain/tabular/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@
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)


class HasColumns(Protocol[TColumn]):
@abc.abstractmethod
def get_column(self, column_id: ColumnIndex) -> TColumn:
...
def get_column(self, column_id: ColumnIndex) -> TColumn: ...
3 changes: 1 addition & 2 deletions src/libecalc/dto/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ class Component(EcalcBaseModel, ABC):

@property
@abstractmethod
def id(self) -> str:
...
def id(self) -> str: ...
3 changes: 1 addition & 2 deletions src/libecalc/dto/core_specs/base/operational_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Loading

0 comments on commit 6880e12

Please sign in to comment.