1+ from hub .numcodecs import PngCodec
12import math
23
34import numpy as np
45
5- from hub .defaults import CHUNK_DEFAULT_SIZE , OBJECT_CHUNK
6+ from hub .defaults import CHUNK_DEFAULT_SIZE , OBJECT_CHUNK , DEFAULT_COMPRESSOR
67from hub .exceptions import HubException
78
89
@@ -17,19 +18,27 @@ def __init__(
1718 dtype = "float64" ,
1819 chunksize = CHUNK_DEFAULT_SIZE ,
1920 object_chunking = OBJECT_CHUNK ,
21+ compressor = DEFAULT_COMPRESSOR ,
2022 ):
2123 self ._int32max = np .iinfo (np .dtype ("int32" )).max
2224
2325 self ._dtype = dtype = np .dtype (dtype )
24- self ._chunksize = chunksize
2526 self ._object_chunking = object_chunking
27+ self ._compressor = compressor
2628
29+ self ._chunksize = chunksize = self ._get_chunksize (chunksize , compressor )
2730 self ._shape = shape = self ._get_shape (shape )
2831 self ._max_shape = max_shape = self ._get_max_shape (shape , max_shape )
2932 self ._chunks = chunks = self ._get_chunks (
3033 shape , max_shape , chunks , dtype , chunksize
3134 )
3235
36+ def _get_chunksize (self , chunksize , compressor ):
37+ if isinstance (compressor , PngCodec ):
38+ return int (math .ceil (0.25 * chunksize ))
39+ else :
40+ return chunksize
41+
3342 def _get_shape (self , shape ):
3443 assert shape is not None
3544 shape = (shape ,) if isinstance (shape , int ) else tuple (shape )
0 commit comments