Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list atlases #40

Merged
merged 6 commits into from Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions brainatlas_api/list_atlases.py
@@ -0,0 +1,65 @@
from pathlib import Path
from rich.table import Table
from rich import print as rprint

from brainatlas_api import config
from brainatlas_api.bg_atlas import (
FedeClaudi marked this conversation as resolved.
Show resolved Hide resolved
BrainGlobeAtlas,
FishAtlas,
RatAtlas,
AllenBrain25Um,
AllenHumanBrain500Um,
)


"""
Some functionality to list all available and downloaded brainglobe atlases
"""


def list_atlases():
# Parse config
conf = config.read_config()
brainglobe_dir = Path(conf["default_dirs"]["brainglobe_dir"])

# ----------------------------- Get local atlases ---------------------------- #
atlases = {}
for elem in brainglobe_dir.iterdir():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to use glob and a pattern to match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used pathlib much so not very familiar with best practices...will fix

if elem.is_dir():
atlases[elem.name] = dict(
downloaded=True,
local=str(elem),
online=BrainGlobeAtlas._remote_url_base.format(elem.name),
)

# ---------------------- Get atlases not yet downloaded ---------------------- #
for atlas in [FishAtlas, RatAtlas, AllenBrain25Um, AllenHumanBrain500Um]:
name = f"{atlas.atlas_name}_v{atlas.version}"
if name not in atlases.keys():
atlases[str(name)] = dict(
downloaded=False,
local="[red]---[/red]",
online=BrainGlobeAtlas._remote_url_base.format(name),
)

# -------------------------------- print table ------------------------------- #
table = Table(
show_header=True,
header_style="bold green",
title="\n\nBrainglobe Atlases",
)
table.add_column("Name")
table.add_column("Downloaded")
table.add_column("Local path")
table.add_column("Online path", style="dim")

for atlas, info in atlases.items():
if info["downloaded"]:
downloaded = "[green]:heavy_check_mark:[/green]"
else:
downloaded = "[red]---[/red]"
table.add_row(
"[b]" + atlas + "[/b]", downloaded, info["local"], info["online"]
)

rprint(table)
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -30,7 +30,8 @@
python_requires=">=3.6, <3.8",
entry_points={
"console_scripts": [
"brainatlas_config = brainatlas_api.config:cli_modify_config"
"brainatlas_config = brainatlas_api.config:cli_modify_config",
"brainatlas_list_atlases = brainatlas_api.list_atlases:list_atlases",
]
},
packages=find_namespace_packages(exclude=("atlas_gen", "docs", "tests*")),
Expand Down