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

Add Cuttlebase cuttlefish atlas #338

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
45834a1
Make empty cuttlefish.py file
kjungwoo5 Aug 2, 2024
2ace3d2
Download cuttlefish hierarchy file from github and amend format
kjungwoo5 Aug 8, 2024
1edcf82
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
4f16ca5
Tweaked region ID structure, loaded in region colour map from cuttlebase
kjungwoo5 Aug 10, 2024
947d056
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Aug 10, 2024
e440e5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 10, 2024
09ed09f
Applied RGB triplets and fixed acronyms for all regions
kjungwoo5 Aug 26, 2024
93dcd64
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Aug 29, 2024
6d5244d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2024
74d47c1
Revised hierarchy creation using annotation data, and added both left…
kjungwoo5 Sep 15, 2024
57d7f5b
Fixed structure ID path of all regions using the new IDs found from a…
kjungwoo5 Sep 29, 2024
ab5256d
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Sep 29, 2024
ede9d78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 29, 2024
b42a409
add wrapup function + minor tweaks
alessandrofelder Oct 4, 2024
6dd72b9
draft mesh creation
alessandrofelder Oct 4, 2024
0bae2f6
Added validation script to brainglobe main folder.
kjungwoo5 Oct 21, 2024
f2b7d02
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
ce5fecd
Updated mesh generation code to store meshes by correct ID. (In previ…
kjungwoo5 Nov 26, 2024
411fe4d
Scaled, rotated and inverted mesh to match the size of the annotation…
kjungwoo5 Dec 2, 2024
a8c23aa
Corrected meshes_dict in wrapup function, changed mesh generation to …
kjungwoo5 Dec 4, 2024
934d156
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Dec 4, 2024
6c45b7c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
98b3b3a
Edited validation script
kjungwoo5 Dec 5, 2024
407c874
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Dec 5, 2024
bbf96d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2024
84f9d47
Corrected the orientation of the meshes using map_points_to rather th…
kjungwoo5 Dec 8, 2024
80f188e
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Dec 8, 2024
ee46a9c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 8, 2024
f215042
Edited the atlas generation to be in 50um resolution, and changed sca…
kjungwoo5 Dec 9, 2024
82195e5
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Dec 9, 2024
92736a3
test to check for functionality of new branch
kjungwoo5 Jan 16, 2025
2101b6b
Remove test of branch functionality
kjungwoo5 Jan 16, 2025
13cb394
Remove mesh generation code from atlas generation script.
kjungwoo5 Jan 16, 2025
64c1fd3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2025
0b74776
Added mesh generation code to create our own meshes, rather than usin…
kjungwoo5 Jan 28, 2025
cd46ba5
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Jan 28, 2025
d7e5e3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 28, 2025
8f5f5f7
Removed temporary validation script, and cleaned up comments on atlas…
kjungwoo5 Jan 31, 2025
d61f5ab
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Jan 31, 2025
7d9fac5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
3051ae3
Removed mesh url, and added code to rescale template image to uint16
kjungwoo5 Feb 4, 2025
1136559
Merge branch 'cuttlefish-atlas' of https://github.com/kjungwoo5/brain…
kjungwoo5 Feb 4, 2025
5e1bf8e
rename script to match api name
PolarBean Feb 5, 2025
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
@@ -0,0 +1,362 @@
__version__ = "0"

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L1

Added line #L1 was not covered by tests

import csv
import glob as glob
import time
from pathlib import Path

Check warning on line 6 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L3-L6

Added lines #L3 - L6 were not covered by tests

import nrrd
import numpy as np
import pooch
from brainglobe_utils.IO.image import load
from rich.progress import track

Check warning on line 12 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L8-L12

Added lines #L8 - L12 were not covered by tests

from brainglobe_atlasapi import utils
from brainglobe_atlasapi.atlas_generation.mesh_utils import (

Check warning on line 15 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L14-L15

Added lines #L14 - L15 were not covered by tests
Region,
create_region_mesh,
)
from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

Check warning on line 20 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L19-L20

Added lines #L19 - L20 were not covered by tests


def hex_to_rgb(hex):
hex = hex.lstrip("#")
rgb = []
for i in (0, 2, 4):
decimal = int(hex[i : i + 2], 16)
rgb.append(decimal)

Check warning on line 28 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L23-L28

Added lines #L23 - L28 were not covered by tests

return rgb

Check warning on line 30 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L30

Added line #L30 was not covered by tests


def create_atlas(working_dir, resolution):
ATLAS_NAME = "columbia_cuttlefish"
SPECIES = "Sepia bandensis"
ATLAS_LINK = "https://www.cuttlebase.org/"
CITATION = (

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L33-L37

Added lines #L33 - L37 were not covered by tests
"Montague et al, 2023, https://doi.org/10.1016/j.cub.2023.06.007"
)
ORIENTATION = "srp"
ATLAS_PACKAGER = "Jung Woo Kim"
ADDITIONAL_METADATA = {}
ROOT_ID = 999
HIERARCHY_FILE_URL = "https://raw.githubusercontent.com/noisyneuron/cuttlebase-util/main/data/brain-hierarchy.csv" # noqa E501
TEMPLATE_URL = r"https://www.dropbox.com/scl/fo/fz8gnpt4xqduf0dnmgrat/ABflM0-v-b4_2WthGaeYM4s/Averaged%2C%20template%20brain/2023_FINAL-Cuttlebase_warped_template.nii.gz?rlkey=eklemeh57slu7v6j1gphqup4z&dl=1" # noqa E501
ANNOTATION_URL = r"https://www.dropbox.com/scl/fo/fz8gnpt4xqduf0dnmgrat/ALfSeAj81IM0v56bEeoTfUQ/Averaged%2C%20template%20brain/2023_FINAL-Cuttlebase_warped_template_lobe-labels.nii.seg.nrrd?rlkey=eklemeh57slu7v6j1gphqup4z&dl=1" # noqa E501

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L40-L46

Added lines #L40 - L46 were not covered by tests

download_dir_path = working_dir / "downloads"
download_dir_path.mkdir(exist_ok=True)

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L48-L49

Added lines #L48 - L49 were not covered by tests

# download hierarchy files
utils.check_internet_connection()
hierarchy_path = pooch.retrieve(

Check warning on line 53 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L52-L53

Added lines #L52 - L53 were not covered by tests
HIERARCHY_FILE_URL,
known_hash="023418e626bdefbd177d4bb8c08661bd63a95ccff47720e64bb7a71546935b77",
progressbar=True,
)

# import cuttlefish .nrrd file
annotation_path = pooch.retrieve(

Check warning on line 60 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L60

Added line #L60 was not covered by tests
ANNOTATION_URL,
known_hash="768973251b179902ab48499093a4cc870cb6507c09ce46ff76b8203daf243f82",
progressbar=True,
)

# process brain annotation file. There are a total of 70 segments.
print("Processing brain annotations:")
readdata, header = nrrd.read(annotation_path)

Check warning on line 68 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L67-L68

Added lines #L67 - L68 were not covered by tests

# Extract annotation mapping information from nrrd headers,
# to be applied to hierarchy file later.
mapping = []
for n in range(0, 70):
mapping.append(

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L72-L74

Added lines #L72 - L74 were not covered by tests
{
"color": header[f"Segment{n}_Color"],
"id": header[f"Segment{n}_LabelValue"],
"acronym": header[f"Segment{n}_Name"],
}
)

# convert the color information stored as a string of 3 RGB floats
# into a list of 3 RGB integers from 0 to 255.
for index, Map in enumerate(mapping):
mapping[index]["color"] = Map["color"].split(" ")
mapping[index]["color"] = list(map(float, mapping[index]["color"]))
mapping[index]["color"] = [

Check warning on line 87 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L84-L87

Added lines #L84 - L87 were not covered by tests
int(255 * x) for x in mapping[index]["color"]
]

# create dictionaries for regions hierarchy
print("Creating structure tree")
with open(

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L92-L93

Added lines #L92 - L93 were not covered by tests
hierarchy_path, mode="r", encoding="utf-8-sig"
) as cuttlefish_file:
cuttlefish_dict_reader = csv.DictReader(cuttlefish_file)

Check warning on line 96 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L96

Added line #L96 was not covered by tests

# empty list to populate with dictionaries
hierarchy = []

Check warning on line 99 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L99

Added line #L99 was not covered by tests

# parse through csv file and populate hierarchy list
for row in cuttlefish_dict_reader:
if row["hasSides"] == "Y":
leftSide = dict(row)
leftSide["abbreviation"] = leftSide["abbreviation"] + "l"
leftSide["name"] = leftSide["name"] + " (left)"

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L102-L106

Added lines #L102 - L106 were not covered by tests

rightSide = dict(row)
rightSide["abbreviation"] = rightSide["abbreviation"] + "r"
rightSide["name"] = rightSide["name"] + " (right)"

Check warning on line 110 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L108-L110

Added lines #L108 - L110 were not covered by tests

hierarchy.append(leftSide)
hierarchy.append(rightSide)

Check warning on line 113 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L112-L113

Added lines #L112 - L113 were not covered by tests
else:
hierarchy.append(row)

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L115

Added line #L115 was not covered by tests

# use layers to give IDs to regions which do not have existing IDs.
layer1 = 100
layer2 = 200

Check warning on line 119 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L118-L119

Added lines #L118 - L119 were not covered by tests
# remove 'hasSides' and 'function' keys,
# reorder and rename the remaining keys
for i in range(0, len(hierarchy)):
hierarchy[i]["acronym"] = hierarchy[i].pop("abbreviation")
hierarchy[i].pop("hasSides")
hierarchy[i].pop("function")
hierarchy[i]["structure_id_path"] = list(

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

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L122-L126

Added lines #L122 - L126 were not covered by tests
(map(int, (hierarchy[i]["index"].split("-"))))
)
hierarchy[i]["structure_id_path"].insert(0, 999)
hierarchy[i].pop("index")
if (

Check warning on line 131 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L129-L131

Added lines #L129 - L131 were not covered by tests
len(hierarchy[i]["structure_id_path"]) < 4
and hierarchy[i]["structure_id_path"][-2] != 3
):
if len(hierarchy[i]["structure_id_path"]) == 3:
hierarchy[i]["id"] = layer2
layer2 += 1
elif len(hierarchy[i]["structure_id_path"]) == 2:
hierarchy[i]["id"] = layer1
layer1 += 1
if hierarchy[i]["acronym"] == "SB":
hierarchy[i]["id"] = 71
elif hierarchy[i]["acronym"] == "IB":
hierarchy[i]["id"] = 72

Check warning on line 144 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L135-L144

Added lines #L135 - L144 were not covered by tests

# remove erroneous key for the VS region
# (error due to commas being included in the 'function' column)
hierarchy[-3].pop(None)
hierarchy[-4].pop(None)

Check warning on line 149 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L148-L149

Added lines #L148 - L149 were not covered by tests

# add the 'root' structure
hierarchy.append(

Check warning on line 152 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L152

Added line #L152 was not covered by tests
{
"name": "root",
"acronym": "root",
"structure_id_path": [999],
"id": ROOT_ID,
}
)

# apply colour and id map to each region
for index, region in enumerate(hierarchy):
for Map in mapping:
if region["acronym"] == Map["acronym"]:
hierarchy[index]["rgb_triplet"] = Map["color"]
hierarchy[index]["id"] = int(Map["id"])

Check warning on line 166 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L162-L166

Added lines #L162 - L166 were not covered by tests

# amend each region's structure_id_path by iterating through entire list,
# and replacing dummy values with actual ID values.
for i in range(0, len(hierarchy)):
if len(hierarchy[i]["structure_id_path"]) == 2:
hierarchy[i]["structure_id_path"][1] = hierarchy[i]["id"]
len2_shortest_index = i

Check warning on line 173 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L170-L173

Added lines #L170 - L173 were not covered by tests

elif len(hierarchy[i]["structure_id_path"]) == 3:
hierarchy[i]["structure_id_path"][1] = hierarchy[

Check warning on line 176 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L175-L176

Added lines #L175 - L176 were not covered by tests
len2_shortest_index
]["id"]
hierarchy[i]["structure_id_path"][2] = hierarchy[i]["id"]
len3_shortest_index = i

Check warning on line 180 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L179-L180

Added lines #L179 - L180 were not covered by tests

elif len(hierarchy[i]["structure_id_path"]) == 4:
hierarchy[i]["structure_id_path"][1] = hierarchy[

Check warning on line 183 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L182-L183

Added lines #L182 - L183 were not covered by tests
len2_shortest_index
]["id"]
hierarchy[i]["structure_id_path"][2] = hierarchy[

Check warning on line 186 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L186

Added line #L186 was not covered by tests
len3_shortest_index
]["id"]
hierarchy[i]["structure_id_path"][3] = hierarchy[i]["id"]

Check warning on line 189 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L189

Added line #L189 was not covered by tests

# original atlas does not give colours to some regions, so we give
# random RGB triplets to regions without specified RGB triplet values
random_rgb_triplets = [

Check warning on line 193 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L193

Added line #L193 was not covered by tests
[156, 23, 189],
[45, 178, 75],
[231, 98, 50],
[12, 200, 155],
[87, 34, 255],
[190, 145, 66],
[64, 199, 225],
[255, 120, 5],
[10, 45, 90],
[145, 222, 33],
[35, 167, 204],
[76, 0, 89],
[27, 237, 236],
[255, 255, 255],
]

n = 0
for index, region in enumerate(hierarchy):
if "rgb_triplet" not in region:
hierarchy[index]["rgb_triplet"] = random_rgb_triplets[n]
n = n + 1

Check warning on line 214 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L210-L214

Added lines #L210 - L214 were not covered by tests

# give filler acronyms for regions without specified acronyms
missing_acronyms = [

Check warning on line 217 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L217

Added line #L217 was not covered by tests
"SpEM",
"VLC",
"BsLC",
"SbEM",
"PLC",
"McLC",
"PvLC",
"BLC",
"PeM",
"OTC",
"NF",
]
n = 0
for index, region in enumerate(hierarchy):
if hierarchy[index]["acronym"] == "":
hierarchy[index]["acronym"] = missing_acronyms[n]
n = n + 1

Check warning on line 234 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L230-L234

Added lines #L230 - L234 were not covered by tests

# generate hierarchy tree
tree = get_structures_tree(hierarchy)
print(

Check warning on line 238 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L237-L238

Added lines #L237 - L238 were not covered by tests
f"Number of brain regions: {tree.size()}, "
f"max tree depth: {tree.depth()}"
)

# import cuttlefish .nii file
template_path = pooch.retrieve(

Check warning on line 244 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L244

Added line #L244 was not covered by tests
TEMPLATE_URL,
known_hash="195125305a11abe6786be1b32830a8aed1bc8f68948ad53fa84bf74efe7cbe9c", # noqa E501
progressbar=True,
)

# process brain template MRI file
print("Processing brain template:")
brain_template = load.load_nii(template_path, as_array=True)
dmin = np.min(brain_template)
dmax = np.max(brain_template)
drange = dmax - dmin
dscale = (2**16 - 1) / drange
brain_template = (brain_template - dmin) * dscale
brain_template = brain_template.astype(np.uint16)

Check warning on line 258 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L251-L258

Added lines #L251 - L258 were not covered by tests

# generate binary mask for mesh creation
# generate binary mask for mesh creation
labels = np.unique(readdata).astype(np.int_)
for key, node in tree.nodes.items():
if key in labels:
is_label = True

Check warning on line 265 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L262-L265

Added lines #L262 - L265 were not covered by tests
else:
is_label = False

Check warning on line 267 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L267

Added line #L267 was not covered by tests

node.data = Region(is_label)

Check warning on line 269 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L269

Added line #L269 was not covered by tests

# write meshes
atlas_dir_name = f"{ATLAS_NAME}_{resolution[0]}um_v1.{__version__}"
mesh_dir = Path(working_dir) / ATLAS_NAME / atlas_dir_name / "meshes"
mesh_dir.mkdir(exist_ok=True, parents=True)

Check warning on line 274 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L272-L274

Added lines #L272 - L274 were not covered by tests

# define smoothing information for meshes
closing_n_iters = 2
decimate_fraction = 0.3
smooth = True

Check warning on line 279 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L277-L279

Added lines #L277 - L279 were not covered by tests

start = time.time()

Check warning on line 281 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L281

Added line #L281 was not covered by tests

for node in track(

Check warning on line 283 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L283

Added line #L283 was not covered by tests
tree.nodes.values(),
total=tree.size(),
description="Creating meshes",
):
create_region_mesh(

Check warning on line 288 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L288

Added line #L288 was not covered by tests
(
mesh_dir,
node,
tree,
labels,
readdata,
ROOT_ID,
closing_n_iters,
decimate_fraction,
smooth,
)
)

print(

Check warning on line 302 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L302

Added line #L302 was not covered by tests
"Finished mesh extraction in : ",
round((time.time() - start) / 60, 2),
" minutes",
)

# create meshes_dict
meshes_dict = dict()
structures_with_mesh = []
for s in hierarchy:

Check warning on line 311 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L309-L311

Added lines #L309 - L311 were not covered by tests
# check if a mesh was created
mesh_path = mesh_dir / f"{s['id']}.obj"
if not mesh_path.exists():
print(f"No mesh file exists for: {s}, ignoring it.")
continue

Check warning on line 316 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L313-L316

Added lines #L313 - L316 were not covered by tests
else:
# check that the mesh actually exists and isn't empty
if mesh_path.stat().st_size < 512:
print(f"obj file for {s} is too small, ignoring it.")
continue
structures_with_mesh.append(s)
meshes_dict[s["id"]] = mesh_path

Check warning on line 323 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L319-L323

Added lines #L319 - L323 were not covered by tests

print(

Check warning on line 325 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L325

Added line #L325 was not covered by tests
f"In the end, {len(structures_with_mesh)} "
"structures with mesh are kept"
)

output_filename = wrapup_atlas_from_data(

Check warning on line 330 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L330

Added line #L330 was not covered by tests
atlas_name=ATLAS_NAME,
atlas_minor_version=__version__,
citation=CITATION,
atlas_link=ATLAS_LINK,
species=SPECIES,
resolution=resolution,
orientation=ORIENTATION,
root_id=ROOT_ID,
reference_stack=brain_template,
annotation_stack=readdata,
structures_list=hierarchy,
meshes_dict=meshes_dict,
scale_meshes=True,
working_dir=working_dir,
hemispheres_stack=None,
cleanup_files=False,
compress=True,
atlas_packager=ATLAS_PACKAGER,
additional_metadata=ADDITIONAL_METADATA,
additional_references={},
)

return output_filename

Check warning on line 353 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L353

Added line #L353 was not covered by tests


if __name__ == "__main__":
res = 50, 50, 50
home = str(Path.home())
bg_root_dir = Path.home() / "brainglobe_workingdir"
bg_root_dir.mkdir(exist_ok=True, parents=True)

Check warning on line 360 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L356-L360

Added lines #L356 - L360 were not covered by tests

create_atlas(bg_root_dir, res)

Check warning on line 362 in brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/columbia_cuttlefish.py#L362

Added line #L362 was not covered by tests
Loading