Skip to content

Commit

Permalink
style: stdlib collection type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
aaraney committed Aug 14, 2024
1 parent 5a8c106 commit 81f77c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions python/ngen_cal/src/ngen/cal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseModel, Field, DirectoryPath
from pathlib import Path
from typing_extensions import Literal
from typing import Any, Dict, Optional, List, Union
from typing import Any, Optional, Union
from types import ModuleType, FunctionType

#local components for composing configuration
Expand Down Expand Up @@ -38,8 +38,8 @@ class General(BaseModel):
parameter_log_file: Optional[Path]
objective_log_file: Optional[Path]
random_seed: Optional[int]
plugins: List[PyObjectOrModule] = Field(default_factory=list)
plugin_settings: Dict[str, Dict[str, Any]] = Field(default_factory=dict)
plugins: list[PyObjectOrModule] = Field(default_factory=list)
plugin_settings: dict[str, dict[str, Any]] = Field(default_factory=dict)

class Config(BaseModel.Config):
# properly serialize plugins
Expand Down
10 changes: 5 additions & 5 deletions python/ngen_cal/src/ngen/cal/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pydantic import BaseModel, DirectoryPath, conint, PyObject, validator, Field, root_validator
from typing import Any, cast, Callable, Dict, List, Optional, Tuple, Union
from typing import Any, cast, Callable, List, Optional, Union
from types import ModuleType, FunctionType
try: #to get literal in python 3.7, it was added to typing in 3.8
from typing import Literal
Expand Down Expand Up @@ -51,14 +51,14 @@ class EvaluationOptions(BaseModel):
#Optional, but co-dependent, see @_validate_start_stop_both_or_neither_exist for validation logic
evaluation_start: Optional[datetime]
evaluation_stop: Optional[datetime]
_eval_range: Tuple[datetime, datetime] = None
_eval_range: tuple[datetime, datetime] = None
"""
Optional objective function selector
TODO allow for additional kwargs to be supplied to these functions?
Document that all functions must take obs, sim args
"""
objective: Optional[Union[Objective, PyObject]] = Objective.custom
target: Union[Literal['min'], Literal['max'], float] = 'min'
target: Union[Literal['min'], Literal['max'], float] = 'min'
_best_score: float
_best_params_iteration: str = '0'
id: Optional[str]
Expand Down Expand Up @@ -220,8 +220,8 @@ class ModelExec(BaseModel, Configurable):
args: Optional[str]
workdir: DirectoryPath = Path("./") #FIXME test the various workdirs
eval_params: Optional[EvaluationOptions] = Field(default_factory=EvaluationOptions)
plugins: List[PyObjectOrModule] = Field(default_factory=list)
plugin_settings: Dict[str, Dict[str, Any]] = Field(default_factory=dict)
plugins: list[PyObjectOrModule] = Field(default_factory=list)
plugin_settings: dict[str, dict[str, Any]] = Field(default_factory=dict)

_plugin_manager: PluginManager
class Config(BaseModel.Config):
Expand Down
8 changes: 4 additions & 4 deletions python/ngen_conf/src/ngen/config/init_config/cfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class CFEBase(serde.IniSerializerDeserializer):
# Nash Config param - primary reservoir
k_lf: FloatUnitPair[empty]
# Nash Config param - secondary reservoir
nash_storage: List[float]
nash_storage: list[float]
# Giuh ordinates in dt time steps
giuh_ordinates: List[float]
giuh_ordinates: list[float]
# set to `1` if `forcing_file=BMI`
num_timesteps: int = Field(1, gte=0)

Expand Down Expand Up @@ -127,7 +127,7 @@ class CFESchaakeCoupledSoilMoisture(CFESchaake):
# layer of the soil that is the maximum root zone depth. That is, the depth of the layer where the AET is drawn from
max_root_zone_layer: FloatUnitPair[m]
# an array of depths from the surface. Example, soil_layer_depths=0.1,0.4,1.0,2.0
soil_layer_depths: List[float]
soil_layer_depths: list[float]
# `ice-fraction based runoff` | when `CFE coupled to SoilFreezeThaw`
sft_coupled: bool # True, true, 1

Expand All @@ -137,7 +137,7 @@ class CFEXinanjiangCoupledSoilMoisture(CFEXinanjiang):
# layer of the soil that is the maximum root zone depth. That is, the depth of the layer where the AET is drawn from
max_root_zone_layer: FloatUnitPair[m]
# an array of depths from the surface. Example, soil_layer_depths=0.1,0.4,1.0,2.0
soil_layer_depths: List[float]
soil_layer_depths: list[float]
# `ice-fraction based runoff` | when `CFE coupled to SoilFreezeThaw`
sft_coupled: bool # True, true, 1

Expand Down
6 changes: 3 additions & 3 deletions python/ngen_conf/src/ngen/config/init_config/noahowp.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class Config(core.Base.Config):


class InitialValues(core.Base):
dzsnso: List[float] # = 0.0, 0.0, 0.0, 0.1, 0.3, 0.6, 1.0
sice: List[float] # = 0.0, 0.0, 0.0, 0.0
sh2o: List[float] # = 0.3, 0.3, 0.3, 0.3
dzsnso: list[float] # = 0.0, 0.0, 0.0, 0.1, 0.3, 0.6, 1.0
sice: list[float] # = 0.0, 0.0, 0.0, 0.0
sh2o: list[float] # = 0.3, 0.3, 0.3, 0.3
zwt: float # = -2.0

class Config(core.Base.Config):
Expand Down

0 comments on commit 81f77c0

Please sign in to comment.