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

Default selected_allen_id is entire brain, support None #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion ccfwidget/structure_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ def _process_node(tree_parent, node):
for child in node['children']:
_process_node(tree_node, child)

tree = TreeNode(None, None)
# "Basic cell groups and regions"
tree = TreeNode(8, 'BFDAE3')
allen_id_to_tree_node[8] = tree
acronym_to_allen_id['grey'] = 8

for node in structure_graph['children']:
_process_node(tree, node)

allen_id_to_acronym = { v: k for k, v in acronym_to_allen_id.items() }
allen_id_to_acronym[8] = 'grey'
29 changes: 18 additions & 11 deletions ccfwidget/widget_ccf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class CCFWidget(HBox):
off_weight = 0.05
on_weight = 1.0

selected_acronyms = List(trait=Unicode(), help='Structure Allen Ids to highlight.')
selected_allen_ids = List(trait=CInt(), help='Structure Allen Ids to highlight.')
selected_acronyms = List(allow_none=True, trait=Unicode(), help='Structure Allen Ids to highlight.')
selected_allen_ids = List(allow_none=True, trait=CInt(), help='Structure Allen Ids to highlight.')

markers = List(help='Marker locations to visualize.')
marker_sizes = List(help='Marker sizes.')
Expand All @@ -55,7 +55,7 @@ def __init__(self, tree=None,
marker_sizes=[],
marker_opacities=[],
marker_colors=[],
selected_allen_ids=None,
selected_allen_ids=[8,],
selected_acronyms=None,
rotate=False,
**kwargs):
Expand Down Expand Up @@ -220,6 +220,8 @@ def _ipytree_on_selected_change(self, change):
def _validate_selected_allen_ids(self, proposal):
self._validating_allen_ids = True
allen_ids = proposal['value']
if allen_ids is None:
allen_ids = []
self._highlight_allen_ids(allen_ids)
acronyms = [allen_id_to_acronym[allen_id] for allen_id in allen_ids]
if not self._validating_acronyms and \
Expand All @@ -232,6 +234,8 @@ def _validate_selected_allen_ids(self, proposal):
def _validate_selected_acronyms(self, proposal):
self._validating_acronyms = True
acronyms = proposal['value']
if acronyms is None:
acronyms = []
allen_ids = [acronym_to_allen_id[acronym] for acronym in acronyms]
if not self._validating_allen_ids and \
not self.selected_allen_ids == allen_ids:
Expand All @@ -240,15 +244,17 @@ def _validate_selected_acronyms(self, proposal):
return acronyms

def _highlight_allen_ids(self, allen_ids):
weights = np.ones((len(self.labels),), dtype=np.float32)*self.off_weight
weights = np.ones((len(self.labels),), dtype=np.float32)
if allen_ids and 8 in allen_ids:
# Optimization for the entire brain
weights *= self.on_weight
else:
weights *= self.off_weight
for allen_id in allen_ids:
labels_for_id = labels_for_allen_id(allen_id)
weights[labels_for_id] = self.on_weight
# Background
weights[0] = 0.0
for allen_id in allen_ids:
labels_for_id = labels_for_allen_id(allen_id)
weights[labels_for_id] = self.on_weight

if not allen_ids:
return

surfaces = [structure_mesh(allen_id) for allen_id in allen_ids]
self.itk_viewer.geometries = self.swc_geometries + surfaces
Expand All @@ -258,7 +264,8 @@ def _highlight_allen_ids(self, allen_ids):
for allen_id in allen_ids:
hex_color = '#' + allen_id_to_tree_node[allen_id].color_hex_triplet
colors.append(matplotlib.colors.to_rgb(hex_color))
self.itk_viewer.geometry_colors = np.array(colors, dtype=np.float32)
if colors:
self.itk_viewer.geometry_colors = np.array(colors, dtype=np.float32)

self.itk_viewer.label_image_weights = weights

Expand Down
2 changes: 1 addition & 1 deletion examples/StructureTreeNavigation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7747772eefca4d03a1ec7e8d076b23e8",
"model_id": "f720390e88ca4f0caaa693e61c0d3181",
"version_major": 2,
"version_minor": 0
},
Expand Down