spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

TypeError: unhashable type: 'list'

Open ZhengTiger opened this issue 2 years ago • 0 comments

Hello, thank you for developing such a good tool.

When I followed this tutorial, I have error:

import math

import matplotlib.pyplot as plt
import spatialdata_plot
from spatialdata.datasets import raccoon
from spatialdata.transformations import (
    Affine,
    Identity,
    MapAxis,
    Scale,
    Sequence,
    Translation,
    get_transformation,
    get_transformation_between_coordinate_systems,
    set_transformation,
)
sdata = raccoon()

print(sdata)

sdata.pl.render_images().pl.show()

INFO Transposing data of type: <class 'dask.array.core.Array'> to ('c', 'y', 'x').
SpatialData object with: ├── Images │ └── 'raccoon': SpatialImage[cyx] (3, 768, 1024) ├── Labels │ └── 'segmentation': SpatialImage[yx] (768, 1024) └── Shapes └── 'circles': GeoDataFrame shape: (4, 2) (2D shapes) with coordinate systems: ▸ 'global', with elements: raccoon (Images), segmentation (Labels), circles (Shapes)

TypeError Traceback (most recent call last) Cell In[14], line 5 1 sdata = raccoon() 3 print(sdata) ----> 5 sdata.pl.render_images().pl.show()

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\spatialdata_plot\pl\basic.py:654, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save) 652 for cmd, params in render_cmds.items(): 653 if cmd == "render_images" and cs_contents.query(f"cs == '{cs}'")["has_images"][0]: --> 654 _render_images( 655 sdata=sdata, 656 render_params=params, 657 coordinate_system=cs, 658 ax=ax, 659 fig_params=fig_params, 660 scalebar_params=scalebar_params, 661 legend_params=legend_params, 662 # extent=extent[cs], 663 ) 664 elif cmd == "render_shapes" and cs_contents.query(f"cs == '{cs}'")["has_shapes"][0]: 665 _render_shapes( 666 sdata=sdata, 667 render_params=params, (...) 672 legend_params=legend_params, 673 )

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\spatialdata_plot\pl\render.py:348, in _render_images(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params) 346 # 2A) Image has 3 channels, no palette/cmap info -> use RGB 347 if n_channels == 3 and render_params.palette is None and not got_multiple_cmaps: --> 348 ax.imshow(np.stack([layers[c] for c in channels], axis=-1), alpha=render_params.alpha) 350 # 2B) Image has n channels, no palette/cmap info -> sample n categorical colors 351 elif render_params.palette is None and not got_multiple_cmaps: 352 # overwrite if n_channels == 2 for intuitive result

File <array_function internals>:180, in stack(*args, **kwargs)

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\numpy\core\shape_base.py:420, in stack(arrays, axis, out) 416 if not overrides.ARRAY_FUNCTION_ENABLED: 417 # raise warning if necessary 418 _arrays_for_stack_dispatcher(arrays, stacklevel=2) --> 420 arrays = [asanyarray(arr) for arr in arrays] 421 if not arrays: 422 raise ValueError('need at least one array to stack')

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\numpy\core\shape_base.py:420, in (.0) 416 if not overrides.ARRAY_FUNCTION_ENABLED: 417 # raise warning if necessary 418 _arrays_for_stack_dispatcher(arrays, stacklevel=2) --> 420 arrays = [asanyarray(arr) for arr in arrays] 421 if not arrays: 422 raise ValueError('need at least one array to stack')

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\xarray\core\common.py:165, in AbstractArray.array(self, dtype) 164 def array(self: Any, dtype: DTypeLike = None) -> np.ndarray: --> 165 return np.asarray(self.values, dtype=dtype)

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\xarray\core\dataarray.py:729, in DataArray.values(self) 720 @property 721 def values(self) -> np.ndarray: 722 """ 723 The array's data as a numpy.ndarray. 724 (...) 727 type does not support coercion like this (e.g. cupy). 728 """ --> 729 return self.variable.values

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\xarray\core\variable.py:608, in Variable.values(self) 605 @property 606 def values(self): 607 """The variable's data as a numpy.ndarray""" --> 608 return _as_array_or_item(self._data)

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\xarray\core\variable.py:314, in _as_array_or_item(data) 300 def _as_array_or_item(data): 301 """Return the given values as a numpy array, or as an individual item if 302 it's a 0d datetime64 or timedelta64 array. 303 (...) 312 TODO: remove this (replace with np.asarray) once these issues are fixed 313 """ --> 314 data = np.asarray(data) 315 if data.ndim == 0: 316 if data.dtype.kind == "M":

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\dask\array\core.py:1700, in Array.array(self, dtype, **kwargs) 1699 def array(self, dtype=None, **kwargs): -> 1700 x = self.compute() 1701 if dtype and x.dtype != dtype: 1702 x = x.astype(dtype)

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\dask\base.py:342, in DaskMethodsMixin.compute(self, **kwargs) 318 def compute(self, **kwargs): 319 """Compute this dask collection 320 321 This turns a lazy Dask collection into its in-memory equivalent. (...) 340 dask.compute 341 """ --> 342 (result,) = compute(self, traverse=False, **kwargs) 343 return result

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\dask\base.py:615, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs) 612 if not collections: 613 return args --> 615 schedule = get_scheduler( 616 scheduler=scheduler, 617 collections=collections, 618 get=get, 619 ) 621 dsk = collections_to_dsk(collections, optimize_graph, **kwargs) 622 keys, postcomputes = [], []

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\dask\base.py:1440, in get_scheduler(get, scheduler, collections, cls) 1437 raise ValueError(get_err_msg) 1439 try: -> 1440 from distributed import get_client 1442 return get_client().get 1443 except (ImportError, ValueError):

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\distributed_init_.py:23 20 from dask.config import config # type: ignore 22 from distributed._version import get_versions ---> 23 from distributed.actor import Actor, ActorFuture, BaseActorFuture 24 from distributed.client import ( 25 Client, 26 CompatibleExecutor, (...) 35 wait, 36 ) 37 from distributed.core import Status, connect, rpc

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\distributed\actor.py:13 9 from typing import Generic, Literal, NoReturn, TypeVar 11 from tornado.ioloop import IOLoop ---> 13 from distributed.client import Future 14 from distributed.protocol import to_serialize 15 from distributed.utils import LateLoopEvent, iscoroutinefunction, sync, thread_state

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\distributed\client.py:116 94 from distributed.utils import ( 95 CancelledError, 96 LoopRunner, (...) 106 thread_state, 107 ) 108 from distributed.utils_comm import ( 109 WrappedKey, 110 gather_from_workers, (...) 114 unpack_remotedata, 115 ) --> 116 from distributed.worker import get_client, get_worker, secede 118 logger = logging.getLogger(name) 120 _global_clients: weakref.WeakValueDictionary[ 121 int, Client 122 ] = weakref.WeakValueDictionary()

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\distributed\worker.py:119 117 from distributed.utils_perf import disable_gc_diagnosis, enable_gc_diagnosis 118 from distributed.versions import get_versions --> 119 from distributed.worker_memory import ( 120 DeprecatedMemoryManagerAttribute, 121 DeprecatedMemoryMonitor, 122 WorkerDataParameter, 123 WorkerMemoryManager, 124 ) 125 from distributed.worker_state_machine import ( 126 AcquireReplicasEvent, 127 BaseWorker, (...) 151 WorkerState, 152 ) 154 if TYPE_CHECKING: 155 # FIXME import from typing (needs Python >=3.10)

File D:\1.study\miniconda3\envs\scverse\lib\site-packages\distributed\worker_memory.py:55 52 from distributed.nanny import Nanny 53 from distributed.worker import Worker ---> 55 WorkerDataParameter: TypeAlias = Union[ 56 # pre-initialized 57 MutableMapping[str, object], 58 # constructor 59 Callable[[], MutableMapping[str, object]], 60 # constructor, passed worker.local_directory 61 Callable[[str], MutableMapping[str, object]], 62 # (constructor, kwargs to constructor) 63 tuple[Callable[..., MutableMapping[str, object]], dict[str, Any]], 64 # initialize internally 65 None, 66 ] 68 worker_logger = logging.getLogger("distributed.worker.memory") 69 worker_logger.addFilter(RateLimiterFilter(r"Unmanaged memory use is high"))

File D:\1.study\miniconda3\envs\scverse\lib\typing.py:243, in _tp_cache..inner(*args, **kwds) 241 except TypeError: 242 pass # All real errors (not unhashable args) are raised below. --> 243 return func(*args, **kwds)

File D:\1.study\miniconda3\envs\scverse\lib\typing.py:316, in _SpecialForm.getitem(self, parameters) 314 @_tp_cache 315 def getitem(self, parameters): --> 316 return self._getitem(self, parameters)

File D:\1.study\miniconda3\envs\scverse\lib\typing.py:421, in Union(self, parameters) 419 msg = "Union[arg, ...]: each arg must be a type." 420 parameters = tuple(_type_check(p, msg) for p in parameters) --> 421 parameters = _remove_dups_flatten(parameters) 422 if len(parameters) == 1: 423 return parameters[0]

File D:\1.study\miniconda3\envs\scverse\lib\typing.py:215, in _remove_dups_flatten(parameters) 213 params.append(p) 214 # Weed out strict duplicates, preserving the first of each occurrence. --> 215 all_params = set(params) 216 if len(all_params) < len(params): 217 new_params = []

TypeError: unhashable type: 'list'

Thank you for your help!

ZhengTiger avatar Oct 09 '23 12:10 ZhengTiger