aicsimageio icon indicating copy to clipboard operation
aicsimageio copied to clipboard

Setting scenes of different shapes raises `xarray` error using bioformats reader

Open NHPatterson opened this issue 4 years ago • 2 comments

System and Software

  • aicsimageio Version: 4.4.0
  • Python Version: 3.8
  • Operating System: Windows

Description

Changing scenes in an bioformats reader image doesn't appear to update the dimension size for xarray, without the ability to set the scene at __init__ in AICSImage (am I missing something?), this means it is impossible to access scenes with a different shape than the scene at index 0. For instance shown below, in this .scn, the scene at index 0 is the overview image and the full resolution image is at index 3.

Reproduction

Using public data found here:

from aicsimageio import AICSImage
aics_im = AICSImage("T:/Leica-1.scn")
print(aics_im.dask_data)
# dask.array<transpose, shape=(1, 1, 1, 4668, 1616, 3), dtype=uint8, chunksize=(1, 1, 1, 4668, 1616, 3), chunktype=numpy.ndarray>
aics_im.set_scene(aics_im.scenes[3])
print(aics_im.dask_data)

traceback

Traceback (most recent call last):
  File "C:\miniconda3\envs\wsireg-new\lib\site-packages\IPython\core\interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-4f429c3d4f61>", line 2, in <module>
    print(aics_im.dask_data)
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\aics_image.py", line 466, in dask_data
    return self.xarray_dask_data.data
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\aics_image.py", line 377, in xarray_dask_data
    and dimensions.DimensionNames.MosaicTile in self.reader.dims.order
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\readers\reader.py", line 511, in dims
    self._dims = Dimensions(dims=self.xarray_dask_data.dims, shape=self.shape)
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\readers\reader.py", line 338, in xarray_dask_data
    self._xarray_dask_data = self._read_delayed()
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\readers\bioformats_reader.py", line 146, in _read_delayed
    return self._to_xarray(delayed=True)
  File "c:\pyproj\git\forked\aicsimageio\aicsimageio\readers\bioformats_reader.py", line 184, in _to_xarray
    return xr.DataArray(
  File "C:\miniconda3\envs\wsireg-new\lib\site-packages\xarray\core\dataarray.py", line 403, in __init__
    coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
  File "C:\miniconda3\envs\wsireg-new\lib\site-packages\xarray\core\dataarray.py", line 152, in _infer_coords_and_dims
    raise ValueError(
ValueError: conflicting sizes for dimension 'Y': length 4668 on the data but length 38432 on coordinate 'Y'

NHPatterson avatar Oct 18 '21 13:10 NHPatterson

thanks! Can you try #339 to see if it works for you?

tlambert03 avatar Oct 18 '21 13:10 tlambert03

@tlambert03 Can confirm this works with the test above locally.

NHPatterson avatar Oct 18 '21 13:10 NHPatterson

We have added a new maintenance feature to clean up stale issues and PRs. Adding this comment to set a baseline for ‘Stale’

BrianWhitneyAI avatar Mar 28 '23 20:03 BrianWhitneyAI

I can't seem to replicate this error given the above parameters. Within the example image provided, aicsimageio only detects 2 scenes, raising an error when trying to index to the 4th scene using aics_im.set_scene(aics_im.scenes[3]).

BrianWhitneyAI avatar Mar 31 '23 22:03 BrianWhitneyAI

Closing this for now. Feel free to reopen!

BrianWhitneyAI avatar Apr 07 '23 18:04 BrianWhitneyAI