Skip to content

simet.parser.transform

simet.parser.transform

TransformParser

Factory that builds transform objects from config dicts.

Parses a plain mapping (e.g., from YAML/JSON) into a TransformSchema and delegates construction to :meth:TransformType.get_transform.

parse_transform staticmethod

parse_transform(transform_data)

Parse transform config and return a concrete transform instance.

Parameters:

Name Type Description Default
transform_data dict

Mapping that must match TransformSchema fields, e.g.: {"type": "InceptionTransform"}.

required

Returns:

Name Type Description
Transform Transform

An instance of the requested transform

Transform

(currently InceptionTransform).

Raises:

Type Description
TypeError

If required fields for TransformSchema are missing.

ValueError

If the "type" value is unknown.

Example

cfg = {"type": "InceptionTransform"} t = TransformParser.parse_transform(cfg) t.class.name 'InceptionTransform'

Source code in simet/parser/transform.py
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
@staticmethod
def parse_transform(transform_data: dict) -> Transform:
    """Parse transform config and return a concrete transform instance.

    Args:
        transform_data (dict):
            Mapping that must match `TransformSchema` fields, e.g.:
            `{"type": "InceptionTransform"}`.

    Returns:
        Transform: An instance of the requested transform
        (currently `InceptionTransform`).

    Raises:
        TypeError: If required fields for `TransformSchema` are missing.
        ValueError: If the `"type"` value is unknown.

    Example:
        >>> cfg = {"type": "InceptionTransform"}
        >>> t = TransformParser.parse_transform(cfg)
        >>> t.__class__.__name__
        'InceptionTransform'
    """
    transform_schema = TransformSchema(**transform_data)
    return TransformType.get_transform(transform_schema)

TransformType

Bases: StrEnum

Enum of supported transform identifiers (string-valued).

get_transform staticmethod

get_transform(transform_schema)

Construct a transform instance from a validated schema.

Parameters:

Name Type Description Default
transform_schema TransformSchema

Validated schema with a type name.

required

Returns:

Name Type Description
Transform Transform

Concrete transform instance.

Raises:

Type Description
ValueError

If transform_schema.type is not a recognized TransformType.

Notes
  • Extend the match with additional cases as new transforms are added.
Source code in simet/parser/transform.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@staticmethod
def get_transform(transform_schema: TransformSchema) -> Transform:
    """Construct a transform instance from a validated schema.

    Args:
        transform_schema (TransformSchema): Validated schema with a `type` name.

    Returns:
        Transform: Concrete transform instance.

    Raises:
        ValueError: If `transform_schema.type` is not a recognized `TransformType`.

    Notes:
        - Extend the `match` with additional cases as new transforms are added.
    """
    try:
        transform_type = TransformType(transform_schema.type)
        match transform_type:
            case TransformType.INCEPTION:
                return InceptionTransform()
    except ValueError as e:
        logger.error(f"Unknown transform type: {transform_schema.type}")
        raise ValueError(f"Unknown transform type: {transform_schema.type}") from e