Adapters¶
Adapters connect deployed models to data sources and sinks.
The common Adapter interface is defined in flowcean.core.
See the adapter guide for the deployment workflow.
adapter
¶
Classes¶
DataFrameAdapter
¶
DataFrameAdapter(source: DataFrame, input_features: Iterable[str], result_path: str)
Bases: Adapter
Adapter wrapper for a DataFrame.
This class allows to use a DataFrame as an Adapter and an input source for a tool loop. The tool receives data from the source DataFrame row by row. The tool loops results are collected in a result DataFrame which is written to a CSV file at the end of the process.
opc
¶
Classes¶
OPCAdapter
¶
Bases: Adapter
Flowcean adapter for OPC (Open Platform Communications) protocol.
Initialize the OPC adapter.
Initializes a new OPC to Flowcean adapter instance. The adapter reads its configuration from a YAML file. The path to this file is provided in the config_path argument and the file has the following structure:
# Path to the OPC Server
server-url: "opc.tcp://127.0.0.1:4840"
# Specify the time window to record before the recording flag is set.
# This enables the capture and processing of data that triggers the
# recording flag.
pre_capture_window_length: 2
# Define Flowcean inputs which their respective feature name, the
# opc-id and the datatype of the feature.
# All inputs will be passed on to the Flowcean model when triggering an
# inference.
# Available data types are: float32, float64, int32, int64 and bool.
inputs:
- feature: "feature_a"
opc-id: "<OPC-ID String>"
type: "int32"
- feature: "feature_b"
opc-id: "<OPC-ID String>"
type: "float64"
- ...
# Define the outputs from the Flowcean Model to the OPC Server.
# All outputs need to be mapped to on OPC field for the adapter to work
# correctly. If certain outputs are not needed / used, those should be
# dropped using transforms. The available datatypes are the same as for
# the input features.
outputs:
- feature: "result_feature"
opc-id: "<OPC-ID String>"
type: "int32"
# Flags are special OPC fields, which are used to communicate between
# the adapter and the OPC server.
# The streaming flag is set by the OPC server to `True` when Flowcean
# should start to record data. Once set back to `False`, the data is
# forwarded to the model, an inference step is executed and the results
# are send back to the OPC server.
stream_flag: "<OPC-ID String>"
# The prediction flag is set to `True` by the adapter when it
# successfully sends data to the OPC server.
# This can be used on the OPC side to process the newly received data.
# The flag is *not* reset by the adapter, so it will remain `True`
# until the OPC server resets it.
prediction_flag: "<OPC-ID String>"
# The connection flag is set to `True` by the adapter when it
# successfully connects to the OPC server and set to `False` when it
# disconnects from the server.
# This can be used to monitor the connection status of the adapter from
# the OPC side.
connection_flag: "<OPC-ID String>"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to the YAML configuration file containing the OPC server URL and feature definitions. |
required |
pull_frequency
|
float
|
Frequency in Hz at which to poll the OPC server for new data. |
150.0
|
Attributes¶
pre_capture_window_length
instance-attribute
¶
streaming_flag_node
instance-attribute
¶
connection_flag_node
instance-attribute
¶
prediction_flag_node
instance-attribute
¶
Methods:¶
send_data
¶
Send data to the OPC server.
Send a polars DataFrame or LazyFrame to the OPC server. The data must contain all required output features, otherwise a ValueError is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | LazyFrame
|
Polars DataFrame or LazyFrame containing the data to send. |
required |