Skip to content

Commit 52eee88

Browse files
committed
Refactor ROI title generation to use dedicated functions for consistency
1 parent 3a23c2b commit 52eee88

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

datalab/adapters_plotpy/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
TypeROI,
4848
TypeROIParam,
4949
TypeSingleROI,
50+
get_generic_roi_title,
5051
)
5152
from sigima.tools import coordinates
5253

@@ -502,7 +503,7 @@ def iterate_roi_items(
502503
item = configure_roi_item(
503504
roi_item, fmt, lbl, editable, option=self.roi.PREFIX
504505
)
505-
item.setTitle(single_roi.title or f"ROI{index:02d}")
506+
item.setTitle(single_roi.title or get_generic_roi_title(index))
506507
yield item
507508

508509

datalab/gui/panel/base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
TypeROI,
4848
create_signal,
4949
)
50-
from sigima.objects.base import ROI_KEY
50+
from sigima.objects.base import ROI_KEY, get_obj_roi_title
5151

5252
from datalab import objectmodel
5353
from datalab.adapters_plotpy.base import items_to_json
@@ -257,8 +257,10 @@ def create_resultdata_dict(
257257
for i_row_res in range(result.array.shape[0]):
258258
ylabel = f"{result.title}({get_short_id(obj)})"
259259
i_roi = int(result.array[i_row_res, 0])
260+
roititle = ""
260261
if i_roi >= 0:
261-
ylabel += f"|ROI{i_roi}"
262+
roititle = get_obj_roi_title(obj, i_roi)
263+
ylabel += f"|{roititle}"
262264
rdata.ylabels.append(ylabel)
263265
return rdatadict
264266

@@ -1593,8 +1595,9 @@ class PlotResultParam(gds.DataSet):
15931595
),
15941596
)
15951597
return
1598+
obj = objs[0]
15961599
for i_roi in all_roi_indexes[0]:
1597-
roi_suffix = f"|ROI{int(i_roi + 1)}" if i_roi >= 0 else ""
1600+
roi_suffix = ""
15981601
for title, results in grouped_results.items(): # title
15991602
x, y = [], []
16001603
for index, result in enumerate(results):
@@ -1605,6 +1608,8 @@ class PlotResultParam(gds.DataSet):
16051608
i_xaxis = rdata.xlabels.index(param.xaxis)
16061609
x.append(result.shown_array[mask, i_xaxis][0])
16071610
y.append(result.shown_array[mask, i_yaxis][0])
1611+
if i_roi >= 0:
1612+
roi_suffix = f"|{get_obj_roi_title(obj, i_roi)}"
16081613
self.__add_result_signal(
16091614
x, y, f"{title}{roi_suffix}", param.xaxis, param.yaxis
16101615
)
@@ -1613,17 +1618,20 @@ class PlotResultParam(gds.DataSet):
16131618
# ------------------------------------------------------------------
16141619
for title, results in grouped_results.items(): # title
16151620
for index, result in enumerate(results): # object
1621+
obj = objs[index]
16161622
roi_idx = np.array(np.unique(result.array[:, 0]), dtype=int)
16171623
for i_roi in roi_idx: # ROI
1618-
roi_suffix = f"|ROI{int(i_roi + 1)}" if i_roi >= 0 else ""
1624+
roi_suffix = ""
1625+
if i_roi >= 0:
1626+
roi_suffix = f"|{get_obj_roi_title(obj, i_roi)}"
16191627
mask = result.array[:, 0] == i_roi
16201628
if param.xaxis == "indices":
16211629
x = np.arange(result.array.shape[0])[mask]
16221630
else:
16231631
i_xaxis = rdata.xlabels.index(param.xaxis)
16241632
x = result.shown_array[mask, i_xaxis]
16251633
y = result.shown_array[mask, i_yaxis]
1626-
shid = get_short_id(objs[index])
1634+
shid = get_short_id(obj)
16271635
stitle = f"{title} ({shid}){roi_suffix}"
16281636
self.__add_result_signal(x, y, stitle, param.xaxis, param.yaxis)
16291637

datalab/gui/processor/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from qtpy import QtWidgets as QW
2626
from sigima.config import options as sigima_options
2727
from sigima.objects import ImageObj, SignalObj, TypeROI, TypeROIParam
28+
from sigima.objects.base import get_obj_roi_title
2829
from sigima.proc.decorator import is_computation_function
2930

3031
from datalab import env
@@ -695,16 +696,16 @@ def compute_1_to_0(
695696
obj.metadata[f"{result.title}Param"] = str(param)
696697

697698
results[get_uuid(obj)] = result
698-
xlabels = result.headers
699699
if obj is current_obj:
700700
self.panel.selection_changed(update_items=True)
701701
else:
702702
self.panel.refresh_plot(get_uuid(obj), True, False)
703+
xlabels = result.headers
703704
for i_row_res in range(result.array.shape[0]):
704705
ylabel = f"{result.title}({get_short_id(obj)})"
705706
i_roi = int(result.array[i_row_res, 0])
706707
if i_roi >= 0:
707-
ylabel += f"|ROI{i_roi}"
708+
ylabel += f"|{get_obj_roi_title(obj, i_roi)}"
708709
ylabels.append(ylabel)
709710
if results:
710711
with warnings.catch_warnings():

datalab/gui/roieditor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
TypeObj,
5757
TypeROI,
5858
)
59+
from sigima.objects.base import get_generic_roi_title
5960

6061
from datalab.adapters_plotpy import (
6162
TypePlotItem,
@@ -87,7 +88,9 @@ def tool_deselect_items(tool: InteractiveTool) -> None:
8788

8889

8990
def tool_setup_shape(
90-
plot: BasePlot, shape: TypeROIItem, obj: SignalObj | ImageObj
91+
plot: BasePlot,
92+
shape: TypeROIItem,
93+
obj: SignalObj | ImageObj,
9194
) -> None:
9295
"""Tool setup shape"""
9396
configure_roi_item_in_tool(shape, obj)
@@ -97,7 +100,7 @@ def tool_setup_shape(
97100
match = re.match(r"ROI(\d+)", name)
98101
if match is not None:
99102
max_index = max(max_index, int(match.group(1)))
100-
shape.setTitle(f"ROI{max_index + 1:02d}")
103+
shape.setTitle(get_generic_roi_title(max_index + 1))
101104

102105

103106
class ROISegmentTool(HRangeTool):

0 commit comments

Comments
 (0)