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

Atlas packaging template #400

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fcb1bf9
First version of the template script
PolarBean Aug 28, 2024
6dc6052
make example_mouse follow the new template
PolarBean Aug 28, 2024
37a75fb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
193a78b
Fix error in example mouse
PolarBean Aug 28, 2024
cd9bafe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
d96ed9d
mixed up reference and annotation
PolarBean Aug 28, 2024
2254886
added mandatory import to template
PolarBean Aug 28, 2024
813b251
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
c521a2f
remove import from example
PolarBean Aug 28, 2024
602dbef
added mandatory import to template
PolarBean Aug 28, 2024
f4b0452
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
9009dc2
include case where variables should be passed between functions
PolarBean Aug 29, 2024
1383b14
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
2b0d42e
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
c47ca80
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
262a07c
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
c51231c
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
fca9c7b
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
8052298
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2024
91c09f7
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
3ebdbd4
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
6cc3222
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
73387c0
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
23b3a16
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2024
4740c06
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
f6253e0
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
af0f450
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 11, 2024
91b97c8
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/template_sc…
PolarBean Sep 11, 2024
d9bc6e3
keep lines shorter than limit and only run code in __main__
PolarBean Sep 11, 2024
2ee5c7b
reformat example mouse
PolarBean Sep 11, 2024
1e68bed
use pooch to validate hash
PolarBean Sep 11, 2024
924e484
add bg_root_dir global
PolarBean Sep 11, 2024
d643653
fix references to annotation and reference
PolarBean Sep 11, 2024
78fe6d5
fix error in the way structure id paths were shown in the example
PolarBean Sep 12, 2024
642e0bb
fix typo
PolarBean Sep 12, 2024
536281f
Update brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mou…
PolarBean Sep 18, 2024
df352c3
adjust comment suggestion to be compliant with the 79 character line …
PolarBean Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 126 additions & 56 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__version__ = "2"

from pathlib import Path

import pooch

Check warning on line 3 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L3

Added line #L3 was not covered by tests
from allensdk.api.queries.ontologies_api import OntologiesApi
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.core.reference_space_cache import ReferenceSpaceCache
Expand All @@ -10,58 +9,136 @@

from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data


def create_atlas(working_dir, resolution):
# Specify information about the atlas:
RES_UM = resolution # 100
ATLAS_NAME = "example_mouse"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
ORIENTATION = "asr"

# Temporary folder for nrrd files download:
download_dir_path = working_dir / "downloading_path"
# a working example atlas-packaging script, which makes a simplified version
# of the Allen Mouse Brain Atlas, at 100um resolution. See `template_script.py`
# for a starting point to package your own atlas.
__version__ = 0 # This will make the example mouse version 1.0
ATLAS_NAME = "example_mouse"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
SPECIES = "Mus musculus" # The scientific name of the species,
ATLAS_LINK = "http://www.brain-map.org" # The URL for the data files
ORIENTATION = "asr" # The orientation of the atlas
ROOT_ID = 997 # The id of the highest level of the atlas.
RESOLUTION = 100 # The resolution of your volume in microns.

Check warning on line 22 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L15-L22

Added lines #L15 - L22 were not covered by tests

BG_ROOT_DIR = Path.home() / "brainglobe_workingdir" / ATLAS_NAME

Check warning on line 24 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L24

Added line #L24 was not covered by tests


def download_resources():

Check warning on line 27 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L27

Added line #L27 was not covered by tests
"""
Download the necessary resources for the atlas. Here we don't, because we
can out-source this to the Allen SDK in later functions.
"""
pass

Check warning on line 32 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L32

Added line #L32 was not covered by tests


def retrieve_reference_and_annotation():

Check warning on line 35 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L35

Added line #L35 was not covered by tests
"""
Retrieve the Allen Mouse atlas reference and annotation as two numpy arrays
using the allen_sdk.

Returns:
tuple: A tuple containing two numpy arrays. The first array is the
reference volume, and the second array is the annotated volume.
"""
# Create temporary download directory
download_dir_path = BG_ROOT_DIR / "downloading_path"
print(download_dir_path)

Check warning on line 46 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L45-L46

Added lines #L45 - L46 were not covered by tests
download_dir_path.mkdir(exist_ok=True)

# Download annotated and template volume:
#########################################
# Setup the reference space cache
spacecache = ReferenceSpaceCache(
manifest=download_dir_path / "manifest.json",
# downloaded files are stored relative to here
resolution=RES_UM,
resolution=RESOLUTION,
reference_space_key="annotation/ccf_2017",
# use the latest version of the CCF
)

# Download
annotated_volume, _ = spacecache.get_annotation_volume()
template_volume, _ = spacecache.get_template_volume()
print("Download completed...")
reference_volume, _ = spacecache.get_template_volume()
annotation_volume, _ = spacecache.get_annotation_volume()
expected_reference_hash = (

Check warning on line 58 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L56-L58

Added lines #L56 - L58 were not covered by tests
"6c24cae773a5cf256586b0384af0ac93ad68564d211c9bdcff4bee9acf07786a"
)
expected_annotation_hash = (

Check warning on line 61 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L61

Added line #L61 was not covered by tests
"451e6a82f531d3db4b58056d024d3e2311703c2adc15cefa75e0268e7f0e69a4"
)
reference_hash = pooch.file_hash(

Check warning on line 64 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L64

Added line #L64 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

I worry that this is
a) not the way we typically use pooch and therefore confusing
b) more importantly, might look scary to new contributors coming more from the biology side

I'm tempted to remove any pooch-related things, and mention it in the template script only (which we already do in this PR)?

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 see your point, the only thing is that pooch here actually serves a purpose, to ensure that the files from the Allen don't change without notifying us. In this instance we would want pooch to confirm the hash of the file. I understand that it's non standard but I think that just comes with using the Allen API in the example.

An alternative would be to not use the allen API at all, instead just use the files from the allen informatics archive. The advantage to this is the example would become more of a standard atlas integration allowing us to use pooch, etc, instead of so much allen specific logic.

Copy link
Member

@alessandrofelder alessandrofelder Sep 19, 2024

Choose a reason for hiding this comment

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

An alternative would be to not use the allen API at all, instead just use the files from the allen informatics archive.

I think this would be great if you have the patience to implement this? 😁 Would this be possible/easy on the OntologiesAPI side for the meshes too?

The alternative is that we make a new issue to at some point move to a more standard atlas (e.g. we have recently generated a bird template for which we will host the data ourselves, and which has ITK snap annotations - our standard - so we could use that when the preprint is published.)

download_dir_path / "average_template_100.nrrd"
)
annotation_hash = pooch.file_hash(

Check warning on line 67 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L67

Added line #L67 was not covered by tests
download_dir_path / "annotation" / "ccf_2017" / "annotation_100.nrrd"
)
assert (

Check warning on line 70 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L70

Added line #L70 was not covered by tests
reference_hash == expected_reference_hash
), "The hash of the reference volume does not match the expected hash."

assert (

Check warning on line 74 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L74

Added line #L74 was not covered by tests
annotation_hash == expected_annotation_hash
), "The hash of the annotation volume does not match the expected hash."
# Download annotated and template volumes
return reference_volume, annotation_volume

Check warning on line 78 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L78

Added line #L78 was not covered by tests


def retrieve_hemisphere_map():

Check warning on line 81 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L81

Added line #L81 was not covered by tests
"""
The Allen atlas is symmetrical, so we can just return `None` in this
function.

# Download structures tree and meshes:
######################################
oapi = OntologiesApi() # ontologies
struct_tree = spacecache.get_structure_tree() # structures tree
Returns:
numpy.array or None: A numpy array representing the hemisphere map,
or None if the atlas is symmetrical.
"""
return None

Check warning on line 90 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L90

Added line #L90 was not covered by tests


def retrieve_structure_information():

Check warning on line 93 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L93

Added line #L93 was not covered by tests
"""
Retrieve the structures tree and meshes for the Allen mouse brain atlas.

Returns:
pandas.DataFrame: A DataFrame containing the atlas information.
"""
download_dir_path = BG_ROOT_DIR / "downloading_path"
oapi = OntologiesApi()

Check warning on line 101 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L100-L101

Added lines #L100 - L101 were not covered by tests

spacecache = ReferenceSpaceCache(

Check warning on line 103 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L103

Added line #L103 was not covered by tests
manifest=download_dir_path / "manifest.json",
resolution=RESOLUTION,
reference_space_key="annotation/ccf_2017",
)
struct_tree = spacecache.get_structure_tree() # Download structures tree

Check warning on line 108 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L108

Added line #L108 was not covered by tests

# Find id of set of regions with mesh:
select_set = (
"Structures whose surfaces are represented by a precomputed mesh"
)

mesh_set_ids = [
s["id"]
for s in oapi.get_structure_sets()
if s["description"] == select_set
]

structs_with_mesh = struct_tree.get_structures_by_set_id(mesh_set_ids)[:3]

# Directory for mesh saving:
meshes_dir = working_dir / "mesh_temp_download"
# Loop over structures, remove entries not used
for struct in structs_with_mesh:
[

Check warning on line 122 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L121-L122

Added lines #L121 - L122 were not covered by tests
struct.pop(k)
for k in ["graph_id", "structure_set_ids", "graph_order"]
]
return structs_with_mesh

Check warning on line 126 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L126

Added line #L126 was not covered by tests


def retrieve_or_construct_meshes():

Check warning on line 129 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L129

Added line #L129 was not covered by tests
"""
This function should return a dictionary of ids and corresponding paths to
mesh files. This atlas comes packaged with mesh files, so we don't need to
use our helper functions to create them ourselves in this case.
"""
space = ReferenceSpaceApi()
meshes_dir = BG_ROOT_DIR / "mesh_temp_download"
meshes_dir.mkdir(exist_ok=True)

Check warning on line 137 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L136-L137

Added lines #L136 - L137 were not covered by tests

meshes_dict = dict()
structs_with_mesh = retrieve_structure_information()

Check warning on line 140 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L140

Added line #L140 was not covered by tests

for s in tqdm(structs_with_mesh):
name = s["id"]
filename = meshes_dir / f"{name}.obj"
Expand All @@ -74,41 +151,34 @@
meshes_dict[name] = filename
except (exceptions.HTTPError, ConnectionError):
print(s)
return meshes_dict

Check warning on line 154 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L154

Added line #L154 was not covered by tests

# Loop over structures, remove entries not used:
for struct in structs_with_mesh:
[
struct.pop(k)
for k in ["graph_id", "structure_set_ids", "graph_order"]
]

# Wrap up, compress, and remove file:
print("Finalising atlas")
# Set up for the example mouse done: use default code to wrap up the atlas
BG_ROOT_DIR.mkdir(exist_ok=True)
download_resources()
reference_volume, annotated_volume = retrieve_reference_and_annotation()
hemispheres_stack = retrieve_hemisphere_map()
structures = retrieve_structure_information()
meshes_dict = retrieve_or_construct_meshes()
if __name__ == "__main__":

Check warning on line 164 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L158-L164

Added lines #L158 - L164 were not covered by tests

output_filename = wrapup_atlas_from_data(
atlas_name=ATLAS_NAME,
atlas_minor_version=__version__,
citation=CITATION,
atlas_link=ATLAS_LINK,
species=SPECIES,
resolution=(RES_UM,) * 3,
resolution=(RESOLUTION,) * 3,
orientation=ORIENTATION,
root_id=997,
reference_stack=template_volume,
root_id=ROOT_ID,
reference_stack=reference_volume,
annotation_stack=annotated_volume,
structures_list=structs_with_mesh,
structures_list=structures,
meshes_dict=meshes_dict,
working_dir=working_dir,
hemispheres_stack=None,
working_dir=BG_ROOT_DIR,
hemispheres_stack=hemispheres_stack,
cleanup_files=False,
compress=True,
scale_meshes=True,
)

return output_filename


if __name__ == "__main__":
# Generated atlas path:
bg_root_dir = Path.home() / "brainglobe_workingdir" / "example"
bg_root_dir.mkdir(exist_ok=True)

# create_atlas(working_dir, 100)
147 changes: 147 additions & 0 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
from pathlib import Path

Check warning on line 1 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L1

Added line #L1 was not covered by tests

from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data

Check warning on line 3 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L3

Added line #L3 was not covered by tests
PolarBean marked this conversation as resolved.
Show resolved Hide resolved

PolarBean marked this conversation as resolved.
Show resolved Hide resolved
# Copy-paste this script into a new file and fill in the functions to package
# your own atlas.

### Metadata ###

# The minor version of the atlas in the brainglobe_atlasapi, this is internal,
# if this is the first time this atlas has been added the value should be 0
# (minor version is the first number after the decimal point, ie the minor
# version of 1.2 is 2)
__version__ = 0

Check warning on line 14 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L14

Added line #L14 was not covered by tests

# The expected format is FirstAuthor_SpeciesCommonName, e.g. kleven_rat, or
# Institution_SpeciesCommonName, e.g. allen_mouse.
ATLAS_NAME = "example_mouse"

Check warning on line 18 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L18

Added line #L18 was not covered by tests

# DOI of the most relevant citable document
CITATION = None

Check warning on line 21 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L21

Added line #L21 was not covered by tests

# The scientific name of the species, ie; Rattus norvegicus
SPECIES = None

Check warning on line 24 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L24

Added line #L24 was not covered by tests

# The URL for the data files
ATLAS_LINK = None

Check warning on line 27 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L27

Added line #L27 was not covered by tests

# The orientation of the **original** atlas data, in BrainGlobe convention:
# https://brainglobe.info/documentation/setting-up/image-definition.html#orientation
ORIENTATION = "asr"

Check warning on line 31 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L31

Added line #L31 was not covered by tests

# The id of the highest level of the atlas. This is commonly called root or
# brain. Include some information on what to do if your atlas is not
# hierarchical
ROOT_ID = None

Check warning on line 36 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L36

Added line #L36 was not covered by tests

# The resolution of your volume in microns. Details on how to format this
# parameter for non isotropic datasets or datasets with multiple resolutions.
RESOLUTION = None

Check warning on line 40 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L40

Added line #L40 was not covered by tests


def download_resources():

Check warning on line 43 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L43

Added line #L43 was not covered by tests
"""
Download the necessary resources for the atlas.

If possible, please use the Pooch library to retrieve any resources.
"""
pass

Check warning on line 49 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L49

Added line #L49 was not covered by tests


def retrieve_reference_and_annotation():

Check warning on line 52 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L52

Added line #L52 was not covered by tests
"""
Retrieve the desired reference and annotation as two numpy arrays.

Returns:
tuple: A tuple containing two numpy arrays. The first array is the
reference volume, and the second array is the annotation volume.
"""
reference = None
annotation = None
return reference, annotation

Check warning on line 62 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L60-L62

Added lines #L60 - L62 were not covered by tests


def retrieve_hemisphere_map():

Check warning on line 65 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L65

Added line #L65 was not covered by tests
"""
Retrieve a hemisphere map for the atlas.

If your atlas is asymmetrical, you may want to use a hemisphere map.
This is an array in the same shape as your template,
with 0's marking the left hemisphere, and 1's marking the right.

If your atlas is symmetrical, ignore this function.

Returns:
numpy.array or None: A numpy array representing the hemisphere map,
or None if the atlas is symmetrical.
"""
return None

Check warning on line 79 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L79

Added line #L79 was not covered by tests


def retrieve_structure_information():

Check warning on line 82 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L82

Added line #L82 was not covered by tests
"""
This function should return a pandas DataFrame with information about your
atlas.

The DataFrame should be in the following format:

╭────┬───────────────────┬─────────┬───────────────────┬─────────────────╮
| id | name | acronym | structure_id_path | rgb_triplet |
| | | | | |
├────┼───────────────────┼─────────┼───────────────────┼─────────────────┤
| 997| root | root | [997] | [255, 255, 255] |
├────┼───────────────────┼─────────┼───────────────────┼─────────────────┤
| 8 | Basic cell groups | grey | [997, 8] | [191, 218, 227] |
├────┼───────────────────┼─────────┼───────────────────┼─────────────────┤
| 567| Cerebrum | CH | [997, 8, 567] | [176, 240, 255] |
╰────┴───────────────────┴─────────┴───────────────────┴─────────────────╯

Returns:
pandas.DataFrame: A DataFrame containing the atlas information.
"""
return None

Check warning on line 103 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L103

Added line #L103 was not covered by tests


def retrieve_or_construct_meshes():

Check warning on line 106 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L106

Added line #L106 was not covered by tests
"""
This function should return a dictionary of ids and corresponding paths to
mesh files. Some atlases are packaged with mesh files, in these cases we
should use these files. Then this function should download those meshes.
In other cases we need to construct the meshes ourselves. For this we have
helper functions to achieve this.
"""
meshes_dict = {}
return meshes_dict

Check warning on line 115 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L114-L115

Added lines #L114 - L115 were not covered by tests


### If the code above this line has been filled correctly, nothing needs to be
### edited below (unless variables need to be passed between the functions).
if __name__ == "__main__":
bg_root_dir = Path.home() / "brainglobe_workingdir" / ATLAS_NAME
bg_root_dir.mkdir(exist_ok=True)
download_resources()
reference_volume, annotated_volume = retrieve_reference_and_annotation()
hemispheres_stack = retrieve_hemisphere_map()
structures = retrieve_structure_information()
meshes_dict = retrieve_or_construct_meshes()

Check warning on line 127 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L120-L127

Added lines #L120 - L127 were not covered by tests

output_filename = wrapup_atlas_from_data(

Check warning on line 129 in brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/template_script.py#L129

Added line #L129 was not covered by tests
atlas_name=ATLAS_NAME,
atlas_minor_version=__version__,
citation=CITATION,
atlas_link=ATLAS_LINK,
species=SPECIES,
resolution=(RESOLUTION,) * 3,
orientation=ORIENTATION,
root_id=ROOT_ID,
reference_stack=reference_volume,
annotation_stack=annotated_volume,
structures_list=structures,
meshes_dict=meshes_dict,
working_dir=bg_root_dir,
hemispheres_stack=None,
cleanup_files=False,
compress=True,
scale_meshes=True,
)
Loading