Skip to content

Commit

Permalink
chore: mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Dec 10, 2024
1 parent e3e1e6a commit add6842
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/libecalc/common/time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,23 @@ def get_period(self, period: Period) -> Optional[Period]:
return None

@property
def all_dates(self):
def all_dates(self) -> list[datetime]:
return self.start_dates + [self.end_dates[-1]]

@property
def start_dates(self):
def start_dates(self) -> list[datetime]:
return [period.start for period in self.periods]

@property
def end_dates(self):
def end_dates(self) -> list[datetime]:
return [period.end for period in self.periods]

@property
def last_date(self):
def last_date(self) -> datetime:
return self.end_dates[-1]

@property
def first_date(self):
def first_date(self) -> datetime:
return self.start_dates[0]

def __add__(self, other):
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/common/utils/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def resample(
ds_interpolated = ds.reindex(ds.index.union(new_dates)).interpolate("slinear")

# New resampled pd.Series
resampled = ds_interpolated.reindex(new_dates).values.tolist()
resampled: list[float] = ds_interpolated.reindex(new_dates).values.tolist()

if not include_start_date:
dropped_cumulative_volume = resampled[0]
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/common/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _evaluate_temporal(

class ExpressionEvaluator(Protocol):
@abc.abstractmethod
def get_time_vector(self) -> [list[datetime]]: ...
def get_time_vector(self) -> list[datetime]: ...

@abc.abstractmethod
def get_period(self) -> Period: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def calculate_enthalpy_change_head_iteration(
"""

pressure_ratios = outlet_pressure / inlet_pressure
pressure_ratios = np.divide(outlet_pressure, inlet_pressure) # Using divide seems to keep the float64 type
inlet_kappa = np.asarray([stream.kappa for stream in inlet_streams])
inlet_z = np.asarray([stream.z for stream in inlet_streams])

Expand Down
3 changes: 3 additions & 0 deletions src/libecalc/core/models/model_input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def _validate_model_input(
if np.ndim(rate) == 2:
# check if any of the streams have changed value during validation, streams along axis 0, time along axis 1
invalid_rate_input = np.any(rate != input_rate, axis=0)

# Ensure invalid_rate_input is an array and not a single bool, this should be the case since using axis=0.
assert isinstance(invalid_rate_input, np.ndarray)
else:
invalid_rate_input = np.where(rate != input_rate, True, False)

Expand Down
6 changes: 3 additions & 3 deletions src/libecalc/core/models/results/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def is_valid(self) -> list[bool]:
if self.stage_results is not None
else [not isnan(x) for x in self.energy_usage]
)
return list(np.all([failure_status_are_valid, turbine_are_valid, stage_results_are_valid], axis=0))
return np.all([failure_status_are_valid, turbine_are_valid, stage_results_are_valid], axis=0).tolist()

@property
def inlet_stream(self) -> CompressorStreamCondition:
Expand All @@ -248,12 +248,12 @@ def mass_rate_kg_per_hr(self) -> list[float]:

@property
def pressure_is_choked(self) -> list[bool]:
return list(np.any([stage.pressure_is_choked for stage in self.stage_results], axis=0))
return np.any([stage.pressure_is_choked for stage in self.stage_results], axis=0).tolist()

@property
def recirculation_loss(self) -> list[float]:
return list(elementwise_sum(*[stage.asv_recirculation_loss_mw for stage in self.stage_results]))

@property
def rate_exceeds_maximum(self) -> list[bool]:
return list(np.any([stage.rate_exceeds_maximum for stage in self.stage_results], axis=0))
return np.any([stage.rate_exceeds_maximum for stage in self.stage_results], axis=0).tolist()
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import Field, model_validator

from libecalc.presentation.yaml.yaml_types import YamlBase
Expand All @@ -12,7 +14,7 @@ class EnergyUsageModelCommon(YamlBase):
title="CONDITION",
description="Logical condition for the consumer to be used.\n\n$ECALC_DOCS_KEYWORDS_URL/CONDITION",
)
conditions: list[YamlExpressionType] = Field(
conditions: Optional[list[YamlExpressionType]] = Field(
None,
title="CONDITIONS",
description="Logical conditions for the consumer to be used.\n\n$ECALC_DOCS_KEYWORDS_URL/CONDITION",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from typing import Literal, Optional

from pydantic import Field

Expand Down Expand Up @@ -29,27 +29,27 @@ class YamlCompressorSystemCompressor(YamlBase):


class YamlCompressorSystemOperationalSetting(YamlBase):
crossover: list[int] = Field(
crossover: Optional[list[int]] = Field(
None,
title="CROSSOVER",
description="Set cross over rules in system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#crossover",
)
rates: list[YamlExpressionType] = Field(
rates: Optional[list[YamlExpressionType]] = Field(
None,
title="RATES",
description="Set rate per consumer in a consumer system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#rates",
)
rate_fractions: list[YamlExpressionType] = Field(
rate_fractions: Optional[list[YamlExpressionType]] = Field(
None,
title="RATE_FRACTIONS",
description="List of expressions defining fractional rate (of total system rate) per consumer. \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#rate-fractions",
)
suction_pressures: list[YamlExpressionType] = Field(
suction_pressures: Optional[list[YamlExpressionType]] = Field(
None,
title="SUCTION_PRESSURES",
description="Set suction pressure per consumer in a consumer system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#suction-pressures",
)
discharge_pressures: list[YamlExpressionType] = Field(
discharge_pressures: Optional[list[YamlExpressionType]] = Field(
None,
title="DISCHARGE_PRESSURES",
description="Set discharge pressure per consumer in a consumer system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#discharge-pressures",
Expand All @@ -67,7 +67,7 @@ class YamlCompressorSystemOperationalSetting(YamlBase):


class YamlPumpSystemOperationalSettings(YamlCompressorSystemOperationalSetting):
fluid_densities: list[YamlExpressionType] = Field(
fluid_densities: Optional[list[YamlExpressionType]] = Field(
None,
title="FLUID_DENSITIES",
description="Set fluid density per consumer in a consumer system operational setting. Will overwrite the systems common fluid density expression \n\n$ECALC_DOCS_KEYWORDS_URL/OPERATIONAL_SETTINGS#fluid-densities",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import ConfigDict, Field, model_validator
from pydantic_core.core_schema import ValidationInfo

Expand Down Expand Up @@ -29,19 +31,19 @@ class YamlAsset(YamlBase):
title="Asset",
)

time_series: list[YamlTimeSeriesCollection] = Field(
time_series: Optional[list[YamlTimeSeriesCollection]] = Field(
None,
title="TIME_SERIES",
description="Defines the inputs for time dependent variables, or 'reservoir variables'."
"\n\n$ECALC_DOCS_KEYWORDS_URL/TIME_SERIES",
)
facility_inputs: list[YamlFacilityModel] = Field(
facility_inputs: Optional[list[YamlFacilityModel]] = Field(
None,
title="FACILITY_INPUTS",
description="Defines input files which characterize various facility elements."
"\n\n$ECALC_DOCS_KEYWORDS_URL/FACILITY_INPUTS",
)
models: list[YamlConsumerModel] = Field(
models: Optional[list[YamlConsumerModel]] = Field(
None,
title="MODELS",
description="Defines input files which characterize various facility elements."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated, Union
from typing import Annotated, Optional, Union

from pydantic import ConfigDict, Field, model_validator

Expand Down Expand Up @@ -53,28 +53,30 @@ class YamlInstallation(YamlBase):
title="REGULARITY",
description="Regularity of the installation can be specified by a single number or as an expression. USE WITH CARE.\n\n$ECALC_DOCS_KEYWORDS_URL/REGULARITY",
)
generator_sets: list[YamlGeneratorSet] = Field(
generator_sets: Optional[list[YamlGeneratorSet]] = Field(
None,
title="GENERATORSETS",
description="Defines one or more generator sets.\n\n$ECALC_DOCS_KEYWORDS_URL/GENERATORSETS",
alias="GENERATORSETS",
)
fuel_consumers: list[
Annotated[
Union[
YamlFuelConsumer,
YamlConsumerSystem,
],
Field(discriminator="component_type"),
DiscriminatorWithFallback("TYPE", "FUEL_CONSUMER"),
fuel_consumers: Optional[
list[
Annotated[
Union[
YamlFuelConsumer,
YamlConsumerSystem,
],
Field(discriminator="component_type"),
DiscriminatorWithFallback("TYPE", "FUEL_CONSUMER"),
]
]
] = Field(
None,
title="FUELCONSUMERS",
description="Defines fuel consumers on the installation which are not generators.\n\n$ECALC_DOCS_KEYWORDS_URL/FUELCONSUMERS",
alias="FUELCONSUMERS",
)
venting_emitters: list[YamlVentingEmitter] = Field(
venting_emitters: Optional[list[YamlVentingEmitter]] = Field(
None,
title="VENTING_EMITTERS",
description="Covers the direct emissions on the installation that are not consuming energy",
Expand Down

0 comments on commit add6842

Please sign in to comment.