Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 11 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
6 changes: 3 additions & 3 deletions atlas_placement_hints/app/metadata/thalamus_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

},
"layers": {
"names": ["RT", "THnotRT"],
"queries": ["RT", "@^\\bAD|AM|AMd|AMv|ATN|AV|CL|CM|DORpm|DORsm|EPI|Eth|GENd|GENv|IAD|IAM|IGL|ILM|IMD|IntG|LAT|LD|LGd|LGd-co|LGd-ip|LGd-sh|LGv|LGvl|LGvm|LH|LP|MD|MDc|MDl|MDm|MED|MG|MGd|MGm|MGv|MH|MTN|PCN|PF|PIL|PIN|PO|POL|PP|PR|PT|PVT|PoT|RE|REth|RH|SGN|SMT|SPA|SPF|SPFm|SPFp|SubG|TH|VAL|VENT|VM|VP|VPL|VPLpc|VPM|VPMpc|Xi\\b$"],
"names": ["layer_1", "layer_2"],
"queries": ["RT", "@^AD$|^AMd$|^AMv$|^AV$|^CL$|^CM$|^Eth$|^IAD$|^IAM$|^IGL$|^IMD$|^IntG$|^LD$|^LGd-co$|^LGd-ip$|^LGd-sh$|^LGv_O$|^LP$|^MD_O$|^MGd$|^MGm$|^MGv$|^PCN$|^PF$|^PIL$|^PO$|^POL$|^PR$|^PT$|^PVT$|^PoT$|^RE$|^RH$|^SGN$|^SMT$|^SPA$|^SPFm$|^SPFp$|^SubG$|^TH_O$|^VAL$|^VM$|^VPL$|^VPLpc$|^VPM$|^VPMpc$|^Xi$"],
"attribute": "acronym",
"with_descendants": false
}
}
}
87 changes: 68 additions & 19 deletions atlas_placement_hints/app/placement_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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])
Expand All @@ -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)
Expand Down Expand Up @@ -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`)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Expand Down
5 changes: 5 additions & 0 deletions atlas_placement_hints/compute_placement_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def compute_placement_hints(
max_thicknesses: Optional[List[float]] = None,
flip_direction_vectors: bool = False,
has_hemispheres: bool = True,
thalamus_meshes_dir: str = "",
) -> Tuple[DistanceInfo, Dict]:
"""
Compute the placement hints for a laminar region of the mouse brain.
Expand All @@ -43,6 +44,9 @@ def compute_placement_hints(
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.

Returns:
Tuple with the following items.
Expand Down Expand Up @@ -70,6 +74,7 @@ def compute_placement_hints(
direction_vectors,
flip_direction_vectors=flip_direction_vectors,
has_hemispheres=has_hemispheres,
thalamus_meshes_dir=thalamus_meshes_dir,
)

distances_to_meshes = distances_info["distances_to_layer_boundaries"]
Expand Down
6 changes: 3 additions & 3 deletions atlas_placement_hints/distances/create_watertight_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def create_watertight_trimesh(
optimized_mesh = trimesh.load_mesh(output_filepath_opt)

if optimization_info:
log_mesh_optimization_info(optimized_mesh, unoptimized_mesh)
log_mesh_optimization_info(optimized_mesh, unoptimized_mesh) # type: ignore

optimized_mesh.fix_normals()
return optimized_mesh
optimized_mesh.fix_normals() # type: ignore
return optimized_mesh # type: ignore
Loading