当前位置:网站首页>读取和保存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)
边栏推荐
- 渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
- X-Forwarded-For详解、如何获取到客户端IP
- Data storage in memory & loading into memory to make the program run
- Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
- 【练习-6】(Uva 725)Division(除法)== 暴力
- 1855. Maximum distance of subscript alignment
- Information security - threat detection - detailed design of NAT log access threat detection platform
- [exercise -10] unread messages
- 信息安全-威胁检测引擎-常见规则引擎底座性能比较
- Frida hook so layer, protobuf data analysis
猜你喜欢
409. Longest palindrome
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
D - function (HDU - 6546) girls' competition
860. Lemonade change
【高老师UML软件建模基础】20级云班课习题答案合集
Penetration test (3) -- Metasploit framework (MSF)
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
Information security - threat detection engine - common rule engine base performance comparison
Determine the Photo Position
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
随机推荐
【练习4-1】Cake Distribution(分配蛋糕)
渗透测试 ( 4 ) --- Meterpreter 命令详解
【练习-6】(PTA)分而治之
[exercise -11] 4 values why sum is 0 (and 4 values of 0)
CEP used by Flink
Borg maze (bfs+ minimum spanning tree) (problem solving report)
【练习-10】 Unread Messages(未读消息)
[exercise-7] crossover answers
nodejs爬虫
1013. Divide the array into three parts equal to and
Programmers, what are your skills in code writing?
[exercise-5] (UVA 839) not so mobile (balance)
最全编程语言在线 API 文档
860. Lemonade change
Shell脚本编程
628. Maximum product of three numbers
C basic grammar
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
Understand what is a programming language in a popular way