提供分片Zarr存储。
项目描述
shardedstore
提供分片Zarr存储。
功能
- 对于大型Zarr存储,避免过多对象或极其大的对象,从而绕过文件系统inode使用和对象存储限制。
- 性能敏感的实现。
- 使用现有的Zarr v2存储。
- 混合和匹配分片存储类型。
- 使用JSON序列化和反序列化ShardedStore。
- 分片组或数组块。
- 轻松对存储分片执行转换。
安装
pip install shardedstore
示例
from shardedstore import ShardedStore, array_shard_directory_store, to_zip_store_with_prefix
from zarr.storage import DirectoryStore
# xarray example, but works with zarr in general
import xarray as xr
from datatree import DataTree, open_datatree
import json
import numpy as np
import os
创建组件分片存储
base_store = DirectoryStore("base.zarr")
shard1 = DirectoryStore("shard1.zarr")
shard2 = DirectoryStore("shard2.zarr")
array_shards1 = array_shard_directory_store("array_shards1")
array_shards2 = array_shard_directory_store("array_shards2")
为示例生成数据
# xarray-datatree Quick Overview
data = xr.DataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]})
# Sharded array dimensions must have a chunk shape of 1.
data = data.chunk([1,2])
ds = xr.Dataset(dict(foo=data, bar=("x", [1, 2]), baz=np.pi))
ds2 = ds.interp(coords={"x": [10, 12, 14, 16, 18, 20]})
ds2 = ds2.chunk({'x':1, 'y':2})
ds3 = xr.Dataset(
dict(people=["alice", "bob"], heights=("people", [1.57, 1.82])),
coords={"species": "human"},
)
dt = DataTree.from_dict({"simulation/coarse": ds, "simulation/fine": ds2, "/": ds3})
单体存储
single_store = DirectoryStore("single.zarr")
dt.to_zarr(single_store)
展示在组和数组上分片的分片存储。
数组在1维上分片。
sharded_store = ShardedStore(base_store,
{'people': shard1, 'species': shard2},
{'simulation/coarse/foo': (1, array_shards1), 'simulation/fine/foo': (1, array_shards2)})
dt.to_zarr(sharded_store)
序列化/反序列化
config = sharded_store.get_config()
config_str = json.dumps(config)
config = json.loads(config_str)
sharded_store = ShardedStore.from_config(config)
验证
from_single = open_datatree(single_store, engine='zarr').compute()
from_sharded = open_datatree(sharded_store, engine='zarr').compute()
assert from_single.identical(from_sharded)
使用map_shards
在组件分片上运行转换
to_zip_stores = to_zip_store_with_prefix("zip_stores")
zip_sharded_stores = sharded_store.map_shards(to_zip_stores)
开发
欢迎并感谢贡献。
git clone https://github.com/thewtex/shardedstore
cd shardedstore
pip install -e ".[test]"
pytest
项目详情
下载文件
下载适合您平台文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源分发
shardedstore-0.3.1.tar.gz (13.1 kB 查看哈希值)
构建版本
shardedstore-0.3.1-py3-none-any.whl (10.9 kB 查看哈希值)
关闭
shardedstore-0.3.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a1b75197274f13dc696fcb22c5d63073f48f83f6538f7abe2de16fa7a3b9c285 |
|
MD5 | 1ab3635b8d9b2fafb48d187955966b35 |
|
BLAKE2b-256 | e49c5d592b01cd56032a3818ef1e55d5de96f64e6ce78d253fcf99875b8dc5e3 |
关闭
shardedstore-0.3.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7bc68fb78f400a4d354c923c1c122ad586eea4f346289d00b9b44efd8e84de26 |
|
MD5 | dc554c9ee6e4ef0136fc1d06c79ddda1 |
|
BLAKE2b-256 | cf9a3b64d4b931e1d2c1c1730394a1870d3aa88659e949893462dc0792048770 |