API Reference
The flacarray
package consists of a primary class (FlacArray
) plus a
variety of helper functions.
Compressed Array Representation
The FlacArray
class stores a compressed representation of an N dimensional
array where the last dimension consists of "streams" of numbers to be
compressed.
flacarray.FlacArray
FLAC compressed array representation.
This class holds a compressed representation of an N-dimensional array. The final (fastest changing) dimension is the axis along which the data is compressed. Each of the vectors in this last dimension is called a "stream" here. The leading dimensions of the original matrix form an array of these streams.
Internally, the data is stored as a contiguous concatenation of the bytes from these compressed streams. A separate array contains the starting byte of each stream in the overall bytes array. The shape of the starting array corresponds to the shape of the leading, un-compressed dimensions of the original array.
The input data is converted to 32bit integers. The "quanta" value is used for floating point data conversion and represents the floating point increment for a single integer value. If quanta is None, each stream is scaled independently based on its data range. If quanta is a scalar, all streams are scaled with the same value. If quanta is an array, it specifies the scaling independently for each stream.
Alternatively, if "precision" is provided, each data vector is scaled to retain the prescribed number of significant digits when converting to integers.
The following rules specify the data conversion that is performed depending on the input type:
-
int32: No conversion.
-
int64: Subtract the integer closest to the mean, then truncate to lower 32 bits, and check that the higher bits were zero.
-
float32: Subtract the mean and scale data based on the quanta value (see above). Then round to nearest 32bit integer.
-
float64: Subtract the mean and scale data based on the quanta value (see above). Then round to nearest 32bit integer.
After conversion to 32bit integers, each stream's data is separately compressed into a sequence of FLAC bytes, which is appended to the bytestream. The offset in bytes for each stream is recorded.
A FlacArray is only constructed directly when making a copy. Use the class methods to create FlacArrays from numpy arrays or on-disk representations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
FlacArray
|
Construct a copy of the input FlacArray. |
required |
Source code in flacarray/array.py
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 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 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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
|
compressed
property
The concatenated raw bytes of all streams on the local process.
global_leading_shape
property
The global shape of leading uncompressed dimensions across all processes.
global_nbytes
property
The sum of total bytes used by compressed data across all processes.
global_nstreams
property
Number of global streams (product of entries of global_leading_shape
)
global_process_nbytes
property
The bytes used by compressed data on each process.
global_shape
property
The global shape of array across any MPI communicator.
global_stream_nbytes
property
The array of nbytes within the global compressed data.
global_stream_starts
property
The array of starting bytes within the global compressed data.
leading_shape
property
The local shape of leading uncompressed dimensions.
mpi_comm
property
The MPI communicator over which the array is distributed.
mpi_dist
property
The range of the leading dimension assigned to each MPI process.
nbytes
property
The total number of bytes used by compressed data on the local process.
nstreams
property
The number of local streams (product of entries of leading_shape
)
shape
property
The shape of the local, uncompressed array.
stream_gains
property
The gain factor for each stream during conversion to int32.
stream_nbytes
property
The array of nbytes for each stream on the local process.
stream_offsets
property
The value subtracted from each stream during conversion to int32.
stream_size
property
The uncompressed length of each stream.
stream_starts
property
The array of starting bytes for each stream on the local process.
__getitem__(key)
Decompress a slice of data on the fly.
Source code in flacarray/array.py
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 |
|
from_array(arr, level=5, quanta=None, precision=None, mpi_comm=None, use_threads=False)
classmethod
Construct a FlacArray from a numpy ndarray.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
The input array data. |
required |
level
|
int
|
Compression level (0-8). |
5
|
quanta
|
(float, array)
|
For floating point data, the floating point increment of each 32bit integer value. Optionally an iterable of increments, one per stream. |
None
|
precision
|
(int, array)
|
Number of significant digits to retain in
float-to-int conversion. Alternative to |
None
|
mpi_comm
|
Comm
|
If specified, the input array is assumed to be distributed across the communicator at the leading dimension. The local piece of the array is passed in on each process. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
FlacArray
|
A newly constructed FlacArray. |
Source code in flacarray/array.py
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 |
|
read_hdf5(hgrp, keep=None, mpi_comm=None, mpi_dist=None)
classmethod
Construct a FlacArray from an HDF5 Group.
This function loads all information about the array from an HDF5 group. If
mpi_comm
is specified, the created array is distributed over that
communicator. If you also wish to use MPI I/O to read data from the group,
then you must be using an MPI-enabled h5py and you should pass in a valid
handle to the group on all processes.
If mpi_dist
is specified, it should be an iterable with the number of leading
dimension elements assigned to each process. If None, the leading dimension
will be distributed uniformly.
If keep
is specified, this should be a boolean array with the same shape
as the leading dimensions of the original array. True values in this array
indicate that the stream should be kept.
If keep
is specified, the returned array WILL NOT have the same shape as
the original. Instead it will be a 2D array of decompressed streams- the
streams corresponding to True values in the keep
mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hgrp
|
Group
|
The open Group for reading. |
required |
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
mpi_comm
|
Comm
|
If specified, the communicator over which to distribute the leading dimension. |
None
|
mpi_dist
|
array
|
If specified, assign blocks of these sizes to processes when distributing the leading dimension. |
None
|
Returns:
Type | Description |
---|---|
FlacArray
|
A newly constructed FlacArray. |
Source code in flacarray/array.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
read_zarr(zgrp, keep=None, mpi_comm=None, mpi_dist=None)
classmethod
Construct a FlacArray from a Zarr Group.
This function loads all information about the array from a zarr group. If
mpi_comm
is specified, the created array is distributed over that
communicator.
If mpi_dist
is specified, it should be an iterable with the number of leading
dimension elements assigned to each process. If None, the leading dimension
will be distributed uniformly.
If keep
is specified, this should be a boolean array with the same shape
as the leading dimensions of the original array. True values in this array
indicate that the stream should be kept.
If keep
is specified, the returned array WILL NOT have the same shape as
the original. Instead it will be a 2D array of decompressed streams- the
streams corresponding to True values in the keep
mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zgrp
|
Group
|
The open Group for reading. |
required |
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
mpi_comm
|
Comm
|
If specified, the communicator over which to distribute the leading dimension. |
None
|
mpi_dist
|
array
|
If specified, assign blocks of these sizes to processes when distributing the leading dimension. |
None
|
Returns:
Type | Description |
---|---|
FlacArray
|
A newly constructed FlacArray. |
Source code in flacarray/array.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
|
to_array(keep=None, stream_slice=None, keep_indices=False, use_threads=False)
Decompress local data into a numpy array.
This uses the compressed representation to reconstruct a normal numpy array. The returned data type will be either int32, int64, float32, or float64 depending on the original data type.
If stream_slice
is specified, the returned array will have only that
range of samples in the final dimension.
If keep
is specified, this should be a boolean array with the same shape
as the leading dimensions of the original array. True values in this array
indicate that the stream should be kept.
If keep
is specified, the returned array WILL NOT have the same shape as
the original. Instead it will be a 2D array of decompressed streams- the
streams corresponding to True values in the keep
mask.
If keep_indices
is True and keep
is specified, then a tuple of two values
is returned. The first is the array of decompressed streams. The second is
a list of tuples, each of which specifies the indices of the stream in the
original array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
stream_slice
|
slice
|
A python slice with step size of one, indicating the sample range to extract from each stream. |
None
|
keep_indices
|
bool
|
If True, also return the original indices of the streams. |
False
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Source code in flacarray/array.py
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 |
|
write_hdf5(hgrp)
Write data to an HDF5 Group.
The internal object properties are written to an open HDF5 group. If you wish to use MPI I/O to write data to the group, then you must be using an MPI enabled h5py and you should pass in a valid handle to the group on all processes.
If the FlacArray
is distributed over an MPI communicator, but the h5py
implementation does not support MPI I/O, then all data will be communicated
to the rank zero process for writing. In this case, the hgrp
argument should
be None except on the root process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hgrp
|
Group
|
The open Group for writing. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in flacarray/array.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
write_zarr(zgrp)
Write data to an Zarr Group.
The internal object properties are written to an open zarr group.
If the FlacArray
is distributed over an MPI communicator, then all data will
be communicated to the rank zero process for writing. In this case, the zgrp
argument should be None except on the root process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zgrp
|
Group
|
The open Group for writing. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in flacarray/array.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
Direct I/O
Sometimes code has no need to store compressed arrays in memory. Instead, it may be desirable to have full arrays in memory and compressed arrays on disk. In those situations, you can use several helper functions to write and read numpy arrays directly to / from files.
HDF5
You can write to / read from an h5py Group using functions in the hdf5
submodule.
flacarray.hdf5.write_array(arr, hgrp, level=5, quanta=None, precision=None, mpi_comm=None, use_threads=False)
Compress a numpy array and write to an HDF5 group.
This function is useful if you do not need to access the compressed array in memory
and only wish to write it directly to HDF5. The input array is compressed and then
the write_compressed()
function is called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
array
|
The input numpy array. |
required |
hgrp
|
Group
|
The Group to use. |
required |
level
|
int
|
Compression level (0-8). |
5
|
quanta
|
(float, array)
|
For floating point data, the floating point increment of each 32bit integer value. Optionally an iterable of increments, one per stream. |
None
|
precision
|
(int, array)
|
Number of significant digits to retain in
float-to-int conversion. Alternative to |
None
|
mpi_comm
|
Comm
|
If specified, the input array is assumed to be distributed across the communicator at the leading dimension. The local piece of the array is passed in on each process. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
None |
Source code in flacarray/hdf5.py
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 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 |
|
flacarray.hdf5.read_array(hgrp, keep=None, stream_slice=None, keep_indices=False, mpi_comm=None, mpi_dist=None, use_threads=False)
Load a numpy array from compressed HDF5.
This function is useful if you do not need to store a compressed representation of the array in memory. Each stream will be read individually from the file and the desired slice decompressed. This avoids storing the full compressed data.
This function acts as a dispatch to the correct version of the reading function. The function is selected based on the format version string in the data.
If stream_slice
is specified, the returned array will have only that
range of samples in the final dimension.
If keep
is specified, this should be a boolean array with the same shape
as the leading dimensions of the original array. True values in this array
indicate that the stream should be kept.
If keep
is specified, the returned array WILL NOT have the same shape as
the original. Instead it will be a 2D array of decompressed streams- the
streams corresponding to True values in the keep
mask.
If keep_indices
is True and keep
is specified, then an additional list
is returned containing the indices of each stream that was kept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hgrp
|
Group
|
The group to read. |
required |
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
stream_slice
|
slice
|
A python slice with step size of one, indicating the sample range to extract from each stream. |
None
|
keep_indices
|
bool
|
If True, also return the original indices of the streams. |
False
|
mpi_comm
|
Comm
|
The optional MPI communicator over which to distribute the leading dimension of the array. |
None
|
mpi_dist
|
list
|
The optional list of tuples specifying the first / last element of the leading dimension to assign to each process. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
array
|
The loaded and decompressed data OR the array and the kept indices. |
Source code in flacarray/hdf5.py
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 |
|
Zarr
You can write to / read from a zarr hierarch Group using functions in the
zarr
submodule.
flacarray.zarr.write_array(arr, zgrp, level=5, quanta=None, precision=None, mpi_comm=None, use_threads=False)
Compress a numpy array and write to an Zarr group.
This function is useful if you do not need to access the compressed array in memory
and only wish to write it directly to Zarr files. The input array is compressed
and then the write_compressed()
function is called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
array
|
The input numpy array. |
required |
zgrp
|
Group
|
The Group to use. |
required |
level
|
int
|
Compression level (0-8). |
5
|
quanta
|
(float, array)
|
For floating point data, the floating point increment of each 32bit integer value. Optionally an iterable of increments, one per stream. |
None
|
precision
|
(int, array)
|
Number of significant digits to retain in
float-to-int conversion. Alternative to |
None
|
mpi_comm
|
Comm
|
If specified, the input array is assumed to be distributed across the communicator at the leading dimension. The local piece of the array is passed in on each process. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
None |
Source code in flacarray/zarr.py
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 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 |
|
flacarray.zarr.read_array(zgrp, keep=None, stream_slice=None, keep_indices=False, mpi_comm=None, mpi_dist=None, use_threads=False)
Load a numpy array from a compressed Zarr group.
This function is useful if you do not need to store a compressed representation of the array in memory. Each stream will be read individually from the file and the desired slice decompressed. This avoids storing the full compressed data.
This function acts as a dispatch to the correct version of the reading function. The function is selected based on the format version string in the data.
If stream_slice
is specified, the returned array will have only that
range of samples in the final dimension.
If keep
is specified, this should be a boolean array with the same shape
as the leading dimensions of the original array. True values in this array
indicate that the stream should be kept.
If keep
is specified, the returned array WILL NOT have the same shape as
the original. Instead it will be a 2D array of decompressed streams- the
streams corresponding to True values in the keep
mask.
If keep_indices
is True and keep
is specified, then an additional list
is returned containing the indices of each stream that was kept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zgrp
|
Group
|
The group to read. |
required |
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
stream_slice
|
slice
|
A python slice with step size of one, indicating the sample range to extract from each stream. |
None
|
keep_indices
|
bool
|
If True, also return the original indices of the streams. |
False
|
mpi_comm
|
Comm
|
The optional MPI communicator over which to distribute the leading dimension of the array. |
None
|
mpi_dist
|
list
|
The optional list of tuples specifying the first / last element of the leading dimension to assign to each process. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
array
|
The loaded and decompressed data OR the array and the kept indices. |
Source code in flacarray/zarr.py
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 |
|
Interactive Tools
The flacarray.demo
submodule contains a few helper functions that are not
imported by default. You will need to have optional dependencies (matplotlib)
installed to use the visualization tools. For testing, it is convenient to
generate arrays consisting of random timestreams with some structure. The
create_fake_data
function can be used for this.
flacarray.demo.create_fake_data(shape, sigma=1.0, dtype=np.float64)
Source code in flacarray/demo.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Most data arrays in practice have 2 or 3 dimensions. If the number of streams
is relatively small, then an uncompressed array can be plotted with the
plot_data
function.
flacarray.demo.plot_data(data, keep=None, stream_slc=slice(None), file=None)
Source code in flacarray/demo.py
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 |
|
Low-Level Tools
For specialized use cases, you can also work directly with the compressed bytestream and auxiliary arrays and convert to / from numpy arrays.
flacarray.compress.array_compress(arr, level=5, quanta=None, precision=None, use_threads=False)
Compress a numpy array with optional floating point conversion.
If arr
is an int32 array, the returned stream offsets and gains will be None.
if arr
is an int64 array, the stream offsets will be the integer value subtracted
when converting to int32. Both float32 and float64 data will have floating point
offset and gain arrays returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
The input array data. |
required |
level
|
int
|
Compression level (0-8). |
5
|
quanta
|
(float, array)
|
For floating point data, the floating point increment of each 32bit integer value. Optionally an array of increments, one per stream. |
None
|
precision
|
(int, array)
|
Number of significant digits to retain in
float-to-int conversion. Alternative to |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
tuple
|
The (compressed bytes, stream starts, stream_nbytes, stream offsets, stream gains) |
Source code in flacarray/compress.py
11 12 13 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 |
|
flacarray.decompress.array_decompress(compressed, stream_size, stream_starts, stream_nbytes, stream_offsets=None, stream_gains=None, first_stream_sample=None, last_stream_sample=None, use_threads=False)
Decompress a FLAC encoded array and restore original data type.
If stream_gains
is specified, the output data will be float32 and stream_offsets
must also be provided. If stream_gains
is not specified, but stream_offsets
is,
then the returned data will be int64. If neither offsets or gains are specified,
the decompressed int32 array is returned.
To decompress a subset of samples in all streams, specify the first_stream_sample
and last_stream_sample
values. None values or negative values disable this
feature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compressed
|
array
|
The array of compressed bytes. |
required |
stream_size
|
int
|
The length of the decompressed final dimension. |
required |
stream_starts
|
array
|
The array of starting bytes in the bytestream. |
required |
stream_nbytes
|
array
|
The array of number of bytes in each stream. |
required |
stream_offsets
|
array
|
The array of offsets, one per stream. |
None
|
stream_gains
|
array
|
The array of gains, one per stream. |
None
|
first_stream_sample
|
int
|
The first sample of every stream to decompress. |
None
|
last_stream_sample
|
int
|
The last sample of every stream to decompress. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
array
|
The output array. |
Source code in flacarray/decompress.py
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 |
|
flacarray.decompress.array_decompress_slice(compressed, stream_size, stream_starts, stream_nbytes, stream_offsets=None, stream_gains=None, keep=None, first_stream_sample=None, last_stream_sample=None, use_threads=False)
Decompress a slice of a FLAC encoded array and restore original data type.
If stream_gains
is specified, the output data will be float32 and stream_offsets
must also be provided. If stream_gains
is not specified, but stream_offsets
is,
then the returned data will be int64. If neither offsets or gains are specified,
the decompressed int32 array is returned.
To decompress a subset of samples in all streams, specify the first_stream_sample
and last_stream_sample
values. None values or negative values disable this
feature.
To decompress a subset of streams, pass a boolean array to the keep
argument.
This should have the same shape as the starts
array. Only streams with a True
value in the keep
array will be decompressed.
If the keep
array is specified, the output tuple will contain the 2D array of
streams that were kept, as well as a list of tuples indicating the original array
indices for each stream in the output. If the keep
array is None, the output
tuple will contain an array with the original N-dimensional leading array shape
and the trailing number of samples. The second element of the tuple will be None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compressed
|
array
|
The array of compressed bytes. |
required |
stream_size
|
int
|
The length of the decompressed final dimension. |
required |
stream_starts
|
array
|
The array of starting bytes in the bytestream. |
required |
stream_nbytes
|
array
|
The array of number of bytes in each stream. |
required |
stream_offsets
|
array
|
The array of offsets, one per stream. |
None
|
stream_gains
|
array
|
The array of gains, one per stream. |
None
|
keep
|
array
|
Bool array of streams to keep in the decompression. |
None
|
first_stream_sample
|
int
|
The first sample of every stream to decompress. |
None
|
last_stream_sample
|
int
|
The last sample of every stream to decompress. |
None
|
use_threads
|
bool
|
If True, use OpenMP threads to parallelize decoding. This is only beneficial for large arrays. |
False
|
Returns:
Type | Description |
---|---|
tuple
|
The (output array, list of stream indices). |
Source code in flacarray/decompress.py
11 12 13 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 |
|