ValueError with calculate_image_features() in tutorial_visium_hne.ipynb
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- numpy, python
调研方向
Reproduce the failing cell in tutorial_visium_hne.ipynb and trace calculate_image_features through squidpy/im/_feature.py and the crop path in squidpy/im/_container.py. Check the interaction with the image rescaling call shown in the traceback, then rerun the notebook cell to confirm feature calculation completes without the ValueError.
由索引模型根据 Issue 内容生成。
描述
Hi there,
Thank you for the tutorial! I was just running through the example data, and encountered this error at:
# calculate features for different scales (higher value means more context)
for scale in [1.0, 2.0]:
feature_name = f"features_summary_scale{scale}"
sq.im.calculate_image_features(
adata2,
img2.compute(),
features="summary",
key_added=feature_name,
n_jobs=4,
scale=scale,
)
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
100%|██████████| 2688/2688 [00:14<00:00, 179.80/s]
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/anndata/_core/anndata.py:1113: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if not is_categorical_dtype(df_full[k]):
{
"name": "ValueError",
"message": "applied function returned data with unexpected number of dimensions. Received 4 dimension(s) but expected 0 dimensions with names: ()",
"stack": "---------------------------------------------------------------------------
_RemoteTraceback Traceback (most recent call last)
_RemoteTraceback:
"""
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/externals/loky/process_executor.py", line 463, in _process_worker
r = call_item()
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/externals/loky/process_executor.py", line 291, in call
return self.fn(*self.args, **self.kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py", line 589, in call
return [func(*args, **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py", line 589, in
return [func(*args, **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_feature.py", line 119, in _calculate_image_features_helper
for crop in img.generate_spot_crops(
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_container.py", line 830, in generate_spot_crops
crop = self.crop_center(y=y, x=x, radius=radius, library_id=obs_library_ids[i], **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_container.py", line 661, in crop_center
return self.crop_corner( # type: ignore[no-any-return]
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_container.py", line 568, in crop_corner
self._post_process(
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_container.py", line 602, in _post_process
data = data.map(_rescale).assign_coords({"z": library_ids})
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/dataset.py", line 6818, in map
variables = {
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/dataset.py", line 6819, in
k: maybe_wrap_array(v, func(v, *args, **kwargs))
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_container.py", line 597, in _rescale
return xr.DataArray(scaling_fn(arr).astype(dtype), dims=arr.dims)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/skimage/_shared/utils.py", line 328, in fixed_func
return func(*args, **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/skimage/transform/_warps.py", line 289, in rescale
return resize(image, output_shape, order=order, mode=mode, cval=cval,
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/skimage/transform/_warps.py", line 188, in resize
_clip_warp_output(image, out, mode, cval, clip)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/skimage/transform/_warps.py", line 692, in _clip_warp_output
np.clip(output_image, min_val, max_val, out=output_image)
File "<array_function internals>", line 180, in clip
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 2152, in clip
return _wrapfunc(a, 'clip', a_min, a_max, out=out, **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/numpy/core/_methods.py", line 159, in _clip
return _clip_dep_invoke_with_casting(
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/numpy/core/_methods.py", line 113, in _clip_dep_invoke_with_casting
return ufunc(*args, out=out, **kwargs)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/arithmetic.py", line 86, in array_ufunc
return apply_ufunc(
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/computation.py", line 1197, in apply_ufunc
return apply_dataarray_vfunc(
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/computation.py", line 304, in apply_dataarray_vfunc
result_var = func(*data_vars)
File "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/xarray/core/computation.py", line 786, in apply_variable_ufunc
raise ValueError(
ValueError: applied function returned data with unexpected number of dimensions. Received 4 dimension(s) but expected 0 dimensions with names: ()
"""
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
/Users/estelladong/Downloads/tutorial_visium_hne.ipynb Cell 13 line 4
2 for scale in [1.0, 2.0]:
3 feature_name = f"features_summary_scale{scale}"
----> 4 sq.im.calculate_image_features(
5 adata2,
6 img2.compute(),
7 features="summary",
8 key_added=feature_name,
9 n_jobs=4,
10 scale=scale,
11 )
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/im/_feature.py:91, in calculate_image_features(adata, img, layer, library_id, features, features_kwargs, key_added, copy, n_jobs, backend, show_progress_bar, **kwargs)
88 n_jobs = _get_n_cores(n_jobs)
89 start = logg.info(f"Calculating features {list(features)} using {n_jobs} core(s)")
---> 91 res = parallelize(
92 _calculate_image_features_helper,
93 collection=adata.obs_names,
94 extractor=pd.concat,
95 n_jobs=n_jobs,
96 backend=backend,
97 show_progress_bar=show_progress_bar,
98 )(adata, img, layer=layer, library_id=library_id, features=features, features_kwargs=features_kwargs, **kwargs)
100 if copy:
101 logg.info("Finish", time=start)
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/squidpy/_utils.py:168, in parallelize..wrapper(*args, **kwargs)
165 else:
166 pbar, queue, thread = None, None, None
--> 168 res = jl.Parallel(n_jobs=n_jobs, backend=backend)(
169 jl.delayed(runner if use_runner else callback)(
170 *((i, cs) if use_ixs else (cs,)),
171 *args,
172 **kwargs,
173 queue=queue,
174 )
175 for i, cs in enumerate(collections)
176 )
178 if thread is not None:
179 thread.join()
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:1952, in Parallel.call(self, iterable)
1946 # The first item from the output is blank, but it makes the interpreter
1947 # progress until it enters the Try/Except block of the generator and
1948 # reach the first yield statement. This starts the aynchronous
1949 # dispatch of the tasks to the workers.
1950 next(output)
-> 1952 return output if self.return_generator else list(output)
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:1595, in Parallel._get_outputs(self, iterator, pre_dispatch)
1592 yield
1594 with self._backend.retrieval_context():
-> 1595 yield from self._retrieve()
1597 except GeneratorExit:
1598 # The generator has been garbage collected before being fully
1599 # consumed. This aborts the remaining tasks if possible and warn
1600 # the user if necessary.
1601 self._exception = True
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:1699, in Parallel._retrieve(self)
1692 while self._wait_retrieval():
1693
1694 # If the callback thread of a worker has signaled that its task
1695 # triggered an exception, or if the retrieval loop has raised an
1696 # exception (e.g. GeneratorExit), exit the loop and surface the
1697 # worker traceback.
1698 if self._aborting:
-> 1699 self._raise_error_fast()
1700 break
1702 # If the next job is not ready for retrieval yet, we just wait for
1703 # async callbacks to progress.
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:1734, in Parallel._raise_error_fast(self)
1730 # If this error job exists, immediatly raise the error by
1731 # calling get_result. This job might not exists if abort has been
1732 # called directly or if the generator is gc'ed.
1733 if error_job is not None:
-> 1734 error_job.get_result(self.timeout)
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:736, in BatchCompletionCallBack.get_result(self, timeout)
730 backend = self.parallel._backend
732 if backend.supports_retrieve_callback:
733 # We assume that the result has already been retrieved by the
734 # callback thread, and is stored internally. It's just waiting to
735 # be returned.
--> 736 return self._return_or_raise()
738 # For other backends, the main thread needs to run the retrieval step.
739 try:
File /opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/joblib/parallel.py:754, in BatchCompletionCallBack._return_or_raise(self)
752 try:
753 if self.status == TASK_ERROR:
--> 754 raise self._result
755 return self._result
756 finally:
ValueError: applied function returned data with unexpected number of dimensions. Received 4 dimension(s) but expected 0 dimensions with names: ()"
}
Could you please let us know the environment.yml you used? Thank you!
Sincerely,
Estella
- 主要语言
- Jupyter Notebook
- 星标
- 35
- 派生
- 26
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
scverse/squidpy-tutorials 的其他 Issue
-
`compute_crops.ipynb` fails because it uses deprecated ` crop_corner.interactive(adata_crop)`可能重新可做 @selmanozleyen 于 400 天前认领,目前没有进行中的 PR。 未关闭
scverse/squidpy-tutorials#147 · 已指派 1 人 ·
-
难度 5/5 一周以上 新手友好度 35/100
scverse/squidpy-tutorials#129 · 7 条评论 ·
-
Two improvements to the Xenium notebook可能重新可做 @LLehner 于 796 天前认领,目前没有进行中的 PR。 未关闭
scverse/squidpy-tutorials#128 · 4 条评论 · 已指派 1 人 ·
-
难度 1/5 1 小时以内 新手友好度 55/100
scverse/squidpy-tutorials#99 · 1 条评论 ·
查看 scverse/squidpy-tutorials 的全部 Issue
相似的 Issue
-
billion-context-pi
难度 2/5 1-3 小时 新手友好度 62/100
ranxianglei/billion-context#2521 · 3 条评论 ·
维护者通常 1 天内回复
-
agent-research agent-review-finding chore
难度 2/5 1-3 小时 新手友好度 66/100
jordansmall/spindrift#4922 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
documentation v2
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/python-sdk#3662 ·
维护者通常 1 天内回复
-
docs(types): update the collection binding note now that typed collections shipped in pycubrid 1.9.0未关闭documentation priority: low size: S
难度 2/5 1-3 小时 新手友好度 75/100
cubrid-lab/sqlalchemy-cubrid#768 ·
维护者通常 1 天内回复