mux
BlockMuxStream
BlockMuxStream(reader, start=None, timeout=0)
Bases: Generic[T]
A time-aware, gap-handling multiplexer for SeriesBlock streams.
Given SeriesBlocks from multiple named streams with monotonically increasing integer timestamps, this data structure can be used to pull out sets of synchronized blocks, all with the same timestamps. If data on the streams is not available before timeouts are reached, gap blocks will be returned.
The oldest items will be held until either all named streams are available or until the timeout has been reached. If a start time has been set, any items with an older timestamp will be rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
StreamReader object producing multiple stream to multiplex. |
required |
start_ns
|
int
|
GPS start time of stream, in nanoseconds. |
required |
timeout
|
int = 0
|
Overall timeout for the muxer, in nanoseconds. Overrides individual queue timeouts. If not specified the mux timeout will be the max of the individual queue timeouts. |
0
|
Source code in arrakis/mux.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
__getitem__
__getitem__(key)
Access an individual queue.
Source code in arrakis/mux.py
473 474 475 | |
pull
pull()
Pull synchronized, concatenated, combined blocks from all streams covering the overall specified stride.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
Iterable[Channel]
|
Channel list for creating gap blocks |
required |
Returns:
| Type | Description |
|---|---|
SeriesBlock
|
|
Source code in arrakis/mux.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
push
push(stream_name, block)
Push an element for time into a particular queue.
Source code in arrakis/mux.py
477 478 479 480 481 | |
ready
ready()
True if all queues have the expected number of elements
covering the overall muxer stride.
Source code in arrakis/mux.py
483 484 485 486 487 488 489 490 491 | |
MuxedData
dataclass
MuxedData(time, data)
Muxer
Muxer(keys, start=None, timeout=DEFAULT_TIMEOUT)
Bases: Generic[T]
A data structure that multiplexes items from multiple named streams.
Given items from multiple named streams with monotonically increasing integer timestamps, this data structure can be used to pull out sets of synchronized items (items all with the same timestamp).
The oldest items will be held until either all named streams are available or until the timeout has been reached. If a start time has been set, any items with an older timestamp will be rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Iterable[str]
|
Identifiers for the named streams to expect when adding items. |
required |
start
|
int
|
The GPS time to start muxing items for. If not set, accept items from any time. |
None
|
timeout
|
timedelta or None
|
The maximum time to wait for messages from named streams, in seconds, before multiplexing. If None is specified, wait indefinitely. Default is 1 second. |
DEFAULT_TIMEOUT
|
Source code in arrakis/mux.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
pull
pull()
Pull monotonically increasing synchronized items from the muxer.
Yields:
| Type | Description |
|---|---|
MuxedData[T]
|
Synchronized items with a common timestamp, keyed by stream keys. |
Source code in arrakis/mux.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
push
push(time, key, item, on_drop=ONDROP_DEFAULT)
Push an item into the muxer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int
|
The timestamp associated with this item. |
required |
key
|
str
|
The key stream associated with this item. Must match a key provided at initialization. |
required |
item
|
T
|
The item to add. |
required |
on_drop
|
str
|
Specifies behavior when the item would be dropped from the muxer, in the case that it was not provided to the muxer before the specified timeout. Options are 'ignore', 'raise', or 'warn'. Default is 'warn'. |
ONDROP_DEFAULT
|
Source code in arrakis/mux.py
117 118 119 120 121 122 123 124 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 155 156 157 158 159 160 161 | |
TimedQueue
TimedQueue(stride, timeout, start=None)
Bases: Generic[T]
A sequential, time-stamped queue handling gaps and timeouts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
GPS start time of queue, in nanoseconds. |
None
|
stride
|
int
|
Time step for elements in the queue, in nanoseconds. |
required |
timeout
|
int
|
Timeout for elements in the queue, in nanoseconds. |
required |
Source code in arrakis/mux.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
drain_until
drain_until(target_time)
Remove elements until the front element is at or after target_time.
Source code in arrakis/mux.py
402 403 404 405 406 | |
front_time
front_time()
Return the timestamp of the front element, or None if empty.
Source code in arrakis/mux.py
395 396 397 398 399 400 | |
pull
pull(duration=None)
Drain the queue.
Gaps are represented by None elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int
|
Duration to extract, in nanoseconds. If the specified duration is not available, no elements will be returned. If not specified, the queue will be drained. |
None
|
Yields:
| Type | Description |
|---|---|
tuple[time, element]
|
The element from the queue and it's associated timestamp. |
Source code in arrakis/mux.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
push
push(time, element, on_drop=ONDROP_DEFAULT)
Push an element into the queue.
The time being pushed into the queue must be a multiple of the time stride specified at initialization of the queue.
If the time associated with the pushed element is less than what has already been processed by the queue, the batch will be dropped and this operation will be a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int
|
GPS time associated with the element, in nanoseconds |
required |
element
|
Any
|
element being pushed into the queue. |
required |
on_drop
|
str
|
Specifies behavior when the item would be dropped from the muxer, in the case that it was not provided to the muxer before the specified timeout. Options are 'ignore', 'raise', or 'warn'. Default is 'warn'. |
ONDROP_DEFAULT
|
Source code in arrakis/mux.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
ready
ready(duration)
Check if queue holds duration worth of elements
Returns:
| Type | Description |
|---|---|
int or None
|
Returns either the number of elements that span duration, or None if the queue does not have duration worth of elements, |
Source code in arrakis/mux.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |