Codec API Reference¶
This page documents the codec implementations for both Zarr V2 and V3.
AnscombeTransformV3¶
AnscombeTransformV3
dataclass
¶
Bases: ArrayArrayCodec
Zarr v3 codec for Anscombe Transform for photon-limited data.
The codec assumes input data has linear encoding with Poisson noise, typically from photon-limited imaging modalities.
Attributes:
| Name | Type | Description |
|---|---|---|
zero_level |
int
|
Signal level when no photons are recorded. |
conversion_gain |
float
|
Signal intensity increase per photon. |
encoded_dtype |
str
|
Data type for encoded values (default: "uint8"). |
decoded_dtype |
str
|
Data type for decoded values (default: "int16"). |
is_fixed_size |
bool
|
Whether the codec produces fixed-size output (default: True). |
Source code in src/anscombe_transform/codec.py
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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
from_dict(data)
classmethod
¶
Create codec instance from configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Configuration dictionary with 'configuration' key containing codec parameters. |
required |
Returns:
| Type | Description |
|---|---|
AnscombeTransformV3
|
New codec instance. |
Source code in src/anscombe_transform/codec.py
to_dict()
¶
Convert codec to configuration dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Configuration dictionary with codec name and parameters. |
Source code in src/anscombe_transform/codec.py
resolve_metadata(chunk_spec)
¶
Resolve metadata for encoded output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_spec
|
ArraySpec
|
Input chunk specification. |
required |
Returns:
| Type | Description |
|---|---|
ArraySpec
|
Output chunk specification with updated dtype. |
Source code in src/anscombe_transform/codec.py
AnscombeTransformV2¶
AnscombeTransformV2
dataclass
¶
Zarr v2 codec for Anscombe Transform for photon-limited data.
The codec assumes input data has linear encoding with Poisson noise, typically from photon-limited imaging modalities.
Attributes:
| Name | Type | Description |
|---|---|---|
codec_id |
str
|
Codec identifier ("anscombe-v1"). |
zero_level |
int
|
Signal level when no photons are recorded. |
conversion_gain |
float
|
Signal intensity increase per photon. |
encoded_dtype |
str
|
Data type for encoded values (default: "uint8"). |
decoded_dtype |
str
|
Data type for decoded values (default: "int16"). |
Source code in src/anscombe_transform/codec.py
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 | |
encode(buf)
¶
Encode data using Anscombe transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
ndarray
|
Input array to encode. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Encoded array. |
Source code in src/anscombe_transform/codec.py
decode(buf, out=None)
¶
Decode data using inverse Anscombe transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
bytes
|
Encoded buffer to decode. |
required |
out
|
object or None
|
Output buffer (unused), by default None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Decoded array. |
Source code in src/anscombe_transform/codec.py
get_config()
¶
Get codec configuration dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Configuration dictionary with codec ID and parameters. |
Source code in src/anscombe_transform/codec.py
from_config(config)
classmethod
¶
Create codec instance from configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Configuration dictionary with 'zero_level' and 'conversion_gain' keys. |
required |
Returns:
| Type | Description |
|---|---|
AnscombeTransformV2
|
New codec instance. |
Source code in src/anscombe_transform/codec.py
Core Functions¶
encode¶
encode(buf, *, conversion_gain, zero_level, encoded_dtype)
¶
Encode an array using the Anscombe transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
ndarray
|
Input array to encode. |
required |
conversion_gain
|
float
|
Signal intensity increase per photon. |
required |
zero_level
|
int
|
Signal level when no photons are recorded. |
required |
encoded_dtype
|
str
|
NumPy dtype string for encoded output. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Encoded array with variance-stabilized values. |
Source code in src/anscombe_transform/codec.py
decode¶
decode(buf, *, conversion_gain, zero_level, encoded_dtype, decoded_dtype)
¶
Decode an array using the inverse Anscombe transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
bytes or ndarray
|
Encoded buffer to decode. |
required |
conversion_gain
|
float
|
Signal intensity increase per photon. |
required |
zero_level
|
int
|
Signal level when no photons are recorded. |
required |
encoded_dtype
|
DtypeLike
|
NumPy dtype of encoded data. |
required |
decoded_dtype
|
DtypeLike
|
NumPy dtype for decoded output. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Decoded array with original value scale. |
Source code in src/anscombe_transform/codec.py
Lookup Table Functions¶
make_anscombe_lookup¶
make_anscombe_lookup(conversion_gain, input_max=32767, zero_level=0, beta=0.5, output_type='uint8')
¶
Compute the Anscombe lookup table.
The lookup converts a linear grayscale image into a uniform variance image by applying the Anscombe variance-stabilizing transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversion_gain
|
float
|
Estimated signal intensity increase per quantum (e.g. photon). |
required |
input_max
|
int
|
The maximum value in the input data, by default 0x7FFF (32767). |
32767
|
zero_level
|
int
|
Signal level when no photons are recorded, by default 0. |
0
|
beta
|
float
|
The grayscale quantization step expressed in units of noise std dev, by default 0.5. |
0.5
|
output_type
|
str
|
NumPy dtype string for output array, by default "uint8". |
'uint8'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Lookup table array for Anscombe transformation. |
Source code in src/anscombe_transform/codec.py
make_inverse_lookup¶
make_inverse_lookup(lookup_table, output_type='int16')
¶
Compute the inverse lookup table for a monotonic forward lookup table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookup_table
|
ndarray
|
Monotonic forward lookup table. |
required |
output_type
|
str
|
NumPy dtype string for output array, by default "int16". |
'int16'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Inverse lookup table that maps encoded values back to original values. |
Source code in src/anscombe_transform/codec.py
lookup¶
lookup(movie, lookup_table)
¶
Apply lookup table to movie with boundary clamping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movie
|
ndarray
|
Input array to transform. |
required |
lookup_table
|
ndarray
|
Lookup table for transformation. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Transformed array with values from lookup table. |