iqz
¶
A simple lossless compression codec for I/Q radar data.
Each chunk of n chirps (int16, any per-chirp shape) is encoded by
subtracting the chunk's rounded mean chirp, zigzag-encoding and
byte-shuffling the residuals, and compressing with zstd; see the
format specification for details.
- Functional API:
encode,decode,decode_into,info. - Streaming API:
EncoderandDecoder, which re-chunk chirps pushed or read in batches of any size.
Two implementations are provided, and can be selected with the backend
argument of each function or class: native (Rust) and numpy. Both
produce and accept identical blobs.
iqz.Decoder
¶
Streaming decoder, which re-chunks decoded chirps into any size.
Push blobs with push, each containing any number of chirps, and
read chirps back out with read or read_into in batches of
any size, regardless of where the chunk boundaries fall.
decoder = iqz.Decoder(shape=(3, 4, 1024))
out = np.empty((16, 3, 4, 1024), dtype=np.int16)
for blob in blobs:
decoder.push(blob)
while decoder.available >= 16:
decoder.read_into(out) # reuses `out`; no allocation
Blobs are only decoded when read: chunks which fit entirely in a read are decoded directly into the output, and only chunks which are split between reads go through an internal buffer.
Warning
Pushed blobs are referenced, not copied, until they have been read; they must not be modified in the meantime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...] | None
|
per-chirp sample shape, excluding the chirps axis. If |
None
|
backend
|
Literal['native', 'numpy'] | None
|
implementation to use; if |
None
|
Source code in src/iqz/_stream.py
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 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 | |
push
¶
Queue a blob for reading.
Only the blob's header is checked here; it is decoded when read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blob
|
Buffer
|
encoded chunk with any number of chirps. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the blob's header is malformed, or does not match the stream's shape. |
Source code in src/iqz/_stream.py
read_into
¶
Read the next len(out) chirps into a buffer provided by the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out
|
Int16[ndarray, chirps * sample]
|
writable, C-contiguous int16 array of shape |
required |
Returns:
| Type | Description |
|---|---|
Int16[ndarray, chirps * sample]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if fewer than |
Source code in src/iqz/_stream.py
read
¶
read(
k: int | None = None, *, format: Literal["numpy", "bytes"] = "numpy"
) -> Int16[ndarray, chirps * sample] | bytes
Read decoded chirps into a new array.
Allocates a new output for every read; use read_into to
reuse a buffer instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int | None
|
number of chirps to read; if |
None
|
format
|
Literal['numpy', 'bytes']
|
|
'numpy'
|
Returns:
| Type | Description |
|---|---|
Int16[ndarray, chirps * sample] | bytes
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if fewer than |
Source code in src/iqz/_stream.py
iqz.Encoder
¶
Streaming encoder, which re-chunks chirps into fixed-size windows.
Chirps can be pushed in batches of any size; each completed window of
window chirps is emitted as one blob. Call flush at the end of
the stream to encode any remaining chirps as a final, shorter chunk.
encoder = iqz.Encoder(window=64)
blobs = []
for frame in frames: # e.g. (1, 3, 4, 1024) int16 each
blobs.extend(encoder.push(frame))
blobs.extend(encoder.flush())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
number of chirps per encoded chunk. |
64
|
shape
|
tuple[int, ...] | None
|
per-chirp sample shape, excluding the chirps axis. If |
None
|
level
|
int
|
zstd compression level. |
3
|
backend
|
Literal['native', 'numpy'] | None
|
implementation to use; if |
None
|
Source code in src/iqz/_stream.py
14 15 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 | |
push
¶
Add chirps to the stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Int16[ndarray, chirps * sample] | Buffer
|
one or more int16 chirps, either as an array with a leading chirps axis, or as a buffer of little-endian int16 samples. The data is copied (or encoded) before returning, so the caller may reuse it. |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
Blobs for each window completed by this push (possibly none). |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Source code in src/iqz/_stream.py
flush
¶
Encode any buffered chirps as a final (shorter) chunk.
The encoder can be reused for a new stream (with the same shape) afterwards.
Returns:
| Type | Description |
|---|---|
list[bytes]
|
One blob if any chirps were pending; otherwise, an empty list. |
Source code in src/iqz/_stream.py
iqz.decode
¶
decode(
blob: Buffer,
shape: tuple[int, ...] | None = None,
*,
format: Literal["numpy", "bytes"] = "numpy",
backend: Literal["native", "numpy"] | None = None,
) -> Int16[ndarray, chirps * sample] | bytes
Decode one chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blob
|
Buffer
|
encoded chunk; any buffer, e.g. |
required |
shape
|
tuple[int, ...] | None
|
per-chirp sample shape, excluding the chirps axis. If |
None
|
format
|
Literal['numpy', 'bytes']
|
|
'numpy'
|
backend
|
Literal['native', 'numpy'] | None
|
implementation to use; if |
None
|
Returns:
| Type | Description |
|---|---|
Int16[ndarray, chirps * sample] | bytes
|
Decoded chirps. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the blob is malformed, or does not match |
Source code in src/iqz/_api.py
iqz.decode_into
¶
decode_into(
blob: Buffer,
out: Int16[ndarray, chirps * sample],
*,
backend: Literal["native", "numpy"] | None = None,
) -> Int16[ndarray, chirps * sample]
decode_into(
blob: Buffer,
out: Buffer,
*,
backend: Literal["native", "numpy"] | None = None,
) -> memoryview
decode_into(
blob: Buffer,
out: Int16[ndarray, chirps * sample] | Buffer,
*,
backend: Literal["native", "numpy"] | None = None,
) -> Int16[ndarray, chirps * sample] | memoryview
Decode one chunk into a buffer provided by the caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blob
|
Buffer
|
encoded chunk; any buffer, e.g. |
required |
out
|
Int16[ndarray, chirps * sample] | Buffer
|
destination; either a writable, C-contiguous int16 array with
exactly |
required |
backend
|
Literal['native', 'numpy'] | None
|
implementation to use; if |
None
|
Returns:
| Type | Description |
|---|---|
Int16[ndarray, chirps * sample] | memoryview
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if the blob is malformed, or |
Source code in src/iqz/_api.py
iqz.encode
¶
encode(
x: Int16[ndarray, chirps * sample] | Buffer,
shape: tuple[int, ...] | None = None,
*,
level: int = 3,
backend: Literal["native", "numpy"] | None = None,
) -> bytes
Encode one chunk of chirps.
Info
The codec is designed for chunks of 64 chirps; any n >= 1 works,
though shorter chunks compress worse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Int16[ndarray, chirps * sample] | Buffer
|
int16 chirps, either as an array with a leading chirps axis, or as
any buffer of little-endian int16 samples (with |
required |
shape
|
tuple[int, ...] | None
|
per-chirp sample shape, excluding the leading chirps axis. If
|
None
|
level
|
int
|
zstd compression level. |
3
|
backend
|
Literal['native', 'numpy'] | None
|
implementation to use; if |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded blob. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Source code in src/iqz/_api.py
iqz.info
¶
Get the shape of an encoded chunk.
The shape is recovered from the content sizes recorded in the blob's two zstd frame headers; nothing is decompressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blob
|
Buffer
|
encoded chunk. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the blob is malformed. |