scverse / scverse/napari-spatialdata
Multiscale image visualization
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 90
- Forks
- 25
- Avg merge
- 22m
- Merged PRs (30d)
- 1
Description
Hi! I was testing with visualization of multiscale images. However, I cannot make this simple example work. Any tips?
I'm using the latest 0.5.5 release version.
Example code:
import numpy as np
from spatialdata import SpatialData
from spatialdata.models import Image2DModel
# A sample multiscale image
img = np.random.randint(0, 255, size=(3,2000, 2000), dtype=np.uint8)
multiscale_image = Image2DModel.parse(img, dims=("c","y","x"), c_coords=("r", "g", "b"), scale_factors=[2,4], chunks=(3,256,256))
sdata = SpatialData(images={"img": multiscale_image})
from napari_spatialdata import Interactive
interactive = Interactive(sdata)
interactive.run()
The error will occur once I select the 'img' element in napari.
Traceback (most recent call last):
File "/.venv/lib/python3.12/site-packages/napari_spatialdata/_sdata_widgets.py", line 145, in run
layer = self.sdata_widget.viewer_model.get_sdata_image(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/napari_spatialdata/_viewer.py", line 468, in get_sdata_image
rgb_image, rgb = _adjust_channels_order(element=sdata.images[original_name])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/napari_spatialdata/utils/_utils.py", line 262, in _adjust_channels_order
new_raster = new_raster.msi.reindex_data_arrays({"c": ["r", "g", "b", "a"][: len(c_coords)]})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/multiscale_spatial_image/multiscale_spatial_image.py", line 188, in reindex_data_arrays
return self._dt.map_over_datasets(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/xarray/core/datatree.py", line 1462, in map_over_datasets
return map_over_datasets(func, self, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/xarray/core/datatree_mapping.py", line 103, in map_over_datasets
results = func_with_error_context(*node_dataset_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/xarray/core/datatree_mapping.py", line 133, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/multiscale_spatial_image/utils.py", line 22, in _func
return func(ds, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.12/site-packages/multiscale_spatial_image/operations/operations.py", line 18, in reindex_data_arrays
return ds["image"].reindex(*args, **kwargs).to_dataset()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DataArray.reindex() takes from 1 to 2 positional arguments but 6 were given
Raised whilst mapping function over node with path 'scale0'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied multiscale-image example with the 0.5.5 release and select the img element in napari. Start with napari_spatialdata/_sdata_widgets.py, then trace through _viewer.py and utils/_utils.py to the reported reindex_data_arrays error. Done means the example can display the multiscale image without the traceback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100