|
47 | 47 | "create_array", |
48 | 48 | "empty", |
49 | 49 | "empty_like", |
| 50 | + "from_array", |
50 | 51 | "full", |
51 | 52 | "full_like", |
52 | 53 | "group", |
@@ -893,6 +894,138 @@ def create_array( |
893 | 894 | ) |
894 | 895 |
|
895 | 896 |
|
| 897 | +def from_array( |
| 898 | + data: Array, |
| 899 | + store: str | StoreLike, |
| 900 | + *, |
| 901 | + name: str | None = None, |
| 902 | + chunks: ChunkCoords | Literal["auto"] = "auto", |
| 903 | + shards: ShardsLike | None = None, |
| 904 | + filters: FiltersLike = "auto", |
| 905 | + compressors: CompressorsLike = "auto", |
| 906 | + serializer: SerializerLike = "auto", |
| 907 | + fill_value: Any | None = None, |
| 908 | + order: MemoryOrder | None = None, |
| 909 | + zarr_format: ZarrFormat | None = 3, |
| 910 | + attributes: dict[str, JSON] | None = None, |
| 911 | + chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingLike | None = None, |
| 912 | + dimension_names: Iterable[str] | None = None, |
| 913 | + storage_options: dict[str, Any] | None = None, |
| 914 | + overwrite: bool = False, |
| 915 | + config: ArrayConfig | ArrayConfigLike | None = None, |
| 916 | +) -> Array: |
| 917 | + """Create an array from an existing array. |
| 918 | +
|
| 919 | + Parameters |
| 920 | + ---------- |
| 921 | + data : Array |
| 922 | + The array to copy. |
| 923 | + store : str or Store |
| 924 | + Store or path to directory in file system or name of zip file for the new array. |
| 925 | + name : str or None, optional |
| 926 | + The name of the array within the store. If ``name`` is ``None``, the array will be located |
| 927 | + at the root of the store. |
| 928 | + chunks : ChunkCoords, optional |
| 929 | + Chunk shape of the array. |
| 930 | + If not specified, defaults to the chunk shape of the data array. |
| 931 | + shards : ChunkCoords, optional |
| 932 | + Shard shape of the array. The default value of ``None`` results in no sharding at all. |
| 933 | + filters : Iterable[Codec], optional |
| 934 | + Iterable of filters to apply to each chunk of the array, in order, before serializing that |
| 935 | + chunk to bytes. |
| 936 | +
|
| 937 | + For Zarr format 3, a "filter" is a codec that takes an array and returns an array, |
| 938 | + and these values must be instances of ``ArrayArrayCodec``, or dict representations |
| 939 | + of ``ArrayArrayCodec``. |
| 940 | +
|
| 941 | + For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the |
| 942 | + the order if your filters is consistent with the behavior of each filter. |
| 943 | +
|
| 944 | + If no ``filters`` are provided, defaults to the filters of the data array. |
| 945 | + compressors : Iterable[Codec], optional |
| 946 | + List of compressors to apply to the array. Compressors are applied in order, and after any |
| 947 | + filters are applied (if any are specified) and the data is serialized into bytes. |
| 948 | +
|
| 949 | + For Zarr format 3, a "compressor" is a codec that takes a bytestream, and |
| 950 | + returns another bytestream. Multiple compressors my be provided for Zarr format 3. |
| 951 | +
|
| 952 | + For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may |
| 953 | + be provided for Zarr format 2. |
| 954 | +
|
| 955 | + If no ``compressors`` are provided, defaults to the compressors of the data array. |
| 956 | + serializer : dict[str, JSON] | ArrayBytesCodec, optional |
| 957 | + Array-to-bytes codec to use for encoding the array data. |
| 958 | + Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion. |
| 959 | +
|
| 960 | + If no ``serializer`` is provided, defaults to the serializer of the input array. |
| 961 | + fill_value : Any, optional |
| 962 | + Fill value for the array. |
| 963 | + If not specified, defaults to the fill value of the data array. |
| 964 | + order : {"C", "F"}, optional |
| 965 | + The memory of the array (default is "C"). |
| 966 | + For Zarr format 2, this parameter sets the memory order of the array. |
| 967 | + For Zarr format 3, this parameter is deprecated, because memory order |
| 968 | + is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory |
| 969 | + order for Zarr format 3 arrays is via the ``config`` parameter, e.g. ``{'config': 'C'}``. |
| 970 | + If not specified, defaults to the memory order of the data array. |
| 971 | + zarr_format : {2, 3}, optional |
| 972 | + The zarr format to use when saving. |
| 973 | + If not specified, defaults to the zarr format of the data array. |
| 974 | + attributes : dict, optional |
| 975 | + Attributes for the array. |
| 976 | + If not specified, defaults to the attributes of the data array. |
| 977 | + chunk_key_encoding : ChunkKeyEncoding, optional |
| 978 | + A specification of how the chunk keys are represented in storage. |
| 979 | + For Zarr format 3, the default is ``{"name": "default", "separator": "/"}}``. |
| 980 | + For Zarr format 2, the default is ``{"name": "v2", "separator": "."}}``. |
| 981 | + If not specified and the data array has the same zarr format as the target array, |
| 982 | + the chunk key encoding of the data array is used. |
| 983 | + dimension_names : Iterable[str], optional |
| 984 | + The names of the dimensions (default is None). |
| 985 | + Zarr format 3 only. Zarr format 2 arrays should not use this parameter. |
| 986 | + If not specified, defaults to the dimension names of the data array. |
| 987 | + storage_options : dict, optional |
| 988 | + If using an fsspec URL to create the store, these will be passed to the backend implementation. |
| 989 | + Ignored otherwise. |
| 990 | + overwrite : bool, default False |
| 991 | + Whether to overwrite an array with the same name in the store, if one exists. |
| 992 | + config : ArrayConfig or ArrayConfigLike, optional |
| 993 | + Runtime configuration for the array. |
| 994 | +
|
| 995 | + Returns |
| 996 | + ------- |
| 997 | + AsyncArray |
| 998 | + The array. |
| 999 | +
|
| 1000 | + Examples |
| 1001 | + -------- |
| 1002 | + #TODO |
| 1003 | + """ |
| 1004 | + return Array( |
| 1005 | + sync( |
| 1006 | + zarr.core.array.from_array( |
| 1007 | + data, |
| 1008 | + store, |
| 1009 | + name=name, |
| 1010 | + chunks=chunks, |
| 1011 | + shards=shards, |
| 1012 | + filters=filters, |
| 1013 | + compressors=compressors, |
| 1014 | + serializer=serializer, |
| 1015 | + fill_value=fill_value, |
| 1016 | + order=order, |
| 1017 | + zarr_format=zarr_format, |
| 1018 | + attributes=attributes, |
| 1019 | + chunk_key_encoding=chunk_key_encoding, |
| 1020 | + dimension_names=dimension_names, |
| 1021 | + storage_options=storage_options, |
| 1022 | + overwrite=overwrite, |
| 1023 | + config=config, |
| 1024 | + ) |
| 1025 | + ) |
| 1026 | + ) |
| 1027 | + |
| 1028 | + |
896 | 1029 | # TODO: add type annotations for kwargs |
897 | 1030 | def empty(shape: ChunkCoords, **kwargs: Any) -> Array: |
898 | 1031 | """Create an empty array. |
|
0 commit comments