Skip to content

model_factory

ModelFactory

Factory class for creating model instances based on the environment.

create_model staticmethod

create_model(
    static_env: StaticEnvAir,
    scenario: DataFrame[ScenarioSchemaAir],
) -> ModelAir
create_model(
    static_env: StaticEnvSoil,
    scenario: DataFrame[ScenarioSchemaSoil],
) -> ModelSoil
create_model(
    static_env: StaticEnv,
    scenario: DataFrame[ScenarioSchemaAir]
    | DataFrame[ScenarioSchemaSoil],
) -> Model

Create a model instance based on the environment type.

Parameters:

Name Type Description Default
static_env StaticEnv

Static environment configuration for the model.

required
scenario DataFrame[ScenarioSchemaAir] | DataFrame[ScenarioSchemaSoil]

Scenario data used by the model.

required

Returns:

Name Type Description
Model Model

An instance of ModelAir or ModelSoil.

Raises:

Type Description
ValueError

If static_env is not a supported environment type.

Source code in cable_thermal_model/model/model_factory.py
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
@staticmethod
def create_model(
    static_env: StaticEnv,
    scenario: DataFrame[ScenarioSchemaAir] | DataFrame[ScenarioSchemaSoil],
) -> Model:
    """Create a model instance based on the environment type.

    Args:
        static_env (StaticEnv): Static environment configuration for the model.
        scenario (DataFrame[ScenarioSchemaAir] | DataFrame[ScenarioSchemaSoil]):
            Scenario data used by the model.

    Returns:
        Model: An instance of ModelAir or ModelSoil.

    Raises:
        ValueError: If static_env is not a supported environment type.
    """
    if isinstance(static_env, StaticEnvAir):
        return ModelAir(static_env=static_env, scenario=cast(DataFrame[ScenarioSchemaAir], scenario))
    elif isinstance(static_env, StaticEnvSoil):
        return ModelSoil(static_env=static_env, scenario=cast(DataFrame[ScenarioSchemaSoil], scenario))
    else:
        raise ValueError(
            f"Unsupported static environment type: {type(static_env).__name__}. "
            f"Expected {StaticEnvAir.__name__} or {StaticEnvSoil.__name__}."
        )