Skip to content

util

convert_to_interface(information_objects)

Convert a list of information objects to interface objects.

Takes a list of SensorInformation, ActuatorInformation or RewardInformation from the palaestrAI ecosystem and converts them to a list of interface objects.

Source code in src/flowcean/palaestrai/util.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def convert_to_interface(
    information_objects: list[SensorInformation]
    | list[ActuatorInformation]
    | list[RewardInformation],
) -> list[Interface]:
    """Convert a list of information objects to interface objects.

    Takes a list of SensorInformation, ActuatorInformation or
    RewardInformation from the palaestrAI ecosystem and converts them
    to a list of interface objects.
    """
    interfaces = []
    for obj in information_objects:
        space = obj.space
        if isinstance(space, Box):
            interfaces.append(
                Interface(
                    uid=obj.uid if isinstance(obj.uid, str) else "",
                    value=obj.value,
                    value_min=space.low,
                    value_max=space.high,
                    shape=space.shape,
                    dtype=space.dtype
                    if space.dtype
                    in (type[np.floating[Any]], type[np.integer[Any]])
                    else np.float64,
                ),
            )

    return interfaces