pct_tools.utils¶
Maintenance of stored system-matrix blocks: recompression and row subsampling.
Both operations read a compressed block written by pct_tools.io, transform it on the
C++ side and write a new file, without loading the matrix into Python. Subsampling keeps a
random fraction of the rows of a matrix block and the matching entries of its b-vector, to
emulate a lower dose from the same simulation.
- pct_tools.utils.subsample_matrix_vector_pair(input_path, projection, output_path, subsampling_ratio, pixel_width, *, seed=0, compression_level=9, shuffle_method=ShuffleMethod.BLOSC_SHUFFLE, codec='lz4hc', verbosity_level=0)[source]¶
Subsample matrix and b-vector for a given projection.
Reads
<input_path>/matrix-<pixel_width>mm/<projection>.matand<input_path>/b/b_<projection>.vec, keeps a random fraction of the rows and writes the result to the same relative locations underoutput_path.- Parameters:
input_path (str) – The path to the input matrices.
projection (str) – The projection to subsample.
output_path (str) – The path to the output matrices.
subsampling_ratio (float) – The fraction of rows to keep, in [0, 1].
pixel_width (float) – The pixel width in mm; selects the
matrix-<pixel_width>mmdirectory.seed (int) – Seed of the random number generator used to pick rows.
compression_level (int) – The compression level to use when storing the result.
shuffle_method (ShuffleMethod) – The blosc shuffle method to use.
codec (Codec) – The Blosc codec to use. Default is LZ4HC.
verbosity_level (int) – The verbosity level.
- pct_tools.utils.recompress_matrix(filename, output, compression_level=9, shuffle_method=ShuffleMethod.BLOSC_SHUFFLE, codec='lz4hc', verbosity_level=0)[source]¶
Recompress a matrix with a given codec and compression level.
- Parameters:
filename (str) – The name of the file containing the matrix.
output (str) – The name of the output file.
compression_level (int) – The compression level to use when storing it.
shuffle_method (ShuffleMethod) – The blosc shuffle method to use.
codec (Codec) – The Blosc codec to use. Default is LZ4HC.
verbosity_level (int) – The verbosity level.