Skip to content

Commit 457d558

Browse files
Save the pool color in the exported table
1 parent d0f284a commit 457d558

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

synapse_net/tools/vesicle_pool_widget.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def _update_pool_colors(self, pool_name, pool_color):
108108
next_color = pool_color
109109
self.pool_colors[pool_name] = next_color
110110

111+
def _add_colors(self, pool_properties, vesicle_colors):
112+
colors = np.array([vesicle_colors[label_id] for label_id in pool_properties.label.values])
113+
pool_properties["color"] = colors
114+
return pool_properties
115+
111116
def _compute_vesicle_pool(
112117
self,
113118
segmentation: np.ndarray,
@@ -136,9 +141,9 @@ def _compute_vesicle_pool(
136141
show_info("ERROR: Neither distances nor vesicle morphology were found.")
137142
return
138143
elif distances is None and morphology is not None: # Only morphology props were found.
139-
merged_df = pd.DataFrame(morphology).drop(columns=["index"])
144+
merged_df = pd.DataFrame(morphology).drop(columns=["index"], errors="ignore")
140145
elif distances is not None and morphology is None: # Only distances were found.
141-
merged_df = pd.DataFrame(distances).drop(columns=["index"])
146+
merged_df = pd.DataFrame(distances).drop(columns=["index"], errors="ignore")
142147
else: # Both were found.
143148
distance_ids = distances.get("label", [])
144149
morphology_ids = morphology.get("label", [])
@@ -190,7 +195,7 @@ def _compute_vesicle_pool(
190195
# Overwrite the intersection of the two pool assignments with the new pool.
191196
pool_intersections = np.intersect1d(pool_vesicle_ids, old_pool_ids)
192197
old_pool_ids = [item for item in old_pool_ids if item not in pool_intersections]
193-
pool_properties = pool_properties[~pool_properties['label'].isin(pool_intersections)]
198+
pool_properties = pool_properties[~pool_properties["label"].isin(pool_intersections)]
194199

195200
pool_assignments = sorted(pool_vesicle_ids + old_pool_ids)
196201

@@ -242,6 +247,7 @@ def _compute_vesicle_pool(
242247
else:
243248
pool_layer = self.viewer.add_labels(vesicle_pools, name=pool_layer_name, colormap=vesicle_colors)
244249

250+
pool_properties = self._add_colors(pool_properties, vesicle_colors)
245251
self._add_properties_and_table(pool_layer, pool_properties, save_path=self.save_path.text())
246252
pool_layer.refresh()
247253

0 commit comments

Comments
 (0)