Skip to content

cable_builder

Module responsible for building Cable objects based on given cable specifications.

CableBuilder

Utility class responsible for constructing Cable objects based on various input specifications.

build_cable_from_cable_id classmethod

build_cable_from_cable_id(cable_id: str, cable_class: type[CableT], grid_points_per_layer: int = 10, pipe: PipeInputSchema | None = None, cable_source_file_path: Path = __PROJECT_ROOT / 'data' / 'example_cables.csv') -> CableT

Builds a new Cable instance based on a cable_id.

Parameters:

Name Type Description Default
cable_id str

The name of a cable mentioned in the file specified by cable_source_file_path.

required
grid_points_per_layer int

The number of points per cable layer.

10
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None
cable_class type[Cable]

The Cable class to instantiate.

required
cable_source_file_path Path

The path to the cable source file. Defaults to "data/example_cables.csv". The file can be either a CSV or an Excel file.

__PROJECT_ROOT / 'data' / 'example_cables.csv'

Returns:

Name Type Description
TCable CableT

A new Cable instance (based on a Cable instance).

Source code in cable_thermal_model/cable/cable_builder.py
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
@classmethod
def build_cable_from_cable_id(
    cls,
    cable_id: str,
    cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
    cable_source_file_path: Path = __PROJECT_ROOT / "data" / "example_cables.csv",
) -> CableT:
    """Builds a new Cable instance based on a cable_id.

    Args:
        cable_id (str): The name of a cable mentioned in the file specified by `cable_source_file_path`.
        grid_points_per_layer (int): The number of points per cable layer.
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.
        cable_class (type[Cable]): The Cable class to instantiate.
        cable_source_file_path (Path): The path to the cable source file.
            Defaults to "data/example_cables.csv". The file can be either
            a CSV or an Excel file.

    Returns:
            TCable: A new Cable instance (based on a Cable instance).

    """
    if issubclass(cable_class, CableTrefoilCircuitSinglePipe) and pipe is None:
        raise ValueError(f"When using Cable class '{cable_class.__name__}', a pipe must be provided.")

    # load the cable data from the specified file
    cable_specs = cls._load_cable_data_from_file(cable_source_file_path, cable_id)

    # build the cable based on the loaded data
    return cls.build_cable_from_cable_specs(
        cable_specs=cable_specs,
        cable_class=cable_class,
        grid_points_per_layer=grid_points_per_layer,
        pipe=pipe,
    )

build_cable_from_cable_specs classmethod

build_cable_from_cable_specs(cable_specs: Series, cable_class: type[CableT], grid_points_per_layer: int = 10, pipe: PipeInputSchema | None = None) -> CableT

Builds a new Cable instance based on a given set of cable specifications.

Parameters:

Name Type Description Default
cable_specs Series

A Pandas Series holding the cable specification.

required
grid_points_per_layer int

The number of points per layer to use in FD grids

10
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None
cable_class type[Cable]

The Cable class to instantiate.

required

Returns:

Name Type Description
TCable CableT

A new Cable instance (based on a Cable instance).

Source code in cable_thermal_model/cable/cable_builder.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@classmethod
def build_cable_from_cable_specs(
    cls,
    cable_specs: pd.Series,
    cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT:
    """Builds a new Cable instance based on a given set of cable specifications.

    Args:
        cable_specs (pd.Series): A Pandas Series holding the cable specification.
        grid_points_per_layer (int): The number of points per layer to use in FD grids
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.
        cable_class (type[Cable]): The Cable class to instantiate.

    Returns:
            TCable: A new Cable instance (based on a Cable instance).

    """
    cable_spec_parser = SpecParserFactory.get_spec_parser(cable_specs)
    cable_constructional_input: CableConstructionalInputSchema = cable_spec_parser.get_cable_constructional_input()

    # build the cable based on the parsed specifications
    return cls.build_cable(
        cable_constructional_input=cable_constructional_input,
        cable_class=cable_class,
        grid_points_per_layer=grid_points_per_layer,
        pipe=pipe,
    )

build_cable classmethod

build_cable(cable_constructional_input: CableConstructionalInputSchema, cable_class: type[CableT], grid_points_per_layer: int = 10, pipe: PipeInputSchema | None = None) -> CableT

Build FD cable object.

Parameters:

Name Type Description Default
cable_constructional_input CableConstructionalInputSchema

A CableConstructionalInputSchema object holding the cable specification.

required
grid_points_per_layer int

The number of points per layer to use in FD grids

10
cable_class type[Cable]

The Cable class to instantiate.

required
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None

Returns:

Name Type Description
CableT CableT

A finite-difference cable object.

Source code in cable_thermal_model/cable/cable_builder.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
@classmethod
def build_cable(
    cls,
    cable_constructional_input: CableConstructionalInputSchema,
    cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT:
    """Build FD cable object.

    Args:
        cable_constructional_input (CableConstructionalInputSchema):
            A CableConstructionalInputSchema object holding the cable
            specification.
        grid_points_per_layer (int): The number of points per layer to use in FD grids
        cable_class (type[Cable]): The Cable class to instantiate.
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.

    Returns:
        CableT: A finite-difference cable object.

    """
    # retrieve the cable's conductor properties
    cable_conductor_properties: CableConductorProperties = cls._get_cable_conductor_properties(
        cable_constructional_input
    )

    # retrieve the cable's layer properties
    cable_layer_properties_by_layer: dict[CableLayer, CableLayerProperties] = cls._get_cable_layer_properties(
        cable_constructional_input
    )

    # retrieve the cable's layer metrics
    cable_layer_metrics: CableLayerMetrics = cls._get_cable_layer_metrics(cable_constructional_input)

    # instantiate the cable
    cable = cable_class(
        conductor=cable_conductor_properties,
        layer_properties=cable_layer_properties_by_layer,
        layer_metrics=cable_layer_metrics,
        cable_type=cable_constructional_input.cable_type,
        grid_counts=dict.fromkeys(cable_layer_properties_by_layer.keys(), grid_points_per_layer),
    )

    # generate a warning if the cable type is of an abstract type
    # (with abstract method "integrate_timestep" not implemented)
    require_implemented_cable(cable, hard_stop=False)

    # add a pipe around the cable if specified
    if pipe is not None:
        cable = cable.get_cable_copy_with_pipe(
            Pipe(
                pipe_input=pipe,
                outer_radius_cable=cable.layer_metrics.cable_radius,
            )
        )

    return cable