brainglobe-atlasapi icon indicating copy to clipboard operation
brainglobe-atlasapi copied to clipboard

`kim_dev...` atlases raise an error

Open adamltyson opened this issue 2 years ago • 11 comments

Not sure if this is an error with the atlas, my machine or the plugin, but I noticed that loading all the kim_dev atlases cause an error.

Full traceback
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/projects/brainglobe/brainglobe-napari/src/brainglobe_napari/atlas_viewer_widget.py:130, in AtlasViewerWidget.__init__.<locals>._on_selection_changed()
    126     self._selected_atlas_name = self._model.data(
    127         self._model.index(self._selected_atlas_row, 0)
    128     )
    129     selected_atlas = BrainGlobeAtlas(self._selected_atlas_name)
--> 130     self.atlas_info.setText(str(selected_atlas))
        selected_atlas = kim dev atlas (res. mouse)
        self = <brainglobe_napari.atlas_viewer_widget.AtlasViewerWidget object at 0x7f705ba39b40>
        self.atlas_info = <PyQt5.QtWidgets.QTextEdit object at 0x7f705b9eb520>
    131 else:
    132     self.atlas_info.setText("")

File ~/miniconda3/envs/brainglobe/lib/python3.10/site-packages/bg_atlasapi/bg_atlas.py:204, in BrainGlobeAtlas.__str__(self=kim dev atlas (res. mouse))
    202 buf = StringIO()
    203 _console = Console(file=buf, force_jupyter=False)
--> 204 _console.print(self)
        _console = <console width=163 None>
        self = kim dev atlas (res. mouse)
    206 return buf.getvalue()

File ~/miniconda3/envs/brainglobe/lib/python3.10/site-packages/rich/console.py:1699, in Console.print(self=<console width=163 None>, sep=' ', end='\n', style=None, justify=None, overflow=None, no_wrap=None, emoji=None, markup=None, highlight=None, width=None, height=None, crop=True, soft_wrap=False, new_line_start=False, *objects=(kim dev atlas (res. mouse),))
   1697 if style is None:
   1698     for renderable in renderables:
-> 1699         extend(render(renderable, render_options))
        render_options = ConsoleOptions(size=ConsoleDimensions(width=163, height=12), legacy_windows=False, min_width=1, max_width=163, is_terminal=False, encoding='utf-8', max_height=12, justify=None, overflow=None, no_wrap=None, highlight=None, markup=None, height=None)
        renderable = kim dev atlas (res. mouse)
   1700 else:
   1701     for renderable in renderables:

File ~/miniconda3/envs/brainglobe/lib/python3.10/site-packages/rich/console.py:1331, in Console.render(self=<console width=163 None>, renderable=kim dev atlas (res. mouse), options=ConsoleOptions(size=ConsoleDimensions(width=163,...p=None, highlight=None, markup=None, height=None))
   1329 _Segment = Segment
   1330 _options = _options.reset_height()
-> 1331 for render_output in iter_render:
        iter_render = <generator object BrainGlobeAtlas.__rich_console__ at 0x7f705ba06b20>
   1332     if isinstance(render_output, _Segment):
   1333         yield render_output

File ~/miniconda3/envs/brainglobe/lib/python3.10/site-packages/bg_atlasapi/bg_atlas.py:213, in BrainGlobeAtlas.__rich_console__(self=kim dev atlas (res. mouse), *args=(<console width=163 None>, ConsoleOptions(size=ConsoleDimensions(width=163,...p=None, highlight=None, markup=None, height=None)))
    208 def __rich_console__(self, *args):
    209     """
    210     Method for rich API's console protocol.
    211     Prints the atlas metadata as a table nested in a panel
    212     """
--> 213     panel = _rich_atlas_metadata(self.atlas_name, self.metadata)
        self.atlas_name = 'kim_dev_mouse_mri_dwi_10um'
        self.metadata = {'name': 'kim_dev_mouse_mri_dwi', 'citation': 'Kim, Yongsoo (2022), “KimLabDevCCFv001”, Mendeley Data, V1, doi: 10.17632/2svx788ddf.1', 'atlas_link': 'https://data.mendeley.com/datasets/2svx788ddf/1', 'species': 'Mus musculus', 'symmetric': True, 'resolution': [10.0, 10.0, 10.0], 'orientation': 'asr', 'version': '1.1', 'shape': [1320, 800, 1140], 'trasform_to_bg': [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, -1.0, 11400.0], [0.0, 0.0, 0.0, 1.0]], 'additional_references': [], 'atlas_packager': None}
        self = kim dev atlas (res. mouse)
    214     yield panel

File ~/miniconda3/envs/brainglobe/lib/python3.10/site-packages/bg_atlasapi/utils.py:27, in _rich_atlas_metadata(atlas_name='kim_dev_mouse_mri_dwi_10um', metadata={'additional_references': [], 'atlas_link': 'https://data.mendeley.com/datasets/2svx788ddf/1', 'atlas_packager': None, 'citation': 'Kim, Yongsoo (2022), “KimLabDevCCFv001”, Mendeley Data, V1, doi: 10.17632/2svx788ddf.1', 'name': 'kim_dev_mouse_mri_dwi', 'orientation': 'asr', 'resolution': [10.0, 10.0, 10.0], 'shape': [1320, 800, 1140], 'species': 'Mus musculus', 'symmetric': True, ...})
     25 gray = "#A9A9A9"
     26 mocassin = "#FFE4B5"
---> 27 cit_name, cit_link = metadata["citation"].split(", ")
        metadata["citation"] = 'Kim, Yongsoo (2022), “KimLabDevCCFv001”, Mendeley Data, V1, doi: 10.17632/2svx788ddf.1'
        metadata = {'name': 'kim_dev_mouse_mri_dwi', 'citation': 'Kim, Yongsoo (2022), “KimLabDevCCFv001”, Mendeley Data, V1, doi: 10.17632/2svx788ddf.1', 'atlas_link': 'https://data.mendeley.com/datasets/2svx788ddf/1', 'species': 'Mus musculus', 'symmetric': True, 'resolution': [10.0, 10.0, 10.0], 'orientation': 'asr', 'version': '1.1', 'shape': [1320, 800, 1140], 'trasform_to_bg': [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, -1.0, 11400.0], [0.0, 0.0, 0.0, 1.0]], 'additional_references': [], 'atlas_packager': None}
     29 # Create a rich table
     30 tb = Table(
     31     box=None,
     32     show_lines=False,
     33     title=atlas_name.replace("_", " ").capitalize(),
     34     title_style=f"bold {orange}",
     35 )

ValueError: too many values to unpack (expected 2)


adamltyson avatar May 26 '23 14:05 adamltyson

Interesting! I can't reproduce this on either my Macbook or my Ubuntu desktop, in a clean conda environmen with a pip install git+ from current main branch 🤔

alessandrofelder avatar May 30 '23 17:05 alessandrofelder

Could it be that you have a dev install of the BG atlas API in your env @adamltyson ?

alessandrofelder avatar May 30 '23 17:05 alessandrofelder

I can reproduce on macOS with:

  • Delete relevant atlases, create env and run napari:
rm -rfv ~/.brainglobe/kim_dev*
micromamba create --name bg-atlastest -c conda-forge python=3.10 napari -y
micromamba activate bg-atlastest
pip install git+https://github.com/brainglobe/brainglobe-napari
napari
  • Plugins -> BrainGlobe Atlas Viewer
  • Click on kim_dev_mouse_idisco_10um
  • In the terminal I get the usual Bgatlas_api: kim_dev_mouse_idisco_10um not found locally. Downloading... which takes a while.
  • Once download is complete I get the above error.

I'm guessing it's something wrong/different with these atlases, but I don't know why I can reproduce and you can't.

adamltyson avatar May 31 '23 09:05 adamltyson

why is it called kim_mouse_idisco_10um for you and kim_mouse_10um for me? Do we have different versions of the bg-atlasapi? I have 1.0.2 from pypi

alessandrofelder avatar May 31 '23 16:05 alessandrofelder

FWIW I can type the commands above into a terminal (with mamba instead of micromamba but that shouldn't matter?), click on the first kim atlas and get: image

alessandrofelder avatar May 31 '23 16:05 alessandrofelder

Ah, mystery solved, these are different atlases. I should have been more specific with my original message. kim_mouse_10um works, but any atlas starting with kim_dev doesn't. The Kim lab have made a lot of atlases!

adamltyson avatar May 31 '23 16:05 adamltyson

Locally, I don't get any kim_dev atlases - is that because they are not included in the bg-atlasapi version I have?

alessandrofelder avatar May 31 '23 16:05 alessandrofelder

Huh. The version shouldn't make any difference. What's the output of brainglobe list?

adamltyson avatar May 31 '23 18:05 adamltyson

Never mind... I was silly :joy: didn't scroll down far enough :flushed: I can reproduce! :tada:

alessandrofelder avatar Jun 01 '23 08:06 alessandrofelder

This can be reproduced without napari or the widget by

from bg_atlasapi import BrainGlobeAtlas

atlas = BrainGlobeAtlas("kim_dev_mouse_stp_10um")
print(atlas)

The problem is that metadata["citation"].split(", ") for this atlas returns a list with 6 elements:

['Kim', 'Yongsoo (2022)', '“KimLabDevCCFv001”', 'Mendeley Data', 'V1', 'doi: 10.17632/2svx788ddf.1']

, but L27 of bg_atlasapi.utils expects just 2 elements.

alessandrofelder avatar Jun 01 '23 09:06 alessandrofelder

For reference, the same line metadata["citation"].split(", ") for the allen_mouse_100um atlas at the same point in the code looks like:

['Wang et al 2020', 'https://doi.org/10.1016/j.cell.2020.04.007']

Ultimately, I think this is a problem with the kim_dev_... atlas itself, specifically, the metadata.json file

alessandrofelder avatar Jun 01 '23 09:06 alessandrofelder

Closed by #304

alessandrofelder avatar Jun 03 '24 14:06 alessandrofelder