Skip to content

Commit cd0da18

Browse files
committed
Fix: update "One curve per result title" mode to respect ROIs in plot analysis
Fix #132
1 parent 69991b9 commit cd0da18

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.
1010

1111
🛠️ Bug fixes:
1212

13+
* Fixed [Issue #132](https://github.com/DataLab-Platform/DataLab/issues/132) - Plot analysis results: "One curve per result title" mode ignores ROIs
14+
* Before this fix, the "One curve per result title" mode was ignoring ROIs, and was plotting the selected result for all objects (signals or images) without taking into account the ROI defined on the objects
15+
* This is now fixed: the "One curve per result title" mode now takes into account the ROI defined on the objects, and plots the selected result for each object (signal or image) and for each ROI defined on the object
1316
* Fixed [Issue #128](https://github.com/DataLab-Platform/DataLab/issues/128) - Support long object titles in Signal and Image panels
1417
* Fixed [Issue #133](https://github.com/DataLab-Platform/DataLab/issues/133) - Remove specific analysis results from metadata clipboard during copy operation
1518
* Image ROI features:

cdl/core/gui/panel/base.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,33 +1286,56 @@ class PlotResultParam(gds.DataSet):
12861286

12871287
i_yaxis = rdata.xlabels.index(param.yaxis)
12881288
if param.kind == "one_curve_per_title":
1289-
# One curve per result title:
1290-
for title, results in grouped_results.items(): # title
1291-
x, y = [], []
1292-
for index, result in enumerate(results): # object
1293-
if param.xaxis == "indices":
1294-
x.append(index)
1295-
else:
1296-
i_xaxis = rdata.xlabels.index(param.xaxis)
1297-
x.append(result.shown_array[0][i_xaxis])
1298-
y.append(result.shown_array[0][i_yaxis])
1299-
self.__add_result_signal(x, y, title, param.xaxis, param.yaxis)
1289+
# One curve per ROI (if any) and per result title
1290+
# ------------------------------------------------------------------
1291+
# Begin by checking if all results have the same number of ROIs:
1292+
# for simplicity, let's check the number of unique ROI indices.
1293+
all_roi_indexes = [
1294+
np.unique(result.array[:, 0]) for result in rdata.results
1295+
]
1296+
# Check if all roi_indexes are the same:
1297+
if len(set(map(tuple, all_roi_indexes))) > 1:
1298+
QW.QMessageBox.warning(
1299+
self,
1300+
_("Plot results"),
1301+
_(
1302+
"All objects associated with results must have the "
1303+
"same regions of interest (ROIs) to plot results "
1304+
"together."
1305+
),
1306+
)
1307+
return
1308+
for i_roi in all_roi_indexes[0]:
1309+
roi_suffix = f"|ROI{int(i_roi+1)}" if i_roi >= 0 else ""
1310+
for title, results in grouped_results.items(): # title
1311+
x, y = [], []
1312+
for index, result in enumerate(results):
1313+
mask = result.array[:, 0] == i_roi
1314+
if param.xaxis == "indices":
1315+
x.append(index)
1316+
else:
1317+
i_xaxis = rdata.xlabels.index(param.xaxis)
1318+
x.append(float(result.shown_array[mask, i_xaxis]))
1319+
y.append(float(result.shown_array[mask, i_yaxis]))
1320+
self.__add_result_signal(
1321+
x, y, f"{title}{roi_suffix}", param.xaxis, param.yaxis
1322+
)
13001323
else:
1301-
# One curve per result title, per object and per ROI:
1324+
# One curve per result title, per object and per ROI
1325+
# ------------------------------------------------------------------
13021326
for title, results in grouped_results.items(): # title
13031327
for index, result in enumerate(results): # object
13041328
roi_idx = np.array(np.unique(result.array[:, 0]), dtype=int)
13051329
for i_roi in roi_idx: # ROI
1330+
roi_suffix = f"|ROI{int(i_roi+1)}" if i_roi >= 0 else ""
13061331
mask = result.array[:, 0] == i_roi
13071332
if param.xaxis == "indices":
13081333
x = np.arange(result.array.shape[0])[mask]
13091334
else:
13101335
i_xaxis = rdata.xlabels.index(param.xaxis)
13111336
x = result.shown_array[mask, i_xaxis]
13121337
y = result.shown_array[mask, i_yaxis]
1313-
stitle = f"{title} ({objs[index].short_id})"
1314-
if len(roi_idx) > 1:
1315-
stitle += f"|ROI{i_roi}"
1338+
stitle = f"{title} ({objs[index].short_id}){roi_suffix}"
13161339
self.__add_result_signal(
13171340
x, y, stitle, param.xaxis, param.yaxis
13181341
)

0 commit comments

Comments
 (0)