Load dask array from stack of npy files .. warning:: This function uses the :mod:`pickle` module to load array metadata. The ``pickle`` module is not secure against erroneous or maliciously constructed data. Never load data that could have come from an untrusted sour
(dirname, mmap_mode="r")
| 6122 | |
| 6123 | |
| 6124 | def from_npy_stack(dirname, mmap_mode="r"): |
| 6125 | """Load dask array from stack of npy files |
| 6126 | |
| 6127 | .. warning:: |
| 6128 | This function uses the :mod:`pickle` module to load array metadata. |
| 6129 | The ``pickle`` module is not secure against erroneous or maliciously |
| 6130 | constructed data. Never load data that could have come from an untrusted |
| 6131 | source, or that could have been tampered with. |
| 6132 | |
| 6133 | Parameters |
| 6134 | ---------- |
| 6135 | dirname: string |
| 6136 | Directory of .npy files |
| 6137 | mmap_mode: (None or 'r') |
| 6138 | Read data in memory map mode |
| 6139 | |
| 6140 | See Also |
| 6141 | -------- |
| 6142 | to_npy_stack |
| 6143 | """ |
| 6144 | with open(os.path.join(dirname, "info"), "rb") as f: |
| 6145 | info = pickle.load(f) |
| 6146 | |
| 6147 | dtype = info["dtype"] |
| 6148 | chunks = info["chunks"] |
| 6149 | axis = info["axis"] |
| 6150 | |
| 6151 | name = f"from-npy-stack-{dirname}" |
| 6152 | keys = list(product([name], *[range(len(c)) for c in chunks])) |
| 6153 | values = [ |
| 6154 | (np.load, os.path.join(dirname, f"{i}.npy"), mmap_mode) |
| 6155 | for i in range(len(chunks[axis])) |
| 6156 | ] |
| 6157 | dsk = dict(zip(keys, values)) |
| 6158 | |
| 6159 | return Array(dsk, name, chunks, dtype) |
| 6160 | |
| 6161 | |
| 6162 | def new_da_object(dsk, name, chunks, meta=None, dtype=None): |