Skip to content

Commit 9ceb256

Browse files
Merge branch 'main' into first-release
2 parents c0afedb + 458ec90 commit 9ceb256

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

synapse_net/tools/base_widget.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,8 @@ def _add_properties_and_table(self, layer, table_data, save_path=""):
330330
layer.properties = table_data
331331

332332
if add_table is not None:
333-
table = get_table(layer, self.viewer)
334-
if table is None:
335-
with _SilencePrint():
336-
add_table(layer, self.viewer)
337-
else:
338-
# FIXME updating the table does not yet work
339-
with _SilencePrint():
340-
table.update_content()
341-
# table_dict = table_data.to_dict()
342-
# table_dict["index"] = table_dict["label"]
343-
# table.set_content(table_dict)
333+
with _SilencePrint():
334+
add_table(layer, self.viewer)
344335

345336
# Save table to file if save path is provided.
346337
if save_path != "":

synapse_net/tools/distance_measure_widget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def on_measure_seg_to_object(self):
8787
seg_ids=seg_ids,
8888
)
8989
table_data = self._to_table_data(distances, seg_ids, endpoints1, endpoints2)
90-
self._add_lines_and_table(lines, table_data, name="distances")
90+
structure_layer_name = self._get_layer_selector_layer(self.image_selector_name2).name
91+
self._add_lines_and_table(lines, table_data, name="distances-to-" + structure_layer_name)
9192

9293
def on_measure_pairwise(self):
9394
segmentation = self._get_layer_selector_data(self.image_selector_name1)

synapse_net/tools/segmentation_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def on_predict(self):
189189
for name, seg in segmentation.items():
190190
self.viewer.add_labels(seg, name=name, metadata=metadata)
191191
else:
192-
self.viewer.add_labels(segmentation, name=f"{model_type}-segmentation", metadata=metadata)
192+
self.viewer.add_labels(segmentation, name=f"{model_type}", metadata=metadata)
193193
show_info(f"INFO: Segmentation of {model_type} added to layers.")
194194

195195
def _create_settings_widget(self):

synapse_net/tools/vesicle_pool_widget.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ def __init__(self):
3030
# 2. Selector for a distance layer.
3131
self.dist_selector_name1 = "Distances to Structure"
3232
self.dist_selector_widget1 = self._create_layer_selector(self.dist_selector_name1, layer_type="Shapes")
33+
# 3. Selector for a second distance layer (optional).
34+
self.dist_selector_name2 = "Distances to Structure 2"
35+
self.dist_selector_widget2 = self._create_layer_selector(self.dist_selector_name2, layer_type="Shapes")
3336

3437
# Add the selector widgets to the layout.
3538
layout.addWidget(self.vesicle_selector_widget)
3639
layout.addWidget(self.dist_selector_widget1)
40+
layout.addWidget(self.dist_selector_widget2)
3741

3842
# Create the UI elements for defining the vesicle pools:
3943
# The name of the output name, the name of the vesicle pool, and the criterion for the pool.
@@ -68,6 +72,11 @@ def on_pool_vesicles(self):
6872

6973
distance_layer = self._get_layer_selector_layer(self.dist_selector_name1)
7074
distances = None if distance_layer is None else distance_layer.properties
75+
distance_layer2 = self._get_layer_selector_layer(self.dist_selector_name2)
76+
# Check if the second distance is the same as the first.
77+
if distance_layer2.name == distance_layer.name:
78+
distance_layer2 = None
79+
distances2 = None if distance_layer2 is None else distance_layer2.properties
7180

7281
if segmentation is None:
7382
show_info("INFO: Please choose a segmentation.")
@@ -87,7 +96,9 @@ def on_pool_vesicles(self):
8796
pool_name = self.pool_name_param.text()
8897

8998
pool_color = self.pool_color_param.text()
90-
self._compute_vesicle_pool(segmentation, distances, morphology, pool_layer_name, pool_name, query, pool_color)
99+
self._compute_vesicle_pool(
100+
segmentation, distances, morphology, pool_layer_name, pool_name, query, pool_color, distances2
101+
)
91102

92103
def _update_pool_colors(self, pool_name, pool_color):
93104
if pool_color == "":
@@ -107,6 +118,7 @@ def _compute_vesicle_pool(
107118
pool_name: str,
108119
query: str,
109120
pool_color: str,
121+
distances2: Dict = None
110122
):
111123
"""Compute a vesicle pool based on the provided query parameters.
112124
@@ -118,6 +130,7 @@ def _compute_vesicle_pool(
118130
pool_name: Name for the pooled group to be assigned.
119131
query: Query parameters.
120132
pool_color: Optional color for the vesicle pool.
133+
distances2: Properties from the second distances layer (optional).
121134
"""
122135
# Check which of the properties are present and construct the combined properties based on this.
123136
if distances is None and morphology is None: # No properties were given -> we can't do anything.
@@ -140,7 +153,14 @@ def _compute_vesicle_pool(
140153
distances = pd.DataFrame(distances).drop(columns=["index"])
141154
morphology = pd.DataFrame(morphology).drop(columns=["index"])
142155
merged_df = morphology.merge(distances, left_on="label", right_on="label", suffixes=("_morph", "_dist"))
143-
156+
# Add distances2 if present.
157+
if distances2 is not None:
158+
distance_ids = distances2.get("label", [])
159+
if set(distance_ids) != set(merged_df.label):
160+
show_info("ERROR: The IDs in distances2 and morphology are not identical.")
161+
return
162+
distances2 = pd.DataFrame(distances2).drop(columns=["index"])
163+
merged_df = merged_df.merge(distances2, left_on="label", right_on="label", suffixes=("", "2"))
144164
# Assign the vesicles to the current pool by filtering the mergeddataframe based on the query.
145165
filtered_df = self._parse_query(query, merged_df)
146166
if len(filtered_df) == 0:
@@ -167,6 +187,12 @@ def _compute_vesicle_pool(
167187
# Combine the vesicle ids corresponding to the previous assignment with the
168188
# assignment for the new / current pool.
169189
old_pool_ids = pool_properties.label.values.tolist()
190+
191+
# Overwrite the intersection of the two pool assignments with the new pool.
192+
pool_intersections = np.intersect1d(pool_vesicle_ids, old_pool_ids)
193+
old_pool_ids = [item for item in old_pool_ids if item not in pool_intersections]
194+
pool_properties = pool_properties[~pool_properties['label'].isin(pool_intersections)]
195+
170196
pool_assignments = sorted(pool_vesicle_ids + old_pool_ids)
171197

172198
# Get a map for each vesicle id to its pool.

0 commit comments

Comments
 (0)