Skip to content

Commit

Permalink
Move ForcingData and RealTime to .bc
Browse files Browse the repository at this point in the history
such that they can be reused later in structure
  • Loading branch information
arthurvd committed Jun 28, 2022
1 parent 5134129 commit 240def0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
24 changes: 23 additions & 1 deletion hydrolib/core/io/bc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
from enum import Enum
from pathlib import Path
from typing import Callable, List, Literal, NamedTuple, Optional, Set
from typing import Callable, List, Literal, NamedTuple, Optional, Set, Union

from pydantic import Extra
from pydantic.class_validators import root_validator, validator
Expand Down Expand Up @@ -295,3 +295,25 @@ def _serialize(self, _: dict) -> None:
# We skip the passed dict for a better one.
config = SerializerConfig(section_indent=0, property_indent=4)
write_ini(self._resolved_filepath, self._to_document(), config=config)


class RealTime(str, Enum):
"""
Enum class containing the valid value for the "realtime" reserved
keyword for real-time controlled forcing data, e.g., for hydraulic
structures.
This class is used inside the ForcingData Union, to force detection
of the realtime keyword, prior to considering it a filename.
"""

realtime = "realtime"
"""str: Realtime data source, externally provided"""


ForcingData = Union[float, RealTime, ForcingModel]
"""Data type that selects from three different types of forcing data:
* a scalar float constant
* "realtime" keyword, indicating externally controlled.
* A ForcingModel coming from a .bc file.
"""
19 changes: 2 additions & 17 deletions hydrolib/core/io/ext/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from enum import Enum
from pathlib import Path
from typing import Dict, List, Literal, Optional, Union
from typing import Dict, List, Literal, Optional

from pydantic import Field, root_validator, validator

from hydrolib.core.io.bc.models import ForcingBase, ForcingModel
from hydrolib.core.io.bc.models import ForcingBase, ForcingData, ForcingModel
from hydrolib.core.io.ini.models import INIBasedModel, INIGeneral, INIModel
from hydrolib.core.io.ini.serializer import SerializerConfig, write_ini
from hydrolib.core.io.ini.util import (
Expand All @@ -15,20 +14,6 @@
from hydrolib.core.utils import str_is_empty_or_none


# TODO: to be moved into hydrolib.core.io.common, once PR #236 has been closed.
class RealTime(str, Enum):
realtime = "realtime"
"""str: Realtime data source, externally provided"""


ForcingData = Union[float, RealTime, ForcingModel]
"""Data type that selects from three different types of forcing data:
* a scalar float constant
* "realtime" keyword, indicating externally controlled.
* A ForcingModel coming from a .bc file.
"""


class Boundary(INIBasedModel):
"""
A `[Boundary]` block for use inside an external forcings file,
Expand Down
4 changes: 2 additions & 2 deletions tests/io/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pytest
from pydantic import ValidationError

from hydrolib.core.io.bc.models import Constant, ForcingModel
from hydrolib.core.io.ext.models import Boundary, ExtModel, Lateral, RealTime
from hydrolib.core.io.bc.models import Constant, ForcingModel, RealTime
from hydrolib.core.io.ext.models import Boundary, ExtModel, Lateral
from hydrolib.core.io.ini.models import INIBasedModel

from ..utils import test_data_dir
Expand Down

0 comments on commit 240def0

Please sign in to comment.