Async API
zarr.api.asynchronous ¶
array
async
¶
array(
data: ArrayLike | Array, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array filled with data
.
Parameters:
-
data
(array_like
) –The data to fill the array with.
-
**kwargs
(Any
, default:{}
) –Passed through to
create
.
Returns:
-
array
(array
) –The new array.
Source code in zarr/api/asynchronous.py
consolidate_metadata
async
¶
consolidate_metadata(
store: StoreLike,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
) -> AsyncGroup
Consolidate the metadata of all nodes in a hierarchy.
Upon completion, the metadata of the root node in the Zarr hierarchy will be
updated to include all the metadata of child nodes. For Stores that do
not support consolidated metadata, this operation raises a TypeError
.
Parameters:
-
store
(StoreLike
) –The store-like object whose metadata you wish to consolidate.
-
path
(str
, default:None
) –A path to a group in the store to consolidate at. Only children below that group will be consolidated.
By default, the root node is used so all the metadata in the store is consolidated.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format of the hierarchy. By default the zarr format is inferred.
Returns:
-
group
(AsyncGroup
) –The group, with the
consolidated_metadata
field set to include the metadata of each child node. If the Store doesn't support consolidated metadata, this function raises aTypeError
. SeeStore.supports_consolidated_metadata
.
Source code in zarr/api/asynchronous.py
copy
async
¶
copy_all
async
¶
copy_store
async
¶
create
async
¶
create(
shape: tuple[int, ...] | int,
*,
chunks: tuple[int, ...] | int | bool | None = None,
dtype: ZDTypeLike | None = None,
compressor: CompressorLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
store: StoreLike | None = None,
synchronizer: Any | None = None,
overwrite: bool = False,
path: PathLike | None = None,
chunk_store: StoreLike | None = None,
filters: Iterable[dict[str, JSON] | Numcodec]
| None = None,
cache_metadata: bool | None = None,
cache_attrs: bool | None = None,
read_only: bool | None = None,
object_codec: Codec | None = None,
dimension_separator: Literal[".", "/"] | None = None,
write_empty_chunks: bool | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
chunk_shape: tuple[int, ...] | int | None = None,
chunk_key_encoding: ChunkKeyEncoding
| tuple[Literal["default"], Literal[".", "/"]]
| tuple[Literal["v2"], Literal[".", "/"]]
| None = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
config: ArrayConfigLike | None = None,
**kwargs: Any,
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array.
Parameters:
-
shape
(int or tuple of ints
) –Array shape.
-
chunks
(int or tuple of ints
, default:None
) –Chunk shape. If True, will be guessed from
shape
anddtype
. If False, will be set toshape
, i.e., single chunk for the whole array. If an int, the chunk size in each dimension will be given by the value ofchunks
. Default is True. -
dtype
(str or dtype
, default:None
) –NumPy dtype.
-
compressor
(Codec
, default:'auto'
) –Primary compressor to compress chunk data. Zarr format 2 only. Zarr format 3 arrays should use
codecs
instead.If neither
compressor
norfilters
are provided, the default compressorzarr.codecs.ZstdCodec
is used.If
compressor
is set toNone
, no compression is used. -
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array.
-
order
(('C', 'F')
, default:'C'
) –Deprecated in favor of the
config
keyword argument. Pass{'order': <value>}
tocreate
instead of using this parameter. Memory layout to be used within each chunk. If not specified, thearray.order
parameter in the global config will be used. -
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
synchronizer
(object
, default:None
) –Array synchronizer.
-
overwrite
(bool
, default:False
) –If True, delete all pre-existing data in
store
atpath
before creating the array. -
path
(str
, default:None
) –Path under which array is stored.
-
chunk_store
(StoreLike or None
, default:None
) –Separate storage for chunks. If not provided,
store
will be used for storage of both chunks and metadata. -
filters
(Iterable[Codec] | Literal['auto']
, default:None
) –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, and these values must be instances of
zarr.abc.codec.ArrayArrayCodec
, or a dict representations ofzarr.abc.codec.ArrayArrayCodec
.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the the order if your filters is consistent with the behavior of each filter.
The default value of
"auto"
instructs Zarr to use a default used based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are empty. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8
orzarr.dtype.VariableLengthUTF8
. In these cases, the default filters contains a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None
. -
cache_metadata
(bool
, default:None
) –If True, array configuration metadata will be cached for the lifetime of the object. If False, array metadata will be reloaded prior to all data access and modification operations (may incur overhead depending on storage and data access pattern).
-
cache_attrs
(bool
, default:None
) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
read_only
(bool
, default:None
) –True if array should be protected against modification.
-
object_codec
(Codec
, default:None
) –A codec to encode object arrays, only needed if dtype=object.
-
dimension_separator
(('.', '/')
, default:'.'
) –Separator placed between the dimensions of a chunk. Zarr format 2 only. Zarr format 3 arrays should use
chunk_key_encoding
instead. -
write_empty_chunks
(bool
, default:None
) –Deprecated in favor of the
config
keyword argument. Pass{'write_empty_chunks': <value>}
tocreate
instead of using this parameter. If True, all chunks will be stored regardless of their contents. If False, each chunk is compared to the array's fill value prior to storing. If a chunk is uniformly equal to the fill value, then that chunk is not be stored, and the store entry for that chunk's key is deleted. -
zarr_format
((2, 3, None)
, default:2
) –The Zarr format to use when creating an array. The default is
None
, which instructs Zarr to choose the default Zarr format value defined in the runtime configuration. -
meta_array
(array - like
, default:None
) –Not implemented.
-
attributes
(dict[str, JSON]
, default:None
) –A dictionary of user attributes to store with the array.
-
chunk_shape
(int or tuple of ints
, default:None
) –The shape of the Array's chunks (default is None). Zarr format 3 only. Zarr format 2 arrays should use
chunks
instead. -
chunk_key_encoding
(ChunkKeyEncoding
, default:None
) –A specification of how the chunk keys are represented in storage. Zarr format 3 only. Zarr format 2 arrays should use
dimension_separator
instead. Default is("default", "/")
. -
codecs
(Sequence of Codecs or dicts
, default:None
) –An iterable of Codec or dict serializations of Codecs. Zarr V3 only.
The elements of
codecs
specify the transformation from array values to stored bytes. Zarr format 3 only. Zarr format 2 arrays should usefilters
andcompressor
instead.If no codecs are provided, default codecs will be used based on the data type of the array. For most data types, the default codecs are the tuple
(BytesCodec(), ZstdCodec())
; data types that require a specialzarr.abc.codec.ArrayBytesCodec
, like variable-length strings or bytes, will use thezarr.abc.codec.ArrayBytesCodec
required for the data type instead ofzarr.codecs.BytesCodec
. -
dimension_names
(Iterable[str | None] | None = None
, default:None
) –An iterable of dimension names. Zarr format 3 only.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
config
(ArrayConfigLike
, default:None
) –Runtime configuration of the array. If provided, will override the default values from
zarr.config.array
.
Returns:
-
z
(array
) –The array.
Source code in zarr/api/asynchronous.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
|
create_array
async
¶
create_array(
store: StoreLike,
*,
name: str | None = None,
shape: ShapeLike | None = None,
dtype: ZDTypeLike | None = None,
data: ndarray[Any, dtype[Any]] | None = None,
chunks: tuple[int, ...] | Literal["auto"] = "auto",
shards: ShardsLike | None = None,
filters: FiltersLike = "auto",
compressors: CompressorsLike = "auto",
serializer: SerializerLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
write_data: bool = True,
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
name
(str or None
, default:None
) –The name of the array within the store. If
name
isNone
, the array will be located at the root of the store. -
shape
(ShapeLike
, default:None
) –Shape of the array. Must be
None
ifdata
is provided. -
dtype
(ZDTypeLike | None
, default:None
) –Data type of the array. Must be
None
ifdata
is provided. -
data
(ndarray
, default:None
) –Array-like data to use for initializing the array. If this parameter is provided, the
shape
anddtype
parameters must beNone
. -
chunks
(tuple[int, ...] | Literal['auto']
, default:"auto"
) –Chunk shape of the array. If chunks is "auto", a chunk shape is guessed based on the shape of the array and the dtype.
-
shards
(tuple[int, ...]
, default:None
) –Shard shape of the array. The default value of
None
results in no sharding at all. -
filters
(Iterable[Codec] | Literal['auto']
, default:'auto'
) –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array,
and these values must be instances of
zarr.abc.codec.ArrayArrayCodec
, or a dict representations ofzarr.abc.codec.ArrayArrayCodec
.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the the order if your filters is consistent with the behavior of each filter.
The default value of
"auto"
instructs Zarr to use a default used based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are empty. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8
orzarr.dtype.VariableLengthUTF8
. In these cases, the default filters contains a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None
. -
compressors
(Iterable[Codec]
, default:'auto'
) –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors my be provided for Zarr format 3. If no
compressors
are provided, a default set of compressors will be used. These defaults can be changed by modifying the value ofarray.v3_default_compressors
inzarr.config
. UseNone
to omit default compressors.For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2. If no
compressor
is provided, a default compressor will be used. inzarr.config
. UseNone
to omit the default compressor. -
serializer
(dict[str, JSON] | ArrayBytesCodec
, default:'auto'
) –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion. If no
serializer
is provided, a default serializer will be used. These defaults can be changed by modifying the value ofarray.v3_default_serializer
inzarr.config
. -
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array.
-
order
(('C', 'F')
, default:"C"
) –The memory of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
config
parameter, e.g.{'config': 'C'}
. If noorder
is provided, a default order will be used. This default can be changed by modifying the value ofarray.order
inzarr.config
. -
zarr_format
((2, 3)
, default:2
) –The zarr format to use when saving.
-
attributes
(dict
, default:None
) –Attributes for the array.
-
chunk_key_encoding
(ChunkKeyEncodingLike
, default:None
) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}
. For Zarr format 2, the default is{"name": "v2", "separator": "."}}
. -
dimension_names
(Iterable[str]
, default:None
) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
overwrite
(bool
, default:False
) –Whether to overwrite an array with the same name in the store, if one exists. If
True
, all existing paths in the store will be deleted. -
config
(ArrayConfigLike
, default:None
) –Runtime configuration for the array.
-
write_data
(bool
, default:True
) –If a pre-existing array-like object was provided to this function via the
data
parameter thenwrite_data
determines whether the values in that array-like object should be written to the Zarr array created by this function. Ifwrite_data
isFalse
, then the array will be left empty.
Returns:
-
AsyncArray
–The array.
Examples:
>>> import zarr
>>> store = zarr.storage.MemoryStore(mode='w')
>>> async_arr = await zarr.api.asynchronous.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='i4',
>>> fill_value=0)
<AsyncArray memory://140349042942400 shape=(100, 100) dtype=int32>
Source code in zarr/core/array.py
4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 |
|
create_group
async
¶
create_group(
*,
store: StoreLike,
path: str | None = None,
overwrite: bool = False,
zarr_format: ZarrFormat | None = None,
attributes: dict[str, Any] | None = None,
storage_options: dict[str, Any] | None = None,
) -> AsyncGroup
Create a group.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
path
(str
, default:None
) –Group path within store.
-
overwrite
(bool
, default:False
) –If True, pre-existing data at
path
will be deleted before creating the group. -
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving. If no
zarr_format
is provided, the default format will be used. This default can be changed by modifying the value ofdefault_zarr_format
inzarr.config
. -
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
AsyncGroup
–The new group.
Source code in zarr/api/asynchronous.py
create_hierarchy
async
¶
create_hierarchy(
*,
store: Store,
nodes: dict[
str,
GroupMetadata | ArrayV2Metadata | ArrayV3Metadata,
],
overwrite: bool = False,
) -> AsyncIterator[
tuple[
str,
AsyncGroup
| AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata],
]
]
Create a complete zarr hierarchy from a collection of metadata objects.
This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
will be inserted as needed. For example, an input like
{'a/b': GroupMetadata}
will be parsed to
{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}
After input parsing, this function then creates all the nodes in the hierarchy concurrently.
Arrays and Groups are yielded in the order they are created. This order is not stable and should not be relied on.
Parameters
Parameters
store : Store
The storage backend to use.
nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]
A dictionary defining the hierarchy. The keys are the paths of the nodes in the hierarchy,
relative to the root of the Store
. The root of the store can be specified with the empty
string ''
. The values are instances of GroupMetadata
or ArrayMetadata
. Note that
all values must have the same zarr_format
-- it is an error to mix zarr versions in the
same hierarchy.
Leading "/" characters from keys will be removed.
overwrite : bool
Whether to overwrite existing nodes. Defaults to False
, in which case an error is
raised instead of overwriting an existing array or group.
This function will not erase an existing group unless that group is explicitly named in
``nodes``. If ``nodes`` defines implicit groups, e.g. ``{`'a/b/c': GroupMetadata}``, and a
group already exists at path ``a``, then this function will leave the group at ``a`` as-is.
Yields:
-
tuple[str, AsyncGroup | AsyncArray]
–This function yields (path, node) pairs, in the order the nodes were created.
Examples:
>>> from zarr.api.asynchronous import create_hierarchy
>>> from zarr.storage import MemoryStore
>>> from zarr.core.group import GroupMetadata
>>> import asyncio
>>> store = MemoryStore()
>>> nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
>>> async def run():
... print(dict([x async for x in create_hierarchy(store=store, nodes=nodes)]))
>>> asyncio.run(run())
# {'a': <AsyncGroup memory://140345143770112/a>, '': <AsyncGroup memory://140345143770112>}
Source code in zarr/core/group.py
3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 |
|
empty
async
¶
empty(
shape: tuple[int, ...], **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an empty array with the specified shape. The contents will be filled with the specified fill value or zeros if no fill value is provided.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/asynchronous.py
empty_like
async
¶
empty_like(
a: ArrayLike, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an empty array like a
. The contents will be filled with the
array's fill value or zeros if no fill value is provided.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/asynchronous.py
from_array
async
¶
from_array(
store: StoreLike,
*,
data: Array | ArrayLike,
write_data: bool = True,
name: str | None = None,
chunks: Literal["auto", "keep"]
| tuple[int, ...] = "keep",
shards: ShardsLike | None | Literal["keep"] = "keep",
filters: FiltersLike | Literal["keep"] = "keep",
compressors: CompressorsLike | Literal["keep"] = "keep",
serializer: SerializerLike | Literal["keep"] = "keep",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array from an existing array or array-like.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
data
(Array | array - like
) –The array to copy.
-
write_data
(bool
, default:True
) –Whether to copy the data from the input array to the new array. If
write_data
isFalse
, the new array will be created with the same metadata as the input array, but without any data. -
name
(str or None
, default:None
) –The name of the array within the store. If
name
isNone
, the array will be located at the root of the store. -
chunks
(tuple[int, ...] or 'auto' or 'keep'
, default:'keep'
) –Chunk shape of the array. Following values are supported:
- "auto": Automatically determine the chunk shape based on the array's shape and dtype.
- "keep": Retain the chunk shape of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the chunk shape.
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
-
shards
(tuple[int, ...]
, default:'keep'
) –Shard shape of the array. Following values are supported:
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
- "keep": Retain the shard shape of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the shard shape.
- None: No sharding.
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
-
filters
(Iterable[Codec] | Literal['auto', 'keep']
, default:'keep'
) –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, and these values must be instances of
zarr.abc.codec.ArrayArrayCodec
, or a dict representations ofzarr.abc.codec.ArrayArrayCodec
.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the the order if your filters is consistent with the behavior of each filter.
The default value of
"keep"
instructs Zarr to inferfilters
fromdata
. If that inference is not possible, Zarr will fall back to the behavior specified by"auto"
, which is to choose default filters based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are the empty tuple()
. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8
orzarr.dtype.VariableLengthUTF8
. In these cases, the default filters is a tuple with a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None
. -
compressors
(Iterable[Codec] or 'auto' or 'keep'
, default:'keep'
) –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors my be provided for Zarr format 3.
For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2.
Following values are supported:
- Iterable[Codec]: List of compressors to apply to the array.
- "auto": Automatically determine the compressors based on the array's dtype.
- "keep": Retain the compressors of the input array if it is a zarr Array.
If no
compressors
are provided, defaults to "keep" if data is a zarr Array, otherwise "auto". -
serializer
(dict[str, JSON] | ArrayBytesCodec or 'auto' or 'keep'
, default:'keep'
) –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion.
Following values are supported:
- dict[str, JSON]: A dict representation of an
ArrayBytesCodec
. - ArrayBytesCodec: An instance of
ArrayBytesCodec
. - "auto": a default serializer will be used. These defaults can be changed by modifying the value of
array.v3_default_serializer
inzarr.config
. - "keep": Retain the serializer of the input array if it is a zarr Array.
- dict[str, JSON]: A dict representation of an
-
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array. If not specified, defaults to the fill value of the data array.
-
order
(('C', 'F')
, default:"C"
) –The memory of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
config
parameter, e.g.{'config': 'C'}
. If not specified, defaults to the memory order of the data array. -
zarr_format
((2, 3)
, default:2
) –The zarr format to use when saving. If not specified, defaults to the zarr format of the data array.
-
attributes
(dict
, default:None
) –Attributes for the array. If not specified, defaults to the attributes of the data array.
-
chunk_key_encoding
(ChunkKeyEncoding
, default:None
) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}
. For Zarr format 2, the default is{"name": "v2", "separator": "."}}
. If not specified and the data array has the same zarr format as the target array, the chunk key encoding of the data array is used. -
dimension_names
(Iterable[str | None] | None
, default:None
) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter. If not specified, defaults to the dimension names of the data array.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
overwrite
(bool
, default:False
) –Whether to overwrite an array with the same name in the store, if one exists.
-
config
(ArrayConfig or ArrayConfigLike
, default:None
) –Runtime configuration for the array.
Returns:
-
AsyncArray
–The array.
Examples:
Create an array from an existing Array::
>>> import zarr
>>> store = zarr.storage.MemoryStore()
>>> store2 = zarr.storage.LocalStore('example.zarr')
>>> arr = zarr.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='int32',
>>> fill_value=0)
>>> arr2 = await zarr.api.asynchronous.from_array(store2, data=arr)
<AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
Create an array from an existing NumPy array::
>>> arr3 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=np.arange(10000, dtype='i4').reshape(100, 100),
>>> )
<AsyncArray memory://123286956732800 shape=(100, 100) dtype=int32>
Create an array from any array-like object::
>>> arr4 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=[[1, 2], [3, 4]],
>>> )
<AsyncArray memory://123286959761024 shape=(2, 2) dtype=int64>
>>> await arr4.getitem(...)
array([[1, 2],[3, 4]])
Create an array from an existing Array without copying the data::
>>> arr5 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=Array(arr4),
>>> write_data=False,
>>> )
<AsyncArray memory://140678602965568 shape=(2, 2) dtype=int64>
>>> await arr5.getitem(...)
array([[0, 0],[0, 0]])
Source code in zarr/core/array.py
4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 |
|
full
async
¶
full(
shape: tuple[int, ...], fill_value: Any, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array, with fill_value
being used as the default value for
uninitialized portions of the array.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
fill_value
(scalar
) –Fill value.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/asynchronous.py
full_like
async
¶
full_like(
a: ArrayLike, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create a filled array like a
.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/asynchronous.py
group
async
¶
group(
*,
store: StoreLike | None = None,
overwrite: bool = False,
chunk_store: StoreLike | None = None,
cache_attrs: bool | None = None,
synchronizer: Any | None = None,
path: str | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
storage_options: dict[str, Any] | None = None,
) -> AsyncGroup
Create a group.
Parameters:
-
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
overwrite
(bool
, default:False
) –If True, delete any pre-existing data in
store
atpath
before creating the group. -
chunk_store
(StoreLike or None
, default:None
) –Separate storage for chunks. Not implemented.
-
cache_attrs
(bool
, default:None
) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
synchronizer
(object
, default:None
) –Array synchronizer.
-
path
(str
, default:None
) –Group path within store.
-
meta_array
(array - like
, default:None
) –An array instance to use for determining arrays to create and return to users. Use
numpy.empty(())
by default. -
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
g
(group
) –The new group.
Source code in zarr/api/asynchronous.py
load
async
¶
load(
*,
store: StoreLike,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
zarr_version: ZarrFormat | None = None,
) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]
Load data from an array or group into memory.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
path
(str or None
, default:None
) –The path within the store from which to load.
Returns:
-
out
–If the path contains an array, out will be a numpy array. If the path contains a group, out will be a dict-like object where keys are array names and values are numpy arrays.
See Also
save
Notes
If loading data from a group of arrays, data will not be immediately loaded into memory. Rather, arrays will be loaded into memory as they are requested.
Source code in zarr/api/asynchronous.py
ones
async
¶
ones(
shape: tuple[int, ...], **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array, with one being used as the default value for uninitialized portions of the array.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/asynchronous.py
ones_like
async
¶
ones_like(
a: ArrayLike, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array of ones like a
.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/asynchronous.py
open
async
¶
open(
*,
store: StoreLike | None = None,
mode: AccessModeLiteral | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
| AsyncGroup
)
Convenience function to open a group or array using file-mode-like semantics.
Parameters:
-
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
mode
(('r', 'r+', 'a', 'w', 'w-')
, default:'r'
) –Persistence mode: 'r' means read only (must exist); 'r+' means read/write (must exist); 'a' means read/write (create if doesn't exist); 'w' means create (overwrite if exists); 'w-' means create (fail if exists). If the store is read-only, the default is 'r'; otherwise, it is 'a'.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
path
(str or None
, default:None
) –The path within the store to open.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs
(Any
, default:{}
) –Additional parameters are passed through to
zarr.creation.open_array
oropen_group
.
Returns:
Source code in zarr/api/asynchronous.py
open_array
async
¶
open_array(
*,
store: StoreLike | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: PathLike = "",
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Open an array using file-mode-like semantics.
Parameters:
-
store
(StoreLike
, default:None
) –Store or path to directory in file system or name of zip file.
-
zarr_version
((2, 3, None)
, default:2
) –The zarr format to use when saving. Deprecated in favor of zarr_format.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
path
(str
, default:''
) –Path in store to array.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs
(Any
, default:{}
) –Any keyword arguments to pass to
create
.
Returns:
-
AsyncArray
–The opened array.
Source code in zarr/api/asynchronous.py
open_consolidated
async
¶
open_consolidated(
*args: Any,
use_consolidated: Literal[True] = True,
**kwargs: Any,
) -> AsyncGroup
Alias for open_group
with use_consolidated=True
.
Source code in zarr/api/asynchronous.py
open_group
async
¶
open_group(
store: StoreLike | None = None,
*,
mode: AccessModeLiteral = "a",
cache_attrs: bool | None = None,
synchronizer: Any = None,
path: str | None = None,
chunk_store: StoreLike | None = None,
storage_options: dict[str, Any] | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
use_consolidated: bool | str | None = None,
) -> AsyncGroup
Open a group using file-mode-like semantics.
Parameters:
-
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
Strings are interpreted as paths on the local file system and used as the
root
argument to zarr.storage.LocalStore.Dictionaries are used as the
store_dict
argument in zarr.storage.MemoryStore.By default (
store=None
) a new zarr.storage.MemoryStore is created. -
mode
(('r', 'r+', 'a', 'w', 'w-')
, default:'r'
) –Persistence mode: 'r' means read only (must exist); 'r+' means read/write (must exist); 'a' means read/write (create if doesn't exist); 'w' means create (overwrite if exists); 'w-' means create (fail if exists).
-
cache_attrs
(bool
, default:None
) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
synchronizer
(object
, default:None
) –Array synchronizer.
-
path
(str
, default:None
) –Group path within store.
-
chunk_store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
meta_array
(array - like
, default:None
) –An array instance to use for determining arrays to create and return to users. Use
numpy.empty(())
by default. -
attributes
(dict
, default:None
) –A dictionary of JSON-serializable values with user-defined attributes.
-
use_consolidated
(bool or str
, default:None
) –Whether to use consolidated metadata.
By default, consolidated metadata is used if it's present in the store (in the
zarr.json
for Zarr format 3 and in the.zmetadata
file for Zarr format 2).To explicitly require consolidated metadata, set
use_consolidated=True
, which will raise an exception if consolidated metadata is not found.To explicitly not use consolidated metadata, set
use_consolidated=False
, which will fall back to using the regular, non consolidated metadata.Zarr format 2 allowed configuring the key storing the consolidated metadata (
.zmetadata
by default). Specify the custom key asuse_consolidated
to load consolidated metadata from a non-default key.
Returns:
-
g
(group
) –The new group.
Source code in zarr/api/asynchronous.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
|
open_like
async
¶
open_like(
a: ArrayLike, path: str, **kwargs: Any
) -> (
AsyncArray[ArrayV3Metadata]
| AsyncArray[ArrayV2Metadata]
)
Open a persistent array like a
.
Parameters:
-
a
(Array
) –The shape and data-type of a define these same attributes of the returned array.
-
path
(str
) –The path to the new array.
-
**kwargs
(Any
, default:{}
) –Any keyword arguments to pass to the array constructor.
Returns:
-
AsyncArray
–The opened array.
Source code in zarr/api/asynchronous.py
save
async
¶
save(
store: StoreLike,
*args: NDArrayLike,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
**kwargs: Any,
) -> None
Convenience function to save an array or group of arrays to the local file system.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
*args
(ndarray
, default:()
) –NumPy arrays with data to save.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
path
(str or None
, default:None
) –The path within the group where the arrays will be saved.
-
**kwargs
(Any
, default:{}
) –NumPy arrays with data to save.
Source code in zarr/api/asynchronous.py
save_array
async
¶
save_array(
store: StoreLike,
arr: NDArrayLike,
*,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> None
Convenience function to save a NumPy array to the local file system, following a similar API to the NumPy save() function.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
arr
(ndarray
) –NumPy array with data to save.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving. The default is
None
, which will use the default Zarr format defined in the global configuration object. -
path
(str or None
, default:None
) –The path within the store where the array will be saved.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs
(Any
, default:{}
) –Passed through to
create
, e.g., compressor.
Source code in zarr/api/asynchronous.py
save_group
async
¶
save_group(
store: StoreLike,
*args: NDArrayLike,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: NDArrayLike,
) -> None
Convenience function to save several NumPy arrays to the local file system, following a similar API to the NumPy savez()/savez_compressed() functions.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
*args
(ndarray
, default:()
) –NumPy arrays with data to save.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
path
(str or None
, default:None
) –Path within the store where the group will be saved.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs
(NDArrayLike
, default:{}
) –NumPy arrays with data to save.
Source code in zarr/api/asynchronous.py
tree
async
¶
tree(
grp: AsyncGroup,
expand: bool | None = None,
level: int | None = None,
) -> Any
Provide a rich display of the hierarchy.
Deprecated
zarr.tree()
is deprecated since v3.0.0 and will be removed in a future release.
Use group.tree()
instead.
Parameters:
-
grp
(Group
) –Zarr or h5py group.
-
expand
(bool
, default:None
) –Only relevant for HTML representation. If True, tree will be fully expanded.
-
level
(int
, default:None
) –Maximum depth to descend into hierarchy.
Returns:
-
TreeRepr
–A pretty-printable object displaying the hierarchy.
Source code in zarr/api/asynchronous.py
zeros
async
¶
zeros(
shape: tuple[int, ...], **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array, with zero being used as the default value for uninitialized portions of the array.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/asynchronous.py
zeros_like
async
¶
zeros_like(
a: ArrayLike, **kwargs: Any
) -> (
AsyncArray[ArrayV2Metadata]
| AsyncArray[ArrayV3Metadata]
)
Create an array of zeros like a
.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.