Skip to content

Commit

Permalink
[SMS-228] construct runspec (#45)
Browse files Browse the repository at this point in the history
* tests: base oseomosys construction

* feat: improvement to base abstraction

* feat: add validation for time_defintion

* tests: for time_definition

* add test_otoole_roundtrip pytest

* [SMS-239] cleanup noqa test data (#36)

* fix: rm otoole sample data from tests

* feat: import utils by name

* fix: cleanup some DS store

* fix: import utils

* Refactor root_validator to model_validator (#37)

* tests: otoole_roundtrip

* feat: fitler pandas=3. dep warning

* tests: roundtrip otoole timedefn

* delint

* otoole_roundtrip as pytest

* fix: rename otoole-csv paths

* fix: make long_name and description optional

* tests: skip full otoole construction for now

* tests: test region construction

* feat: make base osemosys data built from args[0]

* fix: rm composable assumptions and targets for now

* fix: accidental rename

* fix: accident rename test case

* tests: commodity construction and compatability

* feat: begin refactor to /compat

* feat: add 'isnumeric' helper util

* refactor: defaults to initial import, don't import pydatnic schemas

* refactor: defaults and compat

* feat: commodity schema

* feat: make data construction more flexible

* feat: build and test impact construction

* tests: impact otoole roundtrip

* fix: some cleanup on commodity testing

* tests: touchup test-impact

* tests: technology construction

* feat: otoole compatability for technology

* feat: add to defaults

* feat: region and impact compat

* feat: validation for technology

* tests: runspec construction and roundtrip

* feat: add defaults for discount rate depreciation method

* feat: instantiate RunSpec on load model

* feat: add a depreciation_method enum

* feat: include reserve margin in commodity and technology defn

* feat: otoole compatability for RunSpec and Technology

* fix: return 'self' from model_validator(mode='after')

* feat: finish RunSpec model

* tests: roundtrip and yaml compatability

* fix: merge issues

---------

Co-authored-by: edwardxtg <edwardxtg@gmail.com>
Co-authored-by: edwardxtg <71764756+edwardxtg@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 29, 2024
1 parent 43637d8 commit 93f64c9
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 293 deletions.
3 changes: 3 additions & 0 deletions feo/osemosys/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Defaults(BaseSettings):
technology_storage_minimum_charge: float = Field(0.0)
technology_storage_initial_level: float = Field(0.0)
technology_storage_residual_capacity: float = Field(0.0)
depreciation_method: str = "straight-line"
discount_rate: float = Field(0.1)
reserve_margin: float = Field(1.0)


class DefaultsLinopy(BaseSettings):
Expand Down
3 changes: 3 additions & 0 deletions feo/osemosys/io/load_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml

from feo.osemosys import utils
from feo.osemosys.schemas import RunSpec


def load_model(*spec_files):
Expand Down Expand Up @@ -108,3 +109,5 @@ def load_model(*spec_files):

# eval strings
cfg = utils.walk_dict(cfg, utils.maybe_eval_string)

return RunSpec(**cfg)
17 changes: 17 additions & 0 deletions feo/osemosys/schemas/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Annotated, Dict, Mapping, Union

import numpy as np
Expand Down Expand Up @@ -178,3 +179,19 @@ class OSeMOSYSData_Bool(OSeMOSYSData):
Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, bool]]]],
Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, bool]]]]],
]


class DepreciationMethod(str, Enum):
sinking_fund = "sinking-fund"
straight_line = "straight-line"


class OSeMOSYSData_DepreciationMethod(OSeMOSYSData):
data: Union[
DepreciationMethod,
Dict[IdxVar, DepreciationMethod],
Dict[IdxVar, Dict[IdxVar, DepreciationMethod]],
Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, DepreciationMethod]]],
Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, DepreciationMethod]]]],
Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, Dict[IdxVar, DepreciationMethod]]]]],
]
10 changes: 5 additions & 5 deletions feo/osemosys/schemas/commodity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Commodity(OSeMOSYSBase, OtooleCommodity):
demand_profile: OSeMOSYSData_SumOne | None = Field(None)
is_renewable: OSeMOSYSData_Bool | None = Field(None)

# include this technology in joint reserve margin and renewables targets
include_in_joint_reserve_margin: OSeMOSYSData_Bool | None = Field(None)
include_in_joint_renewable_target: OSeMOSYSData_Bool | None = Field(None)

@field_validator("demand_annual", mode="before")
@classmethod
def passthrough_float(cls, v: Any) -> OSeMOSYSData:
Expand All @@ -47,9 +51,5 @@ def passthrough_bool(cls, v: Any) -> OSeMOSYSData_Bool:
@classmethod
def check_demand_exists_if_profile(cls, values):
if values.get("demand_profile") is not None and values.get("demand_annual") is None:
commodity = values.get("id")
raise ValueError(
f"If demand_profile is defined for commodity '{commodity}', "
f"demand_annual must also be defined."
)
raise ValueError("If demand_profile is defined, demand_annual must also be defined.")
return values
Loading

0 comments on commit 93f64c9

Please sign in to comment.