This repository was archived by the owner on Feb 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Update thalamus #11
Merged
Merged
Update thalamus #11
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d183a67
Overhaul the thalamus into steps, and add docs
f4ed2e8
Improve Blender instructions
2a8736e
Change thalamus region list regex
a84d85a
Update layer names to be Atlas-Pipeline-compatible
7e9bcf2
Fix formatting errors
196cca6
Attempt to update tests for new thal workflow
eb8e4aa
Replace part of test anno with region in metadata
4abad7b
fix test + format
arnaudon db44cea
format
arnaudon ce2914d
Fix final linting issues
0919e6d
Make Alexis changes to CLI
b5371ba
Apply MG code review changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -74,6 +74,7 @@ def _placement_hints( # pylint: disable=too-many-locals | |
max_thicknesses: Optional[List[float]] = None, | ||
flip_direction_vectors: bool = False, | ||
has_hemispheres: bool = False, | ||
thalamus_meshes_dir: str = "", | ||
) -> None: | ||
""" | ||
Compute the placement hints for a laminar region of the mouse brain. | ||
|
@@ -93,6 +94,10 @@ def _placement_hints( # pylint: disable=too-many-locals | |
has_hemispheres: (optional) If True, split the volume into halves along the z-axis and | ||
handle each of theses 'hemispheres' separately. Otherwise the whole volume is handled. | ||
Defaults to True. | ||
thalamus_meshes_dir: (optional) Path of the directory to load thalamus meshes | ||
from. Currently only used for thalamus. Required if you are producing thalamus | ||
placement-hints. Defaults to None. | ||
|
||
""" | ||
direction_vectors = voxcell.VoxelData.load_nrrd(direction_vectors_path) | ||
assert_meta_properties([direction_vectors, atlas.region]) | ||
|
@@ -106,6 +111,7 @@ def _placement_hints( # pylint: disable=too-many-locals | |
max_thicknesses, | ||
flip_direction_vectors=flip_direction_vectors, | ||
has_hemispheres=has_hemispheres, | ||
thalamus_meshes_dir=thalamus_meshes_dir, | ||
) | ||
if not Path(output_dir).exists(): | ||
os.makedirs(output_dir) | ||
|
@@ -305,41 +311,84 @@ def isocortex( | |
required=True, | ||
help="path of the directory to write. It will be created if it doesn't exist.", | ||
) | ||
@click.option( | ||
"--thalamus-meshes-dir", | ||
required=True, | ||
help="""Path of the directory to use for either saving or loading thalamus | ||
meshes. It will be created if it doesn't exist.""", | ||
) | ||
@click.option( | ||
"--load-cut-thalamus-meshes", | ||
required=False, | ||
help="""(Optional) Flag to load your custom thalamus meshes, and then use | ||
them to calculate placement-hints.""", | ||
default=False, | ||
is_flag=True, | ||
) | ||
@log_args(L) | ||
# pylint: disable=too-many-arguments | ||
def thalamus( | ||
verbose, annotation_path, hierarchy_path, metadata_path, direction_vectors_path, output_dir | ||
verbose, | ||
annotation_path, | ||
hierarchy_path, | ||
metadata_path, | ||
direction_vectors_path, | ||
output_dir, | ||
thalamus_meshes_dir, | ||
load_cut_thalamus_meshes, | ||
): | ||
"""Generate and save the placement hints of the mouse thalamus. | ||
|
||
Placement hints are saved under the names sepecified in `app/metadata/thalamus_metadata.json`. | ||
Default to: | ||
First, call this without passing '--load-cut-thalamus-meshes' to | ||
create your region meshes, but not your placement-hints. Then, hand-cut | ||
your meshes according to the documentation in | ||
'atlas_placement_hints/layered_atlas.py::ThalamusAtlas'. Finally, call | ||
this again while passing '--load-cut-thalamus-meshes'. | ||
|
||
Placement hints are saved under the names specified in | ||
`app/metadata/thalamus_metadata.json`. These default to: | ||
|
||
\b | ||
- `[PH]y.nrrd` | ||
- `[PH]Rt.nrrd`, `[PH]VPL.nrrd` | ||
- `[PH]layer_1.nrrd` (This is the "top-most" layer, equivalent to "RT". | ||
This previously used the filename `[PH]RT.nrrd`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason you're calling it "layer 1" instead of RT? I find the later easier to reason about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's a new requirement imposed by the BBP Atlas Pipeline: for any rules that apply region-specific customization (such as placement hints for the thalamus), the output files need to be named in a very particular way. If you have questions, slack me or look at the "Customize a pipeline rule" section of the BBP Atlas Pipeline README. |
||
- `[PH]layer_2.nrrd` (This is the "deepest" layer, equivalent to the | ||
thalamus except the habenular, peripeduncular, and reticular regions. | ||
This previously used the filename `[PH]THnotRT.nrrd`) | ||
|
||
A report together with an nrrd volume on problematic distance computations are generated | ||
in `output_dir` under the names: | ||
A report together with an nrrd volume on problematic distance computations | ||
are generated in `output_dir` under the names: | ||
|
||
\b | ||
- `distance_report.json` | ||
- `<Thalamus>_problematic_voxel_mask.nrrd` (mask of the voxels for which the computed | ||
placement hints cannot be trusted). <Thalamus> is the region name specified in | ||
thalamus_metadata.json. Defaults to "Thalamus". | ||
|
||
The annotation file can contain the thalamus or a superset. | ||
For the algorithm to work properly, some space should separate the boundary | ||
of the thalamus from the boundary of its enclosing array. | ||
- `<Thalamus>_problematic_voxel_mask.nrrd` (mask of the voxels for which | ||
the computed placement hints cannot be trusted). <Thalamus> is the | ||
region name specified in thalamus_metadata.json. Defaults to "Thalamus". | ||
|
||
The annotation file can contain the thalamus or a superset. For the | ||
algorithm to work properly, some space should separate the boundary of the | ||
thalamus from the boundary of its enclosing array. | ||
|
||
For instructions on all steps necessary to generate the thalamus' placement | ||
hints, see | ||
'atlas-placement-hints/atlas_placement_hints/layered_atlas.py::ThalamusAtlas' | ||
and its methods for details. | ||
""" | ||
set_verbose(L, verbose) | ||
|
||
atlas = _create_layered_atlas(annotation_path, hierarchy_path, metadata_path) | ||
_placement_hints( | ||
atlas, | ||
direction_vectors_path, | ||
output_dir, | ||
has_hemispheres=True, | ||
) | ||
|
||
if load_cut_thalamus_meshes: | ||
_placement_hints( | ||
atlas, | ||
direction_vectors_path, | ||
output_dir, | ||
thalamus_meshes_dir=thalamus_meshes_dir, | ||
has_hemispheres=True, | ||
) | ||
else: | ||
Path(thalamus_meshes_dir).mkdir(parents=True, exist_ok=True) | ||
atlas.create_uncut_thalamus_meshes(thalamus_meshes_dir) | ||
|
||
|
||
@app.command() | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.