@@ -30,6 +30,19 @@ class BitInfo(BitRound):
30
30
axes: int or list of int, optional
31
31
Axes along which to calculate the bit information. If None, all axes
32
32
are used.
33
+
34
+ Examples
35
+ --------
36
+ >>> import xarray as xr
37
+ >>> ds = xr.tutorial.open_dataset("air_temperature")
38
+ >>> # Note these data have already undergone lossy compression,
39
+ >>> # which should not be combined with bitinformation in practice
40
+
41
+ >>> from numcodecs import Blosc, BitInfo
42
+ >>> compressor = Blosc(cname="zstd", clevel=3)
43
+ >>> filters = [BitInfo(info_level=0.99)]
44
+ >>> encoding = {"air": {"compressor": compressor, "filters": filters}}
45
+ >>> ds.to_zarr('xbit.zarr', mode="w", encoding=encoding)
33
46
"""
34
47
35
48
codec_id = 'bitinfo'
@@ -204,8 +217,7 @@ def bitpaircount(a, b):
204
217
205
218
206
219
def mutual_information (a , b , base = 2 ):
207
- """Calculate the mutual information between two arrays.
208
- """
220
+ """Calculate the mutual information between two arrays."""
209
221
assert a .dtype == b .dtype
210
222
assert a .dtype .kind == "u"
211
223
@@ -265,9 +277,7 @@ def get_keepbits(info_per_bit, inflevel=0.99):
265
277
266
278
cdf = _cdf_from_info_per_bit (info_per_bit )
267
279
bitdim_non_mantissa_bits = NMBITS [len (info_per_bit )]
268
- keepmantissabits = (
269
- (cdf > inflevel ).argmax () + 1 - bitdim_non_mantissa_bits
270
- )
280
+ keepmantissabits = (cdf > inflevel ).argmax () + 1 - bitdim_non_mantissa_bits
271
281
272
282
return keepmantissabits
273
283
0 commit comments