-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* list atlases * added test * test fix * auto detect available atlases * test_get_atlas_from_name * added rich to requirements.txt
- Loading branch information
1 parent
becbdcb
commit 73b3e06
Showing
6 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from brainatlas_api import bg_atlas | ||
from brainatlas_api.list_atlases import list_atlases | ||
|
||
available_atlases = [ | ||
cls for cls in map(bg_atlas.__dict__.get, bg_atlas.__all__) | ||
] | ||
|
||
|
||
def get_atlas_class_from_name(name): | ||
names = [ | ||
f"{atlas.atlas_name}_v{atlas.version}" for atlas in available_atlases | ||
] | ||
atlases = {n: a for n, a in zip(names, available_atlases)} | ||
|
||
if name in atlases.keys(): | ||
return atlases[name] | ||
else: | ||
print(f"Could not find atlas with name {name}. Available atlases:\n") | ||
list_atlases() | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from pathlib import Path | ||
from rich.table import Table | ||
from rich import print as rprint | ||
|
||
from brainatlas_api import config | ||
from brainatlas_api import bg_atlas | ||
|
||
|
||
""" | ||
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(): | ||
if elem.is_dir(): | ||
atlases[elem.name] = dict( | ||
downloaded=True, | ||
local=str(elem), | ||
online=bg_atlas.BrainGlobeAtlas._remote_url_base.format( | ||
elem.name | ||
), | ||
) | ||
|
||
# ---------------------- Get atlases not yet downloaded ---------------------- # | ||
available_atlases = [ | ||
cls for cls in map(bg_atlas.__dict__.get, bg_atlas.__all__) | ||
] | ||
for atlas in available_atlases: | ||
name = f"{atlas.atlas_name}_v{atlas.version}" | ||
if name not in atlases.keys(): | ||
atlases[str(name)] = dict( | ||
downloaded=False, | ||
local="[red]---[/red]", | ||
online=atlas._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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ treelib | |
pandas | ||
requests | ||
meshio | ||
click | ||
click | ||
rich |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import brainatlas_api | ||
|
||
|
||
def test_list_atlases(): | ||
brainatlas_api.list_atlases() | ||
|
||
|
||
def test_get_atlas_from_name(): | ||
a1 = brainatlas_api.get_atlas_class_from_name("allen_mouse_25um_v0.2") | ||
a2 = brainatlas_api.get_atlas_class_from_name("xxxx") | ||
|
||
if a1 is None: | ||
raise ValueError | ||
if a2 is not None: | ||
raise ValueError |