ValueError with calculate_image_features() in tutorial_visium_hne.ipynb
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
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.
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
Sorry for late reply. Does this issue still persist?