roverd.channels
¶
Channel types.
Info
The core API is implemented and documented by the base type
Channel
.
Available Types¶
The following channel types are provided:
Name | Class | Description |
---|---|---|
raw |
RawChannel |
Little-endian raw byte array |
lzma |
LzmaChannel |
LZMA-compressed raw data |
lzmaf |
LzmaFrameChannel |
LZMA, but each frame is compressed independently |
mjpg |
VideoChannel |
MJPEG video |
npz |
NPZBlobChannel |
Sequence of .npz files, one per blob |
jpg |
JPEGBlobChannel |
Sequence of .jpg files, one per blob |
Configuration¶
Channels are conventionally specified by a configuration dict with the following fields:
format
: channel data format.type
: data type, using numpy size-in-bytes convention (e.g. u2 for 2-byte/16-bit unsigned integer)shape
: shape of the non-time dimensions.desc
: description of the channel; should be human-readable, and is not intended for use by scripts.
Use from_config
to create channel from a provided configuration.
Sample Configuration
roverd.channels.JPEGBlobChannel
¶
Bases: BlobChannel
Blob channel consisting of .jpg
files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
workers
|
int
|
maximum number of worker threads to use for I/O. |
8
|
length
|
int | None
|
number of blobs, potentially calculated some more efficient
way. If |
None
|
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/blob.py
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]],
thread: bool = False,
append: bool = False,
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume. |
required |
thread
|
bool
|
whether to return immediately, and run in a separate thread instead of returning immediately. |
False
|
append
|
bool
|
whether to append or overwrite existing blobs. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/abstract.py
read
¶
Read data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, ...]
|
Read frames as an array, with a leading axis corresponding to
the number of |
Source code in format/src/roverd/channels/abstract.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[Shaped[ndarray, ...]]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[Shaped[ndarray, ...]]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/abstract.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write, with leading axis corresponding to the number of samples/frames. |
required |
append
|
bool
|
append is currently not implemented for blob channels. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/abstract.py
roverd.channels.LzmaChannel
¶
Bases: RawChannel
LZMA-compressed binary data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/lzma.py
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]], thread: bool = False
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume. |
required |
thread
|
bool
|
if |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/raw.py
read
¶
Read data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, ...]
|
Read frames as an array, with a leading axis corresponding to
the number of |
Source code in format/src/roverd/channels/lzma.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[Shaped[ndarray, ...]]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[Shaped[ndarray, ...]]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/raw.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write. |
required |
append
|
bool
|
only |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/lzma.py
roverd.channels.LzmaFrameChannel
¶
Bases: Channel
Frame-wise LZMA-compressed binary data.
Should have an additional file with the suffix _i
, e.g. mask
, mask_i
which contains the starting offsets for each frame as a u8 (8-byte
unsigned integer).
This file should have the offset for the next unwritten frame as well.
As an example, for a channel example
with compressed frame sizes
[2, 5, 3]
, example_i
should be:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/lzma.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 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 162 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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]],
thread: bool = False,
preset: int = 0,
batch: int = 8,
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume; possibly already batched (see |
required |
thread
|
bool
|
whether to return immediately, and run in a separate thread instead of returning immediately. |
False
|
preset
|
int
|
lzma compression preset to use. |
0
|
batch
|
int
|
aggregate, then batch this many lzma compressions in
parallel. Necessary for throughput reasons, since lzma
is only single (?) threaded. If |
8
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/lzma.py
read
¶
Read data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, 'samples ...']
|
Read frames as an array, with a leading axis corresponding to
the number of |
Raises:
Type | Description |
---|---|
ValueError
|
None of the frames could be read, possibly due to an invalid video, or invalid start index. |
Source code in format/src/roverd/channels/lzma.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[ndarray]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[ndarray]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/lzma.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write. |
required |
preset
|
int
|
LZMA compression preset (0-9, 0 is fastest, 9 is best). |
0
|
append
|
bool
|
only |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/lzma.py
roverd.channels.NPZBlobChannel
¶
Bases: BlobChannel
Blob channel consisting of .npz
files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
workers
|
int
|
maximum number of worker threads to use for I/O. |
8
|
length
|
int | None
|
number of blobs, potentially calculated some more efficient
way. If |
None
|
compress
|
bool
|
whether to use compression when writing |
False
|
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/blob.py
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]],
thread: bool = False,
append: bool = False,
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume. |
required |
thread
|
bool
|
whether to return immediately, and run in a separate thread instead of returning immediately. |
False
|
append
|
bool
|
whether to append or overwrite existing blobs. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/abstract.py
read
¶
Read data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, ...]
|
Read frames as an array, with a leading axis corresponding to
the number of |
Source code in format/src/roverd/channels/abstract.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[Shaped[ndarray, ...]]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[Shaped[ndarray, ...]]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/abstract.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write, with leading axis corresponding to the number of samples/frames. |
required |
append
|
bool
|
append is currently not implemented for blob channels. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/abstract.py
roverd.channels.RawChannel
¶
Bases: Channel
Raw (uncompressed) data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/raw.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]], thread: bool = False
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume. |
required |
thread
|
bool
|
if |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/raw.py
read
¶
Read data.
Info
We read through bytearray -> memoryview -> np.frombuffer
to
provide a read-write buffer without requiring an additional copy.
This is required for full functionality in downstream applications,
e.g. torch.from_numpy
.
Note that this is valid since the bytearray is not returned, so ownership is passed to the returned numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, ...]
|
Read frames as an array, with a leading axis corresponding to
the number of |
Source code in format/src/roverd/channels/raw.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[Shaped[ndarray, ...]]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[Shaped[ndarray, ...]]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/raw.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write. |
required |
append
|
bool
|
if |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/raw.py
roverd.channels.VideoChannel
¶
Bases: Channel
Video data.
Warning
While opencv is a heavy dependency, it seems to have very efficient
seeking for mjpeg compared to imageio
, the other library that I
tested. Using opencv-python-headless
instead of the default opencv
should alleviate some of these issues.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
file path. |
required |
dtype
|
str | type | dtype
|
data type, or string name of dtype (e.g. |
required |
shape
|
Sequence[int]
|
data shape. |
required |
Attributes:
Name | Type | Description |
---|---|---|
path |
str
|
file path. |
type |
dtype
|
numpy data type. |
shape |
tuple[int, ...]
|
sample data shape. |
size |
int
|
total file size, in bytes. |
Source code in format/src/roverd/channels/video.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
consume
¶
consume(
stream: Streamable[Data | Sequence[Data]],
thread: bool = False,
fps: float = 10.0,
) -> None
Consume iterable or queue and write to file.
- If
Iterable
, fetches from the iterator until exhausted (i.e. untilStopIteration
), then returns. - If
Queue
,.get()
from theQueue
untilNone
is received, then return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
Streamable[Data | Sequence[Data]]
|
stream to consume. |
required |
fps
|
float
|
video framerate. |
10.0
|
thread
|
bool
|
whether to return immediately, and run in a separate thread instead of returning immediately. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/video.py
read
¶
Read data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
int | integer
|
start index to read. |
0
|
samples
|
int | integer
|
number of samples/frames to read. If |
-1
|
Returns:
Type | Description |
---|---|
Shaped[ndarray, 'samples ...']
|
Read frames as an array, with a leading axis corresponding to
the number of |
Raises:
Type | Description |
---|---|
ValueError
|
None of the frames could be read, possibly due to an invalid video, or invalid start index. |
Source code in format/src/roverd/channels/video.py
stream
¶
stream(
transform: Callable[[Shaped[ndarray, ...]], Any] | None = None,
batch: int = 0,
) -> Iterator[ndarray]
Get iterable data stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Callable[[Shaped[ndarray, ...]], Any] | None
|
callable to apply to the read data. Should take a single sample or batch of samples, and can return an arbitrary type. |
None
|
batch
|
int
|
batch size to read. If 0, load only a single sample and do not append an empty axis. |
0
|
Returns:
Type | Description |
---|---|
Iterator[ndarray]
|
Iterator which yields successive frames. |
Source code in format/src/roverd/channels/video.py
write
¶
Write data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Data
|
data to write. |
required |
append
|
bool
|
if |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
data type/shape does not match channel specifications. |
Source code in format/src/roverd/channels/video.py
roverd.channels.from_config
¶
from_config(
path: str,
format: str,
type: str,
shape: Sequence[int],
description: str | None = None,
desc: str | None = None,
args: dict = {},
) -> Channel
Create channel from configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
File path to the channel data. |
required |
format
|
str
|
channel format name. |
required |
type
|
str
|
data type, using numpy size-in-bytes convention (e.g. u2 for 2-byte/16-bit unsigned integer). |
required |
shape
|
Sequence[int]
|
shape of the non-time dimensions. |
required |
args
|
dict
|
other arguments to pass to the channel constructor. |
{}
|
Returns:
Type | Description |
---|---|
Channel
|
Initialized channel object. |