brainglobe / brainglobe-atlasapi

A lightweight python module to interact with atlases for systems neuroscience
https://brainglobe.info/documentation/brainglobe-atlasapi/index.html
BSD 3-Clause "New" or "Revised" License
125 stars 33 forks source link

`kim_dev...` atlases raise an error #232

Closed adamltyson closed 3 months ago

adamltyson commented 1 year ago

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__.._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 = self.atlas_info = 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 = 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=, 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=, 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 = 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=(, 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) ```
alessandrofelder commented 1 year ago

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 commented 1 year ago

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

adamltyson commented 1 year ago

I can reproduce on macOS with:

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

alessandrofelder commented 1 year ago

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 commented 1 year ago

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

adamltyson commented 1 year ago

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!

alessandrofelder commented 1 year ago

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

adamltyson commented 1 year ago

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

alessandrofelder commented 1 year ago

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

alessandrofelder commented 1 year ago

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 commented 1 year ago

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 commented 3 months ago

Closed by #304