comdas.codecs.wavelet¶
Wavelet compression via PyWavelets.
Classes
|
Wavelet-thresholding codec. |
|
Thresholded wavelet-coefficient representation of an array. |
- class comdas.codecs.wavelet.WaveletPayload(original_shape, dtype, wavelet, mode, indices, values)¶
Bases:
CompressedPayloadThresholded wavelet-coefficient representation of an array.
Retained coefficients are stored as
(indices, values)pairs.- Variables:
wavelet (str) – Name of the PyWavelets wavelet.
mode (str) – PyWavelets signal extension mode.
indices (numpy.ndarray) – Flat indices of retained coefficients.
values (numpy.ndarray) – Values of retained coefficients.
- property coeff_shapes: list¶
Get the coefficient shapes of the decomposition before thresholding.
- Return type:
list
- property n_coeffs: int¶
Total number of coefficients in the full decomposition without thresholding.
- Return type:
int
- property compression_params: dict¶
The compression parameters used for this payload.
- Return type:
dict
- class comdas.codecs.wavelet.WaveletCodec(wavelet='db4', mode='symmetric', keep_fraction=None, threshold=None)¶
Bases:
CodecWavelet-thresholding codec.
The array is decomposed with a multilevel n-dimensional discrete wavelet transform (
pywt.wavedecn()) at the maximum useful level for the array shape, and only the largest-magnitude coefficients are retained.Coefficients to keep can be chosen either as a fraction
keep_fractionin(0, 1]of all coefficients, or as an absolute magnitudethresholdwhere coefficients with|c| > thresholdare kept. Exactly one option must be specified, either as a codec-level default or per-call parameter.- Parameters:
wavelet (
str) – PyWavelets wavelet name. (default:"db4")mode (
str) – PyWavelets signal extension mode. (default:"symmetric")keep_fraction (
float|None) – Default fraction of coefficients to retain.threshold (
float|None) – Default absolute coefficient magnitude threshold.
- Raises:
ValueError – If both of
keep_fractionandthresholdare specified.
- encode(array, *, wavelet=None, mode=None, keep_fraction=None, threshold=None, **kwargs)¶
Compress an array via wavelet coefficient thresholding.
- Parameters:
array (
ndarray) – The dense array to compress.wavelet (
str|None) – Overridesself.default_waveletfor this call.mode (
str|None) – Overridesself.default_modefor this call.keep_fraction (
float|None) – Fraction of coefficients to retain, in(0, 1]. Overridesself.default_keep_fractionfor this call.threshold (
float|None) – Absolute coefficient magnitude threshold. Overridesself.default_thresholdfor this call.kwargs – Accepted and ignored for compatibility.
- Returns:
The sparse wavelet payload.
- Return type:
- Raises:
ValueError – If both or neither of
keep_fractionandthresholdare specified, or either is out of range.
- decode(payload)¶
Reconstruct the dense array via the inverse wavelet transform.
- Parameters:
payload (
WaveletPayload) – A payload previously produced byencode().- Returns:
The reconstructed dense array.
- Return type:
ndarray
- compressed_size_bytes(payload)¶
Get payload size.
- Parameters:
payload (
WaveletPayload) – A payload previously produced byencode().- Returns:
Combined byte size of the stored arrays.
- Return type:
int
- payload_to_group(payload, group)¶
Write
indices,values, and transform parameters into an openh5py.Group.- Parameters:
payload (
WaveletPayload) – The payload to serialize.group (h5py.Group) – An open, writable
h5py.Groupdedicated to this one patch.
- Return type:
None
- payload_from_group(group, *, original_shape, dtype)¶
Construct a
WaveletPayloadfrom an HDF5 group.- Parameters:
group (h5py.Group) – An open, readable
h5py.Grouppreviously written bypayload_to_group().original_shape (
tuple[int,...]) – The array shape, as read from the container’s own attributes.dtype (
dtype) – The array dtype, as read from the container’s own attributes.
- Returns:
The reconstructed payload.
- Return type: