本文整理汇总了Python中blosc.decompress方法的典型用法代码示例。如果您正苦于以下问题:Python blosc.decompress方法的具体用法?Python blosc.decompress怎么用?Python blosc.decompress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blosc
的用法示例。
在下文中一共展示了blosc.decompress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_file
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def _load_file(f, compressor, dtype):
try:
data = f.read()
if not len(data):
return np.zeros(0, dtype=dtype)
data = COMPRESSORS[compressor]['decompress'](data)
try:
return np.frombuffer(data, dtype=dtype)
except ValueError as e:
raise ValueError(f"ValueError while loading data with dtype =\n\t{dtype}") from e
except Exception:
raise strax.DataCorrupted(
f"Fatal Error while reading file {f}: "
+ strax.utils.formatted_exception())
示例2: unconvert
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def unconvert(values, dtype, compress=None):
if dtype == np.object_:
return np.array(values, dtype=object)
if compress == 'zlib':
values = zlib.decompress(values)
return np.frombuffer(values, dtype=dtype)
elif compress == 'blosc':
if not _BLOSC:
raise Exception("cannot uncompress w/o blosc")
# decompress
values = blosc.decompress(values)
return np.frombuffer(values, dtype=dtype)
# from a string
return np.fromstring(values.encode('latin1'), dtype=dtype)
示例3: PushFindMissingHashRecords
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def PushFindMissingHashRecords(self, request_iterator, context):
"""Determine data tensor hash records existing on the client and not on the server.
"""
for idx, request in enumerate(request_iterator):
if idx == 0:
commit = request.commit
hBytes, offset = bytearray(request.total_byte_size), 0
size = len(request.hashs)
hBytes[offset: offset + size] = request.hashs
offset += size
uncompBytes = blosc.decompress(hBytes)
c_hashs_raw = chunks.deserialize_record_pack(uncompBytes)
c_hashset = set([chunks.deserialize_ident(raw).digest for raw in c_hashs_raw])
s_hashset = set(hashs.HashQuery(self.env.hashenv).list_all_hash_keys_raw())
s_missing = c_hashset.difference(s_hashset)
s_hashs_raw = [chunks.serialize_ident(s_mis, '') for s_mis in s_missing]
raw_pack = chunks.serialize_record_pack(s_hashs_raw)
err = hangar_service_pb2.ErrorProto(code=0, message='OK')
response_pb = hangar_service_pb2.FindMissingHashRecordsReply
cIter = chunks.missingHashIterator(commit, raw_pack, err, response_pb)
yield from cIter
示例4: _load_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def _load_blosc(self, ix, src=None, dst=None):
""" Load data from a blosc packed file """
file_name = self._get_file_name(ix, src)
with open(file_name, 'rb') as f:
data = dill.loads(blosc.decompress(f.read()))
components = tuple(dst or self.components)
try:
item = tuple(data[i] for i in components)
except Exception as e:
raise KeyError('Cannot find components in corresponfig file', e)
return item
示例5: test_channel_uint8_cuboid_aligned_no_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint8_cuboid_aligned_no_offset_no_time_blosc(self):
""" Test uint8 data, cuboid aligned, no offset, no time samples"""
test_mat = np.random.randint(1, 254, (16, 128, 128))
test_mat = test_mat.astype(np.uint8)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=8)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel1/0/0:128/0:128/0:16/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel1/0/0:128/0:128/0:16/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint8)
data_mat = np.reshape(data_mat, (16, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例6: test_channel_uint8_cuboid_aligned_no_offset_no_time_blosc_4d
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint8_cuboid_aligned_no_offset_no_time_blosc_4d(self):
""" Test uint8 data, cuboid aligned, no offset, no time samples"""
test_mat = np.random.randint(1, 254, (1, 16, 128, 128))
test_mat = test_mat.astype(np.uint8)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=8)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel1/0/0:128/0:128/0:16/3:4/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range="3:4")
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel1/0/0:128/0:128/0:16/3:4/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:16', t_range="3:4").render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint8)
data_mat = np.reshape(data_mat, (1, 16, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例7: test_channel_uint8_cuboid_aligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint8_cuboid_aligned_offset_no_time_blosc(self):
""" Test uint8 data, cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 254, (16, 128, 128))
test_mat = test_mat.astype(np.uint8)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=8)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel1/0/128:256/256:384/16:32/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel1/0/128:256/256:384/16:32/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint8)
data_mat = np.reshape(data_mat, (16, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例8: test_channel_uint8_cuboid_unaligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint8_cuboid_unaligned_offset_no_time_blosc(self):
""" Test uint8 data, not cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 254, (17, 300, 500))
test_mat = test_mat.astype(np.uint8)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=8)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel1/0/100:600/450:750/20:37/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel1/0/100:600/450:750/20:37/',
HTTP_ACCEPT='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint8)
data_mat = np.reshape(data_mat, (17, 300, 500), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例9: test_channel_uint16_cuboid_aligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint16_cuboid_aligned_offset_no_time_blosc(self):
""" Test uint16 data, cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 2**16-1, (16, 128, 128))
test_mat = test_mat.astype(np.uint16)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=16)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel2/0/128:256/256:384/16:32/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel2',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel2/0/128:256/256:384/16:32/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel2',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:32', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint16)
data_mat = np.reshape(data_mat, (16, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例10: test_channel_uint16_cuboid_unaligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint16_cuboid_unaligned_offset_no_time_blosc(self):
""" Test uint16 data, not cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 2**16-1, (17, 300, 500))
test_mat = test_mat.astype(np.uint16)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=16)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/channel2/0/100:600/450:750/20:37/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel2',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/channel2/0/100:600/450:750/20:37/',
HTTP_ACCEPT='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='channel2',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint16)
data_mat = np.reshape(data_mat, (17, 300, 500), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例11: test_channel_uint64_cuboid_aligned_no_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint64_cuboid_aligned_no_offset_no_time_blosc(self):
""" Test uint64 data, cuboid aligned, no offset, no time samples"""
test_mat = np.random.randint(1, 256, (4, 128, 128))
test_mat = test_mat.astype(np.uint64)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=64)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/layer1/0/0:128/0:128/0:4/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:4', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/layer1/0/0:128/0:128/0:4/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='0:128', y_range='0:128', z_range='0:4', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint64)
data_mat = np.reshape(data_mat, (4, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例12: test_channel_uint64_cuboid_aligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint64_cuboid_aligned_offset_no_time_blosc(self):
""" Test uint64 data, cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 256, (4, 128, 128))
test_mat = test_mat.astype(np.uint64)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=64)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/layer1/0/128:256/256:384/16:20/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:20', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/layer1/0/128:256/256:384/16:20/',
accepts='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='128:256', y_range='256:384', z_range='16:20', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint64)
data_mat = np.reshape(data_mat, (4, 128, 128), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例13: test_channel_uint64_cuboid_unaligned_offset_no_time_blosc
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def test_channel_uint64_cuboid_unaligned_offset_no_time_blosc(self):
""" Test uint64 data, not cuboid aligned, offset, no time samples, blosc interface"""
test_mat = np.random.randint(1, 256, (17, 300, 500))
test_mat = test_mat.astype(np.uint64)
h = test_mat.tobytes()
bb = blosc.compress(h, typesize=64)
# Create request
factory = APIRequestFactory()
request = factory.post('/' + version + '/cutout/col1/exp1/layer1/0/100:600/450:750/20:37/', bb,
content_type='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Create Request to get data you posted
request = factory.get('/' + version + '/cutout/col1/exp1/layer1/0/100:600/450:750/20:37/',
HTTP_ACCEPT='application/blosc')
# log in user
force_authenticate(request, user=self.user)
# Make request
response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='layer1',
resolution='0', x_range='100:600', y_range='450:750', z_range='20:37', t_range=None).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Decompress
raw_data = blosc.decompress(response.content)
data_mat = np.fromstring(raw_data, dtype=np.uint64)
data_mat = np.reshape(data_mat, (17, 300, 500), order='C')
# Test for data equality (what you put in is what you got back!)
np.testing.assert_array_equal(data_mat, test_mat)
示例14: commit_ref_raw_val_from_db_val
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def commit_ref_raw_val_from_db_val(commit_db_val: bytes) -> DigestAndDbRefs:
"""Load and decompress a commit ref db_val into python object memory.
Parameters
----------
commit_db_val : bytes
Serialized and compressed representation of commit refs.
Returns
-------
DigestAndDbRefs
`digest` of the unpacked commit refs if desired for verification. `db_kvs`
Iterable of binary encoded key/value pairs making up the repo state at the
time of that commit. key/value pairs are already in sorted order.
"""
uncomp_db_raw = blosc.decompress(commit_db_val)
# if a commit has nothing in it (completely empty), the return from query == ()
# the stored data is b'' from which the hash is calculated. We manually set these
# values as the expected unpacking routine will not work correctly.
if uncomp_db_raw == b'':
refsDigest = _hash_func(b'')
raw_db_kv_list = ()
else:
raw_joined_kvs_list = uncomp_db_raw.split(CMT_REC_JOIN_KEY)
refsDigest = _commit_ref_joined_kv_digest(raw_joined_kvs_list)
raw_db_kv_list = tuple(map(tuple, map(bytes.split, raw_joined_kvs_list)))
return DigestAndDbRefs(digest=refsDigest, db_kvs=raw_db_kv_list)
示例15: commit_spec_raw_val_from_db_val
# 需要导入模块: import blosc [as 别名]
# 或者: from blosc import decompress [as 别名]
def commit_spec_raw_val_from_db_val(db_val: bytes) -> DigestAndUserSpec:
uncompressed_db_val = blosc.decompress(db_val)
digest = _hash_func(uncompressed_db_val)
commit_spec = json.loads(uncompressed_db_val)
user_spec = CommitUserSpec(**commit_spec)
return DigestAndUserSpec(digest=digest, user_spec=user_spec)