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

Fixing admba #322

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
__version__ = "0"
__version__ = "1"

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L1

Added line #L1 was not covered by tests

import dataclasses
import json
import multiprocessing as mp
import time
import zipfile
from os import listdir, path
from pathlib import Path
from typing import Tuple

import numpy as np
import pandas as pd
import pooch

Check warning on line 13 in brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L13

Added line #L13 was not covered by tests
from rich.progress import track
from skimage import io

Expand All @@ -22,24 +22,27 @@
from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

PARALLEL = True
PARALLEL = False

Check warning on line 25 in brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L25

Added line #L25 was not covered by tests


def download_atlas_files(download_dir_path, atlas_file_url, ATLAS_NAME):
utils.check_internet_connection()

atlas_files_dir = download_dir_path / ATLAS_NAME
try:
download_name = ATLAS_NAME + "_atlas.zip"
except TypeError:
download_name = ATLAS_NAME / "_atlas.zip"
destination_path = download_dir_path / download_name
utils.retrieve_over_http(atlas_file_url, destination_path)

with zipfile.ZipFile(destination_path, "r") as zip_ref:
zip_ref.extractall(atlas_files_dir)
pooch.retrieve(

Check warning on line 37 in brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L37

Added line #L37 was not covered by tests
url=atlas_file_url,
known_hash=None,
path=destination_path,
progressbar=True,
processor=pooch.Unzip(extract_dir="."),
)

return atlas_files_dir
return destination_path

Check warning on line 45 in brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L45

Added line #L45 was not covered by tests


def parse_structures(structures_file, root_id):
Expand Down Expand Up @@ -144,10 +147,11 @@
total=tree.size(),
description="Creating meshes",
):
# root_node = tree.nodes[root_id]
create_region_mesh(
(
meshes_dir_path,
node,
node, # root_node
tree,
labels,
annotated_volume,
Expand Down Expand Up @@ -298,14 +302,15 @@
cleanup_files=False,
compress=True,
scale_meshes=True,
resolution_mapping=[2, 1, 0],
)
print("Done. Atlas generated at: ", output_filename)
return output_filename


if __name__ == "__main__":
# Generated atlas path:
bg_root_dir = Path.home() / "brainglobe_workingdir"
bg_root_dir = Path.home() / ".brainglobe"

Check warning on line 313 in brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/admba_3d_dev_mouse.py#L313

Added line #L313 was not covered by tests
bg_root_dir.mkdir(exist_ok=True, parents=True)

# set up E11.5 atlas settings and use as template for rest of brains
Expand All @@ -314,8 +319,13 @@
species="Mus musculus",
atlas_link="https://search.kg.ebrains.eu/instances/8ab25629-bdac-47d0-bc86-6f3aa3885f29",
atlas_file_url="https://data.kg.ebrains.eu/zip?container=https://object.cscs.ch/v1/AUTH_4791e0a3b3de43e2840fe46d9dc2b334/ext-d000023_3Drecon-ADMBA-E11pt5_pub",
orientation="lsa",
resolution=(16, 16, 20),
orientation="rsa",
Copy link
Member

Choose a reason for hiding this comment

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

This is the correct way around, others need to be adapted!

resolution=(
16,
16,
20,
), # this is in ASR, the target orientation.
# The resolution in LR is lower than SI and AP!
citation="Young et al. 2021, https://doi.org/10.7554/eLife.61408",
root_id=15564,
atlas_packager="Pradeep Rajasekhar, WEHI, Australia, "
Expand Down Expand Up @@ -368,6 +378,7 @@
# P28 atlas, which has same resolutions as P14
p28_config = dataclasses.replace(
p14_config,
resolution=(16.752, 16.752, 25),
atlas_name="admba_3d_p28_mouse",
atlas_link="https://search.kg.ebrains.eu/instances/3a1153f0-6779-43bd-9f02-f92700a585a4",
atlas_file_url="https://data.kg.ebrains.eu/zip?container=https://object.cscs.ch/v1/AUTH_4791e0a3b3de43e2840fe46d9dc2b334/ext-d000029_3Drecon-ADMBA-P28_pub",
Expand Down
19 changes: 18 additions & 1 deletion brainglobe_atlasapi/atlas_generation/wrapup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
cleanup_files=False,
compress=True,
scale_meshes=False,
resolution_mapping=None,
additional_references={},
additional_metadata={},
):
Expand Down Expand Up @@ -102,6 +103,9 @@
If True the meshes points are scaled by the resolution
to ensure that they are specified in microns,
regardless of the atlas resolution.
resolution_mapping: list, optional
a list of three mapping the target space axes to the source axes
only needed for mesh scaling of anisotropic atlases
additional_references: dict, optional
(Default value = empty dict).
Dictionary with secondary reference stacks.
Expand Down Expand Up @@ -171,7 +175,20 @@

if scale_meshes:
# Scale the mesh to the desired resolution, BEFORE transforming:
mesh.points *= resolution
# Note that this transformation happens in original space,
# but the resolution is passed in target space (typically ASR)
if not resolution_mapping:

Check warning on line 180 in brainglobe_atlasapi/atlas_generation/wrapup.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/wrapup.py#L180

Added line #L180 was not covered by tests
# isotropic case, so don't need to re-map resolution
mesh.points *= resolution

Check warning on line 182 in brainglobe_atlasapi/atlas_generation/wrapup.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/wrapup.py#L182

Added line #L182 was not covered by tests
else:
# resolution needs to be transformed back
# to original space in anisotropic case
original_resolution = (

Check warning on line 186 in brainglobe_atlasapi/atlas_generation/wrapup.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/wrapup.py#L186

Added line #L186 was not covered by tests
resolution[resolution_mapping[0]],
resolution[resolution_mapping[1]],
resolution[resolution_mapping[2]],
)
mesh.points *= original_resolution

Check warning on line 191 in brainglobe_atlasapi/atlas_generation/wrapup.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/wrapup.py#L191

Added line #L191 was not covered by tests

# Reorient points:
mesh.points = space_convention.map_points_to(
Expand Down
Loading