当前位置:网站首页>读取和保存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)
边栏推荐
- Openwrt build Hello ipk
- 渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
- Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
- Penetration test (8) -- official document of burp Suite Pro
- Flink 使用之 CEP
- [exercise-3] (UVA 442) matrix chain multiplication
- Truck History
- Opencv learning log 28 -- detect the red cup cover
- [exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
- Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
猜你喜欢

409. Longest palindrome

1529. Minimum number of suffix flips
Frida hook so layer, protobuf data analysis

Penetration test (8) -- official document of burp Suite Pro
快速转 TypeScript 指南

Analysis of protobuf format of real-time barrage and historical barrage at station B

Borg maze (bfs+ minimum spanning tree) (problem solving report)

渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计

Penetration test (7) -- vulnerability scanning tool Nessus
随机推荐
The most complete programming language online API document
CEP used by Flink
Pyside6 signal, slot
Opencv learning log 30 -- histogram equalization
921. Minimum additions to make parentheses valid
Hdu-6025-prime sequence (girls' competition)
对iptables进行常规操作
Opencv learning log 33 Gaussian mean filtering
Determine the Photo Position
nodejs爬虫
PySide6 信号、槽
Opencv learning log 29 -- gamma correction
New to redis
Opencv learning log 31 -- background difference
1903. Maximum odd number in string
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
2027. Minimum number of operations to convert strings
[exercise-5] (UVA 839) not so mobile (balance)
B - Code Party (girls' competition)
[exercise-9] Zombie's Treasury test