dask-image icon indicating copy to clipboard operation
dask-image copied to clipboard

ndinterp methods fails with ResourceBackedDaskArray from aicsimageio

Open sommerc opened this issue 2 years ago • 4 comments

Hi there,

I want to use ndinterp.affine_transform on images loaded with aicsimageio/nd2. For some image formats (e.g. .nd2) aicsimageio returns a ResourceBackedDaskAray which is an instance of da.Array.

However the type check for da.core.Array fails.

img = AICSImage("image.nd2")
affine_transform(img.dask_data, matrix)

ValueError: Array is already a dask array. Use 'asarray' or 'rechunk' instead.

Cheers, Chris

sommerc avatar Apr 19 '24 11:04 sommerc

Hi @sommerc, thanks for posting this issue 🙏

This is the line behind the type check you mentioned:

type(image) == da.core.Array

We should probably look into whether this is the right way to perform this check. Would you be aware of a check that ResourceBackedDaskArrays passes?

m-albert avatar Apr 19 '24 11:04 m-albert

Hi @m-albert,

thanks for your quick reply! I am not an expert on dask, but

isinstance(image, da.core.Array) is True for image of type ResourceBackedDaskArray

and should not do any harm.

C

sommerc avatar Apr 19 '24 13:04 sommerc

Thanks! Probably we should be using isinstance in dask_image.ndinterp to also support dask array sublcasses, as your example clearly motivates.

Would you be interested in creating a PR for this @sommerc ?

m-albert avatar Apr 19 '24 14:04 m-albert

Yes, then it would also match the check inside da.from_array()

Would you be interested in creating a PR

Absolutely, I'll create on tomorrow.

Thanks a lot!

sommerc avatar Apr 19 '24 14:04 sommerc