I have a Dask array of image data. How do I save this array to a directory of tiff files?
1
Ideally there would be some sort of imsave
function. As of 2019-10-31 I can't find one, but you might want to watch https://image.dask.org in the future for this sort of functionality.
You can accomplish this today using map_blocks and skimage.io.imread
import dask.array as da
import skimage.io
x = da.random.random((2000, 2000), chunks=(200, 200)) # make a dask array
def save_file(arr, block_info=None):
""" Save file to foo-x-y.tif, where x and y are block locations """
filename = "foo-" + "-".join(map(str, block_info[0]["chunk-location"])) + ".tif"
skimage.io.imsave(filename, arr)
return arr
x.map_blocks(save_file, dtype=x.dtype).compute() # call function on every block
.
$ ls
foo-0-0.tif
foo-0-1.tif
...
foo-9-8.tif
foo-9-9.tif