Skip to content

model_input_schemas

AbstractScenarioSchema

Bases: DataFrameModel

Base schema for scenario dataframe as used when creating a model.

Structure: - Index: datetime (time series) - Columns: - load_ (float): load in Amperes for each circuit (e.g., load_circuit1, load_circuit2, etc.) - ambient_temperature (float): ambient temperature in degrees Celsius

check_datetime_index classmethod

check_datetime_index(df: DataFrame)

Ensure index is datetime-like or timedelta-like.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
22
23
24
25
26
@pa.dataframe_check(error="Scenario index must be either datetime-like or timedelta-like..")
@classmethod
def check_datetime_index(cls, df: pd.DataFrame):
    """Ensure index is datetime-like or timedelta-like."""
    return pd.api.types.is_datetime64_any_dtype(df.index) or pd.api.types.is_timedelta64_dtype(df.index)

check_required_columns classmethod

check_required_columns(df: DataFrame)

Ensure shared required columns are present.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
28
29
30
31
32
33
34
35
36
37
38
@pa.dataframe_check(error="Scenario columns must include load_<circuit_name> and ambient_temperature.")
@classmethod
def check_required_columns(cls, df: pd.DataFrame):
    """Ensure shared required columns are present."""
    req_columns = {"ambient_temperature"}
    load_columns = [col for col in df.columns if col.startswith("load_")]
    if not all(col in df.columns for col in req_columns) or len(load_columns) == 0:
        raise ValueError(
            f"Scenario dataframe must include columns: {req_columns} and at least one load_<circuit_name> column."
        )
    return True

check_load_columns classmethod

check_load_columns(df: DataFrame)

Ensure load columns are in the correct format and contain numeric values.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
40
41
42
43
44
45
46
47
48
@pa.dataframe_check(error="Load columns must be in the format load_<circuit_name> and contain numeric values.")
@classmethod
def check_load_columns(cls, df: pd.DataFrame):
    """Ensure load columns are in the correct format and contain numeric values."""
    load_columns = [col for col in df.columns if col.startswith("load_")]
    for col in load_columns:
        if not pd.api.types.is_numeric_dtype(df[col]):
            raise ValueError(f"Load column {col} must contain numeric values.")
    return True

check_numeric_columns classmethod

check_numeric_columns(df: DataFrame)

Ensure ambient temperature column contains numeric values.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
50
51
52
53
54
55
56
57
58
@pa.dataframe_check(error="Ambient temperature must contain numeric values.")
@classmethod
def check_numeric_columns(cls, df: pd.DataFrame):
    """Ensure ambient temperature column contains numeric values."""
    numeric_columns = ["ambient_temperature"]
    for col in numeric_columns:
        if not pd.api.types.is_numeric_dtype(df[col]):
            raise ValueError(f"Column {col} must contain numeric values.")
    return True

check_no_missing_values classmethod

check_no_missing_values(df: DataFrame)

Ensure there are no missing values in the scenario dataframe.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
60
61
62
63
64
65
66
@pa.dataframe_check(error="Scenario dataframe must not contain missing values.")
@classmethod
def check_no_missing_values(cls, df: pd.DataFrame):
    """Ensure there are no missing values in the scenario dataframe."""
    if any(df.isna().sum()):
        raise ValueError("Scenario contains nan values.")
    return True

ScenarioSchemaAir

Bases: AbstractScenarioSchema

Air scenario schema extending the base scenario schema.

This schema currently does not add extra checks beyond AbstractScenarioSchema, but exists to allow air-specific evolution in the future.

ScenarioSchemaSoil

Bases: AbstractScenarioSchema

Soil scenario schema extending the base scenario with required soil properties.

check_required_soil_columns classmethod

check_required_soil_columns(df: DataFrame)

Ensure soil-specific required columns are present.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
80
81
82
83
84
85
86
87
@pa.dataframe_check(error="Scenario columns must include soil_thermal_resistivity and soil_thermal_capacity.")
@classmethod
def check_required_soil_columns(cls, df: pd.DataFrame):
    """Ensure soil-specific required columns are present."""
    req_columns = {"soil_thermal_resistivity", "soil_thermal_capacity"}
    if not all(col in df.columns for col in req_columns):
        raise ValueError(f"Scenario dataframe must include columns: {req_columns}.")
    return True

check_numeric_soil_columns classmethod

check_numeric_soil_columns(df: DataFrame)

Ensure soil thermal columns contain numeric values.

Source code in cable_thermal_model/model/schemas/model_input_schemas.py
89
90
91
92
93
94
95
96
97
@pa.dataframe_check(error="Soil thermal columns must contain numeric values.")
@classmethod
def check_numeric_soil_columns(cls, df: pd.DataFrame):
    """Ensure soil thermal columns contain numeric values."""
    numeric_columns = ["soil_thermal_resistivity", "soil_thermal_capacity"]
    for col in numeric_columns:
        if not pd.api.types.is_numeric_dtype(df[col]):
            raise ValueError(f"Column {col} must contain numeric values.")
    return True