本文整理汇总了Python中zarr.Group方法的典型用法代码示例。如果您正苦于以下问题:Python zarr.Group方法的具体用法?Python zarr.Group怎么用?Python zarr.Group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zarr
的用法示例。
在下文中一共展示了zarr.Group方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def execute(cls, ctx, op):
import zarr
fs = get_fs(op.path, None)
fs_map = FSMap(op.path, fs)
group = zarr.Group(store=fs_map, path=op.group)
array = group[op.dataset]
to_store = ctx[op.inputs[0].key]
axis_offsets = op.axis_offsets
shape = to_store.shape
array[tuple(slice(offset, offset + size)
for offset, size
in zip(axis_offsets, shape))] = to_store
ctx[op.outputs[0].key] = np.empty((0,) * to_store.ndim,
dtype=to_store.dtype)
示例2: _write_method
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def _write_method(cls: Type[T]) -> Callable[[zarr.Group, str, T], None]:
return _find_impl(cls, ZARR_WRITE_REGISTRY)
示例3: read_zarr
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def read_zarr(store: Union[str, Path, MutableMapping, zarr.Group]) -> AnnData:
"""\
Read from a hierarchical Zarr array store.
Parameters
----------
store
The filename, a :class:`~typing.MutableMapping`, or a Zarr storage class.
"""
if isinstance(store, Path):
store = str(store)
f = zarr.open(store, mode="r")
d = {}
for k in f.keys():
# Backwards compat
if k.startswith("raw."):
continue
if k in {"obs", "var"}:
d[k] = read_dataframe(f[k])
else: # Base case
d[k] = read_attribute(f[k])
d["raw"] = _read_legacy_raw(f, d.get("raw"), read_dataframe, read_attribute)
_clean_uns(d)
return AnnData(**d)
示例4: read_group
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def read_group(group: zarr.Group):
if "encoding-type" in group.attrs:
enctype = group.attrs["encoding-type"]
EncodingVersions[enctype].check(group.name, group.attrs["encoding-version"])
if enctype == "dataframe":
return read_dataframe(group)
elif enctype == "csr_matrix":
return read_csr(group)
elif enctype == "csc_matrix":
return read_csc(group)
# At the moment, just treat raw as normal group
return {k: read_attribute(group[k]) for k in group.keys()}
示例5: read_csr
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def read_csr(group: zarr.Group) -> sparse.csr_matrix:
return sparse.csr_matrix(
(group["data"], group["indices"], group["indptr"]), shape=group.attrs["shape"],
)
示例6: read_csc
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def read_csc(group: zarr.Group) -> sparse.csc_matrix:
return sparse.csc_matrix(
(group["data"], group["indices"], group["indptr"]), shape=group.attrs["shape"],
)
示例7: open_mask_group
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def open_mask_group(self):
"""Open the zarr group that contains the masks
Returns
-------
mask_group : zarr.Group
"""
mapper = self.mask_fs.get_mapper(self.mask_path)
zgroup = zarr.open_consolidated(mapper)
return zgroup
示例8: vtkjs_to_zarr
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def vtkjs_to_zarr(vtkjs, group, chunks=True):
"""Convert a vtk.js-like Python object to a Zarr Group.
Parameters
----------
vtkjs: dictionary, required
The vtk.js-like data structure to convert.
group: zarr.Group, required
The Zarr group to store the result.
chunks: bool or int or tuple of ints, optional
The chunk size passed to zarr.creation.create.
"""
for key, value in vtkjs.items():
if key == 'vtkClass':
group.attrs[key] = value
elif key == 'arrays':
for index, arr in enumerate(value):
vtkjs_to_zarr(arr,
group.create_group('arrays/' + str(index), True),
chunks=chunks)
elif isinstance(value, dict):
vtkjs_to_zarr(value,
group.create_group(key, True),
chunks=chunks)
elif isinstance(value, np.ndarray):
group.array(key, value, chunks=chunks)
else:
group.attrs[key] = value
return group
示例9: zarr_to_vtkjs
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def zarr_to_vtkjs(group):
"""Convert Zarr Group that contains vtk.js data structure to a Python-like object.
Parameters
----------
group: zarr.Group, required
The Zarr group to convert.
"""
def process_group(group, result):
for key, value in group.attrs.items():
result[key] = value
for name, value in group.arrays():
result[name] = np.asarray(value)
for name, value in group.groups():
if name == 'arrays':
nested = []
for index, subgroup in value.groups():
subresult = dict()
process_group(subgroup, subresult)
nested.append(subresult)
result[name] = nested
else:
nested = dict()
process_group(value, nested)
result[name] = nested
result = dict()
process_group(group, result)
return result
示例10: __init__
# 需要导入模块: import zarr [as 别名]
# 或者: from zarr import Group [as 别名]
def __init__(
self,
dataset: xr.Dataset,
model: Model,
zobject: Optional[Union[zarr.Group, MutableMapping, str]] = None,
encoding: Optional[EncodingDict] = None,
batch_dim: Optional[str] = None,
lock: Optional[Any] = None,
):
self.dataset = dataset
self.model = model
self.in_memory = False
self.consolidated = False
if isinstance(zobject, zarr.Group):
self.zgroup = zobject
elif zobject is None:
self.zgroup = zarr.group(store=zarr.MemoryStore())
self.in_memory = True
else:
self.zgroup = zarr.group(store=zobject)
self.output_vars = dataset.xsimlab.output_vars_by_clock
self.output_save_steps = dataset.xsimlab.get_output_save_steps()
if encoding is None:
encoding = {}
self.var_info = _get_var_info(dataset, model, encoding)
self.batch_dim = batch_dim
self.batch_size = get_batch_size(dataset, batch_dim)
self.mclock_dim = dataset.xsimlab.master_clock_dim
self.clock_sizes = dataset.xsimlab.clock_sizes
# initialize clock incrementers
self.clock_incs = self._init_clock_incrementers()
# ensure no dataset conflict in zarr group
znames = [vi["name"] for vi in self.var_info.values()]
ensure_no_dataset_conflict(self.zgroup, znames)
if lock is None:
self.lock = DummyLock()
else:
self.lock = lock