napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.21k stars 422 forks source link

Error in example script surface_timeseries_.py #5611

Closed GenevieveBuckley closed 1 year ago

GenevieveBuckley commented 1 year ago

🐛 Bug

The napari example script surface_timeseries_.py returns an error when it is run.

To Reproduce

Steps to reproduce the behavior:

  1. Install napari, and nilearn into your python environment
  2. Download and run the napari example surface_timeseries_.py from here: python surface_timeseries_.py
  3. An error message is produced: "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part"
Error message: ``` python surface_timeseries_.py Dataset created in /Users/genevieb/nilearn_data/nki_enhanced_surface Downloading data from https://www.nitrc.org/frs/download.php/8470/pheno_nki_nilearn.csv ... ...done. (1 seconds, 0 min) Downloading data from https://www.nitrc.org/frs/download.php/8261/A00028185_rh_preprocessed_fsaverage5_fwhm6.gii ... Downloaded 42377216 of 42412120 bytes (99.9%, 0.1s remaining) ...done. (100 seconds, 1 min) Downloading data from https://www.nitrc.org/frs/download.php/8260/A00028185_lh_preprocessed_fsaverage5_fwhm6.gii ... Downloaded 41697280 of 42402060 bytes (98.3%, 1.3s remaining) ...done. (81 seconds, 1 min) Traceback (most recent call last): File "/Users/genevieb/Documents/GitHub/napari/examples/surface_timeseries_.py", line 24, in brain_vertices, brain_faces = surface.load_surf_data(fsaverage['pial_left']) File "/Users/genevieb/mambaforge/envs/napari-dev/lib/python3.10/site-packages/nilearn/surface/surface.py", line 733, in load_surf_data data_part = _gifti_img_to_data(gii) File "/Users/genevieb/mambaforge/envs/napari-dev/lib/python3.10/site-packages/nilearn/surface/surface.py", line 684, in _gifti_img_to_data return np.asarray([arr.data for arr in gifti_img.darrays]).T.squeeze() ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part. ```

Expected behavior

I expected the example script to run without an error, and to display some timeseries surface data in napari.

Environment

napari: 0.4.13.dev917+g54c1dbf8 Platform: macOS-12.3.1-arm64-arm-64bit System: MacOS 12.3.1 Python: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:25:29) [Clang 14.0.6 ] Qt: 5.15.6 PyQt5: 5.15.7 NumPy: 1.24.2 SciPy: 1.10.1 Dask: 2023.1.0 VisPy: 0.12.1 magicgui: 0.6.1 superqt: unknown in-n-out: 0.1.6 app-model: 0.1.1 npe2: 0.6.2

OpenGL:

Screens:

Settings path:

Additional context

Juan and I were talking about how to colour the vertices of a mesh according to some property, and he suggested I look at this example. We were both surprised when it gave an error, and thought that was something the CI should have caught.

Czaki commented 1 year ago

@sofroniewn, as you are the author of this example, maybe it is possible to take a look at it?

psobolewskiPhD commented 1 year ago

We were both surprised when it gave an error, and thought that was something the CI should have caught.

I assume the check at the top for nilearn prevents this from running on CI? It doesn't show up in the logs.

Edit: looking at the workflow and stuff further—yes. This example is skipped: https://github.com/napari/napari/blob/3ec4be1ae8eee50ab4912ba87981261cc94c075f/napari/_tests/test_examples.py#L23-L33

GenevieveBuckley commented 1 year ago

Yes it's skipped on the CI, but my point is that the example fails when you do install nilearn and try to run it.

Czaki commented 1 year ago

The examples test was moved to separate job. So maybe someone could review list of skipped examples and check if some of them could be enabled.

@GenevieveBuckley the only solution is that some core dev will spend time to fix it.

dalthviz commented 1 year ago

Hi, just in case, I checked the example and seems like the error comes from nilearn being incompatible with numpy 1.24.x. If you run the example with numpy 1.23.x it works:

imagen

Also, with numpy 1.23.x a VisibleDeprecationWarning message appears which points to the line inside nilearn where the error occurs when using numpy 1.24.x :

\site-packages\nilearn\surface\surface.py:684: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  return np.asarray([arr.data for arr in gifti_img.darrays]).T.squeeze()

So I guess either being sure to use numpy < 1.24.x or adding the dtype=object kwarg at the line mentioned inside nilearn should fix the example

psobolewskiPhD commented 1 year ago

If I'm parsing this correctly, this is an upstream issue in nilearn and not a bug in napari/the example?

GenevieveBuckley commented 1 year ago

FYI nilearn does have a PR open that could fix this error: https://github.com/nilearn/nilearn/pull/3644