6.1.2.1. Karabo Bridge Python client¶
The karabo_bridge
Python package provides a client interface to receive
data from the Karabo bridge.
- class karabo_bridge.Client(endpoint, sock='REQ', ser='msgpack', timeout=None, context=None)¶
Karabo bridge client for Karabo pipeline data.
This class can request data to a Karabo bridge server. Create the client with:
from karabo_bridge import Client krb_client = Client("tcp://153.0.55.21:12345")
then call
data = krb_client.next()
to request next available data container.- Parameters
endpoint (str) – server socket you want to connect to (only support TCP socket).
sock (str, optional) – socket type - supported: REQ, SUB.
ser (str, DEPRECATED) – Serialization protocol to use to decode the incoming message (default is msgpack) - supported: msgpack.
context (zmq.Context) – To run the Client’s sockets using a provided ZeroMQ context.
timeout (int) –
Timeout on :method:`next` (in seconds)
Data transfered at the EuXFEL for Mega-pixels detectors can be very large. Setting a too small timeout might end in never getting data. Some example of transfer timing for 1Mpix detector (AGIPD, LPD):
32 pulses per train (125 MB): ~0.1 s 128 pulses per train (500 MB): ~0.4 s 350 pulses per train (1.37 GB): ~1 s
- Raises
NotImplementedError – if socket type or serialization algorythm is not supported.
ZMQError – if provided endpoint is not valid.
- next()¶
Request next data container.
This function call is blocking.
- Returns
data (dict) – The data for this train, keyed by source name.
meta (dict) – The metadata for this train, keyed by source name.
This dictionary is populated for protocol version 1.0 and 2.2. For other protocol versions, metadata information is available in data dict.
- Raises
TimeoutError – If timeout is reached before receiving data.
6.1.2.1.1. Data container¶
The data object returned by Client.next()
is a tuple of two nested
dictionaries, holding data and metadata respectively.
The first level of keys in both dictionaries are source names, which typically correspond to Karabo device names.
In the data dictionary, each source has a dictionary representing a flattened Karabo hash, with dots delimiting successive key levels. The values are either basic Python types such as strings and floats, or numpy arrays.
In the metadata dictionary, each source has a dictionary with keys: source
,
timestamp
, timestamp.tid
, timestamp.sec
, timestamp.frac
and ignored_keys
, which is a list of strings identifying keys which were
filtered out of the data by configuration options on the bridge server.
(
{ # Metadata
'SPB_DET_AGIPD1M-1/DET/0CH0:xtdf': {
'source': 'SPB_DET_AGIPD1M-1/DET/0CH0:xtdf',
'timestamp': 1526464869.4109755,
# Timestamps can have attosecond resolution: 18 fractional digits
'timestamp.frac': '410975500000000000',
'timestamp.sec': '1526464869',
'timestamp.tid': 10000000001,
'ignored_keys': []
},
},
{ # Data
'SPB_DET_AGIPD1M-1/DET/0CH0:xtdf': {
'image.data': array(...),
'header.pulseCount': 64,
# ... other keys
}
}
)