当前位置:网站首页>读取和保存zarr文件
读取和保存zarr文件
2022-07-06 09:28:00 【深山里的小白羊】
前言
zarr一种数据格式,和hdf文件有点类似,即一个文件里面可以包含很多不同的dataset
与hdf文件不同,直观上看hdf是一个单一的文件,而zarr是一个文件夹,里面还包含不同的子文件夹(相当于hdf中的dataset),子文件夹下面保存着数据
另一点,zarr分块保存数据,直白来讲,就是将一整块的数据划分成相同大小的子块,每个子块保存成一个文件,命名为*.*.*,这样处理的好处是对于大规模的医学图像非常友好
还有两个特殊的文件是.zarray和.zattrs,里面分别保存着数据特性和大小信息等等,例如
.zarray
.zattrs
读取
import zarr
import numpy as np
input_name = 'data.zarr'
dataset_name = 'volumes/raw'
f = zarr.open(input_name)
raw = f[dataset_name ]
print(raw.shape)
raw_data = raw[:]
保存
import zarr
import numpy as np
output_name = 'data.zarr'
dataset_name = 'volumes/raw'
root = zarr.open(output_name , mode='a')
shape = [1000, 1000, 1000] # 整个数据的大小,3D
chunk_size = [128, 128, 128] # 分块的大小
dtype = np.uint8 # 数据类型
compressor = {
'id': 'gzip', 'level': 5}
compressor = zarr.get_codec(compressor) # 压缩方式
dataset_name = dataset_name.lstrip('/')
ds = root.create_dataset(
dataset_name,
shape=shape,
chunks=chunk_size,
dtype=dtype,
compressor=compressor)
ds.attrs['resolution'] = [8, 8, 8]
ds.attrs['offset'] = [0, 0, 0]
ds[:] = np.ones(tuple(shape), dtype=dtype)
边栏推荐
- Pyside6 signal, slot
- Truck History
- Determine the Photo Position
- [exercise-4] (UVA 11988) broken keyboard = = (linked list)
- Gartner: five suggestions on best practices for zero trust network access
- TCP's three handshakes and four waves
- 【练习-7】Crossword Answers
- 1005. Maximized array sum after K negations
- China potato slicer market trend report, technical dynamic innovation and market forecast
- Ball Dropping
猜你喜欢
Vs2019 initial use
Basic Q & A of introductory C language
Penetration test (1) -- necessary tools, navigation
1013. Divide the array into three parts equal to and
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
Information security - threat detection - detailed design of NAT log access threat detection platform
C language is the watershed between low-level and high-level
渗透测试 ( 1 ) --- 必备 工具、导航
Pyside6 signal, slot
921. Minimum additions to make parentheses valid
随机推荐
[exercise-5] (UVA 839) not so mobile (balance)
Information security - security professional name | CVE | rce | POC | Vul | 0day
The concept of C language array
Borg maze (bfs+ minimum spanning tree) (problem solving report)
Penetration test (1) -- necessary tools, navigation
Determine the Photo Position
双向链表—全部操作
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
China's peripheral catheter market trend report, technological innovation and market forecast
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Research Report on shell heater industry - market status analysis and development prospect forecast
C language learning notes
Opencv learning log 19 skin grinding
想应聘程序员,您的简历就该这样写【精华总结】
628. Maximum product of three numbers
Opencv learning log 28 -- detect the red cup cover
Penetration test (7) -- vulnerability scanning tool Nessus
Essai de pénétration (1) - - outils nécessaires, navigation
China potato slicer market trend report, technical dynamic innovation and market forecast
【练习-7】(Uva 10976)Fractions Again?!(分数拆分)