Skip to content

Dike

Dike models for the Dikes for Dummies package

Classes representing the real domain of a Dike and its characteristics. Constructors are also defined in this module.

Dike Profile

DikeProfile

Bases: DikeProfileProtocol

Source code in dikesfordummies/dike/dike_profile.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class DikeProfile(DikeProfileProtocol):

    characteristic_points: List[Point]

    def __init__(self) -> None:
        self.characteristic_points = []

    @property
    def height(self) -> float:
        """
        The greatest `y coordinate` in the `characteristic_points` (`List[Point]`).

        Returns:
            float: Highest y coordinate of the dike.
        """
        if not self.characteristic_points:
            return math.nan
        return max([p.y for p in self.characteristic_points])

    @property
    def width(self) -> float:
        """
        The greatest `x coordinate` in the `characteristic_points` (`List[Point]`).

        Returns:
            float: Highest x coordinate of the dike.
        """
        if not self.characteristic_points:
            return math.nan
        return self.characteristic_points[-1].x

    @classmethod
    def from_tuple_list(cls, tuple_list: List[Tuple[float, float]]) -> DikeProfile:
        """
        Initializes a `DikeProfile` with the given `tuple_list` mapped into a `List[Point]` representing the `characteristic_points` property.

        Args:
            tuple_list (List[Tuple[float, float]]): List of float tuples representing the characteristic points.

        Raises:
            ValueError: When no `tuple_list` is given.

        Returns:
            DikeProfile: Instance with valid `characteristic points`.
        """
        if not tuple_list:
            raise ValueError("tuple_list argument required.")
        _dike = cls()
        _dike.characteristic_points = list(map(Point, tuple_list))
        return _dike

from_tuple_list(tuple_list: List[Tuple[float, float]]) -> DikeProfile classmethod

Initializes a DikeProfile with the given tuple_list mapped into a List[Point] representing the characteristic_points property.

Parameters:

Name Type Description Default
tuple_list List[Tuple[float, float]]

List of float tuples representing the characteristic points.

required

Raises:

Type Description
ValueError

When no tuple_list is given.

Returns:

Name Type Description
DikeProfile DikeProfile

Instance with valid characteristic points.

Source code in dikesfordummies/dike/dike_profile.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@classmethod
def from_tuple_list(cls, tuple_list: List[Tuple[float, float]]) -> DikeProfile:
    """
    Initializes a `DikeProfile` with the given `tuple_list` mapped into a `List[Point]` representing the `characteristic_points` property.

    Args:
        tuple_list (List[Tuple[float, float]]): List of float tuples representing the characteristic points.

    Raises:
        ValueError: When no `tuple_list` is given.

    Returns:
        DikeProfile: Instance with valid `characteristic points`.
    """
    if not tuple_list:
        raise ValueError("tuple_list argument required.")
    _dike = cls()
    _dike.characteristic_points = list(map(Point, tuple_list))
    return _dike

height() -> float property

The greatest y coordinate in the characteristic_points (List[Point]).

Returns:

Name Type Description
float float

Highest y coordinate of the dike.

Source code in dikesfordummies/dike/dike_profile.py
18
19
20
21
22
23
24
25
26
27
28
@property
def height(self) -> float:
    """
    The greatest `y coordinate` in the `characteristic_points` (`List[Point]`).

    Returns:
        float: Highest y coordinate of the dike.
    """
    if not self.characteristic_points:
        return math.nan
    return max([p.y for p in self.characteristic_points])

width() -> float property

The greatest x coordinate in the characteristic_points (List[Point]).

Returns:

Name Type Description
float float

Highest x coordinate of the dike.

Source code in dikesfordummies/dike/dike_profile.py
30
31
32
33
34
35
36
37
38
39
40
@property
def width(self) -> float:
    """
    The greatest `x coordinate` in the `characteristic_points` (`List[Point]`).

    Returns:
        float: Highest x coordinate of the dike.
    """
    if not self.characteristic_points:
        return math.nan
    return self.characteristic_points[-1].x

Dike Profile Builder

DikeProfileBuilder

Class responsible of building a valid concrete DikeProfileProtocol with a given DikeInput.

Raises:

Type Description
ValueError

When trying to build without a valid DikeInput.

Source code in dikesfordummies/dike/dike_profile_builder.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class DikeProfileBuilder:
    """
    Class responsible of building a valid concrete `DikeProfileProtocol` with a given `DikeInput`.

    Raises:
        ValueError: When trying to `build` without a valid `DikeInput`.
    """

    dike_input: DikeInput
    dike_type: Type[DikeProfileProtocol]

    def __init__(self) -> None:
        self.dike_input = None
        self.dike_type = None

    def _build_waterside(self) -> List[Point]:
        _p4 = Point(0, self.dike_input.kruin_hoogte)
        _p3_x = _p4.x - (
            (self.dike_input.kruin_hoogte - self.dike_input.buiten_berm_hoogte)
            * self.dike_input.buiten_talud
        )
        _p3 = Point(_p3_x, self.dike_input.buiten_berm_hoogte)
        _p2_x = _p3.x - self.dike_input.buiten_berm_breedte
        _p2 = Point(_p2_x, self.dike_input.buiten_berm_hoogte)
        _p1_x = _p2.x - (
            (self.dike_input.buiten_berm_hoogte - self.dike_input.buiten_maaiveld)
            * self.dike_input.buiten_talud
        )
        _p1 = Point(_p1_x, self.dike_input.buiten_maaiveld)
        return [_p1, _p2, _p3, _p4]

    def _build_polderside(self) -> List[Point]:
        _x_p5 = self.dike_input.kruin_breedte
        _p5 = Point(_x_p5, self.dike_input.kruin_hoogte)
        _x_p6 = _p5.x + (
            (self.dike_input.kruin_hoogte - self.dike_input.binnen_berm_hoogte)
            * self.dike_input.binnen_talud
        )
        _p6 = Point(_x_p6, self.dike_input.binnen_berm_hoogte)
        _x_p7 = _p6.x + self.dike_input.binnen_berm_breedte
        _p7 = Point(_x_p7, self.dike_input.binnen_berm_hoogte)
        _x_p8 = _p7.x + (
            (self.dike_input.binnen_berm_hoogte - self.dike_input.binnen_maaiveld)
            * self.dike_input.binnen_talud
        )
        _p8 = Point(_x_p8, self.dike_input.binnen_maaiveld)
        return [_p5, _p6, _p7, _p8]

    def build(self) -> DikeProfileProtocol:
        """
        Builds a `DikeProfileProtocol` based on the given `DikeInput` and concrete type of `DikeProfileProtocol`

        Raises:
            ValueError: When the `dike_input` or `dike_type` are not provided.

        Returns:
            DikeProfileProtocol: Valid concrete instanced of DikeProfileProtocol.
        """
        if not self.dike_input:
            raise ValueError("Input Profile should be provided.")
        if not self.dike_type:
            raise ValueError(
                f"Dike type from {DikeProfileProtocol} should be provided."
            )

        _dike_points: List[Point] = []
        _waterside = self._build_waterside()
        _polderside = self._build_polderside()
        _dike_points.extend(_waterside)
        _dike_points.extend(_polderside)
        _dike = self.dike_type()
        _dike.characteristic_points = _dike_points
        return _dike

    @classmethod
    def from_input(
        cls,
        dike_input: DikeInput,
        dike_type: Optional[Type[DikeProfileProtocol]] = DikeProfile,
    ) -> DikeProfileBuilder:
        """
        Initializes a `DikeProfileBuilder' with a valid `DikeInput` as `dike_input` parameter and a concrete type of `DikeProfileProtocol` as `dike_type`.

        Args:
            dike_input (DikeInput): Dike input to be set to the instance of the builder.
            dike_type (Optional[Type[DikeProfileProtocol]], optional): _description_. Defaults to DikeProfile.

        Returns:
            DikeProfileBuilder: Valid instance of a DikeProfileBuilder instance.
        """
        _builder = cls()
        _builder.dike_input = dike_input
        _builder.dike_type = dike_type
        return _builder

build() -> DikeProfileProtocol

Builds a DikeProfileProtocol based on the given DikeInput and concrete type of DikeProfileProtocol

Raises:

Type Description
ValueError

When the dike_input or dike_type are not provided.

Returns:

Name Type Description
DikeProfileProtocol DikeProfileProtocol

Valid concrete instanced of DikeProfileProtocol.

Source code in dikesfordummies/dike/dike_profile_builder.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def build(self) -> DikeProfileProtocol:
    """
    Builds a `DikeProfileProtocol` based on the given `DikeInput` and concrete type of `DikeProfileProtocol`

    Raises:
        ValueError: When the `dike_input` or `dike_type` are not provided.

    Returns:
        DikeProfileProtocol: Valid concrete instanced of DikeProfileProtocol.
    """
    if not self.dike_input:
        raise ValueError("Input Profile should be provided.")
    if not self.dike_type:
        raise ValueError(
            f"Dike type from {DikeProfileProtocol} should be provided."
        )

    _dike_points: List[Point] = []
    _waterside = self._build_waterside()
    _polderside = self._build_polderside()
    _dike_points.extend(_waterside)
    _dike_points.extend(_polderside)
    _dike = self.dike_type()
    _dike.characteristic_points = _dike_points
    return _dike

from_input(dike_input: DikeInput, dike_type: Optional[Type[DikeProfileProtocol]] = DikeProfile) -> DikeProfileBuilder classmethod

Initializes a DikeProfileBuilder' with a validDikeInputasdike_inputparameter and a concrete type ofDikeProfileProtocolasdike_type`.

Parameters:

Name Type Description Default
dike_input DikeInput

Dike input to be set to the instance of the builder.

required
dike_type Optional[Type[DikeProfileProtocol]]

description. Defaults to DikeProfile.

DikeProfile

Returns:

Name Type Description
DikeProfileBuilder DikeProfileBuilder

Valid instance of a DikeProfileBuilder instance.

Source code in dikesfordummies/dike/dike_profile_builder.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def from_input(
    cls,
    dike_input: DikeInput,
    dike_type: Optional[Type[DikeProfileProtocol]] = DikeProfile,
) -> DikeProfileBuilder:
    """
    Initializes a `DikeProfileBuilder' with a valid `DikeInput` as `dike_input` parameter and a concrete type of `DikeProfileProtocol` as `dike_type`.

    Args:
        dike_input (DikeInput): Dike input to be set to the instance of the builder.
        dike_type (Optional[Type[DikeProfileProtocol]], optional): _description_. Defaults to DikeProfile.

    Returns:
        DikeProfileBuilder: Valid instance of a DikeProfileBuilder instance.
    """
    _builder = cls()
    _builder.dike_input = dike_input
    _builder.dike_type = dike_type
    return _builder

Dike Input

DikeInput

Data structure containing the necessary data to generate Characteristic Points.

Source code in dikesfordummies/dike/dike_input.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class DikeInput:
    """
    Data structure containing the necessary data to generate Characteristic Points.
    """

    def __init__(self) -> None:
        self.buiten_maaiveld = math.nan
        self.buiten_talud = math.nan
        self.buiten_berm_hoogte = math.nan
        self.buiten_berm_breedte = math.nan
        self.kruin_hoogte = math.nan
        self.kruin_breedte = math.nan
        self.binnen_talud = math.nan
        self.binnen_berm_hoogte = math.nan
        self.binnen_berm_breedte = math.nan
        self.binnen_maaiveld = math.nan

    @classmethod
    def from_list(cls, values: List[float]) -> DikeInput:
        """
        Initializes a `DikeInput` with the given values mapped to the class' parameters.

        Args:
            values (List[float]): Values representing a Dike's profile data.

        Raises:
            ValueError: When the values given do not match the amount expected.

        Returns:
            DikeInput: Instanciated object with set data.
        """
        _input = cls()
        _dike_keys = _input.__dict__.keys()
        if not values or len(values) != len(_dike_keys):
            if not values:
                values = []
            raise ValueError(
                "Expected {} values, {} provided".format(len(_dike_keys), len(values))
            )

        for idx, key in enumerate(_dike_keys):
            _input.__dict__[key] = values[idx]
        return _input

from_list(values: List[float]) -> DikeInput classmethod

Initializes a DikeInput with the given values mapped to the class' parameters.

Parameters:

Name Type Description Default
values List[float]

Values representing a Dike's profile data.

required

Raises:

Type Description
ValueError

When the values given do not match the amount expected.

Returns:

Name Type Description
DikeInput DikeInput

Instanciated object with set data.

Source code in dikesfordummies/dike/dike_input.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@classmethod
def from_list(cls, values: List[float]) -> DikeInput:
    """
    Initializes a `DikeInput` with the given values mapped to the class' parameters.

    Args:
        values (List[float]): Values representing a Dike's profile data.

    Raises:
        ValueError: When the values given do not match the amount expected.

    Returns:
        DikeInput: Instanciated object with set data.
    """
    _input = cls()
    _dike_keys = _input.__dict__.keys()
    if not values or len(values) != len(_dike_keys):
        if not values:
            values = []
        raise ValueError(
            "Expected {} values, {} provided".format(len(_dike_keys), len(values))
        )

    for idx, key in enumerate(_dike_keys):
        _input.__dict__[key] = values[idx]
    return _input