Skip to content

Commit

Permalink
try from __future__ import annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
aclerc committed Sep 5, 2024
1 parent 41da13d commit c3290be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies = [
'seaborn',
'tabulate',
'toml',
'utm',
'tqdm',
'utm',
]

[project.urls]
Expand Down
22 changes: 12 additions & 10 deletions wind_up/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime as dt
import logging
from pathlib import Path
Expand Down Expand Up @@ -53,7 +55,7 @@ class Turbine(BaseModel):
latitude: float = Field(default=np.nan, ge=-90, le=90)
longitude: float = Field(default=np.nan, ge=-180, le=180)

def get_latlongs(self: "Turbine") -> list[tuple[float, float]]:
def get_latlongs(self: Turbine) -> list[tuple[float, float]]:
return [(self.latitude, self.longitude)]


Expand Down Expand Up @@ -268,21 +270,21 @@ class WindUpConfig(BaseModel):
prepost: PrePost | None = None

@model_validator(mode="after")
def check_years_offset_for_pre_period(self: "WindUpConfig") -> "WindUpConfig":
def check_years_offset_for_pre_period(self: WindUpConfig) -> WindUpConfig:
if self.toggle is None and self.years_offset_for_pre_period is None:
msg = "toggle is None and years_offset_for_pre_period is None"
raise ValueError(msg)
return self

@model_validator(mode="after")
def check_first_datetime_before_last(self: "WindUpConfig") -> "WindUpConfig":
def check_first_datetime_before_last(self: WindUpConfig) -> WindUpConfig:
if self.upgrade_first_dt_utc_start >= self.analysis_last_dt_utc_start:
msg = "upgrade_first_datetime must be before last_useable_datetime"
raise ValueError(msg)
return self

@model_validator(mode="after")
def check_non_wtg_ref_names(self: "WindUpConfig") -> "WindUpConfig":
def check_non_wtg_ref_names(self: WindUpConfig) -> WindUpConfig:
for non_wtg_ref in self.non_wtg_ref_names:
if non_wtg_ref == "reanalysis":
if len(self.reanalysis_method) < 1:
Expand All @@ -294,7 +296,7 @@ def check_non_wtg_ref_names(self: "WindUpConfig") -> "WindUpConfig":
return self

@model_validator(mode="after")
def print_summary(self: "WindUpConfig") -> "WindUpConfig":
def print_summary(self: WindUpConfig) -> WindUpConfig:
logger.info(f"loaded WindUpConfig assessment_name: {self.assessment_name}")
dt_fmt = "%Y-%m-%d %H:%M"
if self.toggle is not None:
Expand Down Expand Up @@ -424,10 +426,10 @@ def from_yaml(cls, file_path: Path) -> "WindUpConfig": # noqa ANN102
raise ValueError(msg)
return WindUpConfig.model_validate(cfg_dct)

def get_max_rated_power(self: "WindUpConfig") -> float:
def get_max_rated_power(self: WindUpConfig) -> float:
return max(x.turbine_type.rated_power_kw for x in self.asset.wtgs)

def list_unique_turbine_types(self: "WindUpConfig") -> list["TurbineType"]:
def list_unique_turbine_types(self: WindUpConfig) -> list[TurbineType]:
unique_names = sorted({x.turbine_type.turbine_type for x in self.asset.wtgs})
unique_turbine_types = []
for name in unique_names:
Expand All @@ -436,11 +438,11 @@ def list_unique_turbine_types(self: "WindUpConfig") -> list["TurbineType"]:
)
return unique_turbine_types

def list_turbine_ids_of_type(self: "WindUpConfig", ttype: "TurbineType") -> list[str]:
def list_turbine_ids_of_type(self: WindUpConfig, ttype: TurbineType) -> list[str]:
return [x.name for x in self.asset.wtgs if x.turbine_type == ttype]

def get_normal_operation_genrpm_range(self: "WindUpConfig", ttype: "TurbineType") -> tuple[float, float]:
def get_normal_operation_genrpm_range(self: WindUpConfig, ttype: TurbineType) -> tuple[float, float]:
return next(x.turbine_type.normal_operation_genrpm_range for x in self.asset.wtgs if x.turbine_type == ttype)

def get_normal_operation_pitch_range(self: "WindUpConfig", ttype: "TurbineType") -> tuple[float, float]:
def get_normal_operation_pitch_range(self: WindUpConfig, ttype: TurbineType) -> tuple[float, float]:
return next(x.turbine_type.normal_operation_pitch_range for x in self.asset.wtgs if x.turbine_type == ttype)

0 comments on commit c3290be

Please sign in to comment.