Skip to content

model_output_schemas

TemperatureResultSchema

Bases: DataFrameModel

Schema for temperature result DataFrame with MultiIndex columns.

Structure: - Index: datetime (time series) - Columns: MultiIndex with 3 levels: - Level 0: circuit_name (str) - Level 1: cable_position (CablePosition enum values) - Level 2: cable_layer (CableLayer enum values) - Values: temperature in degrees Celsius (float)

check_datetime_index classmethod

check_datetime_index(df: DataFrame)

Ensure index is datetime-like.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
30
31
32
33
34
@pa.dataframe_check(error="Temperature result index must be datetime-like.")
@classmethod
def check_datetime_index(cls, df: pd.DataFrame):
    """Ensure index is datetime-like."""
    return pd.api.types.is_datetime64_any_dtype(df.index) or pd.api.types.is_timedelta64_dtype(df.index)

check_multiindex_columns classmethod

check_multiindex_columns(df: DataFrame)

Ensure columns are a MultiIndex with 3 levels.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
36
37
38
39
40
41
42
43
@pa.dataframe_check(
    error="Temperature result columns must be a 3-level MultiIndex: (circuit_name, cable_position, cable_layer)."
)
@classmethod
def check_multiindex_columns(cls, df: pd.DataFrame):
    """Ensure columns are a MultiIndex with 3 levels."""
    expected_nlevels = 3
    return isinstance(df.columns, pd.MultiIndex) and df.columns.nlevels == expected_nlevels

check_circuit_names classmethod

check_circuit_names(df: DataFrame) -> bool

Ensure circuit names are non-empty strings.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
46
47
48
49
50
51
52
53
54
@pa.dataframe_check
@classmethod
def check_circuit_names(cls, df: pd.DataFrame) -> bool:
    """Ensure circuit names are non-empty strings."""
    circuit_names = df.columns.get_level_values(0).unique()
    for name in circuit_names:
        if not isinstance(name, str) or len(name) == 0:
            raise ValueError(f"Circuit name '{name}' is not a valid non-empty string.")
    return True

check_cable_positions classmethod

check_cable_positions(df: DataFrame) -> bool

Ensure cable positions are valid CablePosition enum values.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
57
58
59
60
61
62
@pa.dataframe_check
@classmethod
def check_cable_positions(cls, df: pd.DataFrame) -> bool:
    """Ensure cable positions are valid CablePosition enum values."""
    positions = df.columns.get_level_values(1).unique()
    return bool([CablePosition(pos) for pos in positions])

check_cable_layers classmethod

check_cable_layers(df: DataFrame) -> bool

Ensure cable layers are valid CableLayer enum values.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
65
66
67
68
69
70
@pa.dataframe_check
@classmethod
def check_cable_layers(cls, df: pd.DataFrame) -> bool:
    """Ensure cable layers are valid CableLayer enum values."""
    layers = df.columns.get_level_values(2).unique()
    return bool([CableLayer(layer) for layer in layers])

check_temperature_values classmethod

check_temperature_values(df: DataFrame) -> bool

Ensure temperature values are floats.

Source code in cable_thermal_model/model/schemas/model_output_schemas.py
73
74
75
76
77
78
79
80
@pa.dataframe_check
@classmethod
def check_temperature_values(cls, df: pd.DataFrame) -> bool:
    """Ensure temperature values are floats."""
    for dtype in df.dtypes:
        if not pd.api.types.is_float_dtype(dtype):
            raise ValueError("All temperature values must be of float type.")
    return True

ModelOutputSchema

Bases: BaseModel, Generic[StateT]

Schema for the output of the thermal cable model, containing the temperature results and the final state.