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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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