Skip to content

Commit e50ee1e

Browse files
authored
Merge pull request #97 from rohangirishrao/devel
Fix `bioformats.get_stage_coords` and add option to `resultstable.add_results`
2 parents 1c5a5fb + 9cf3819 commit e50ee1e

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/imcflibs/imagej/bioformats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ def get_stage_coords(filenames):
574574
if series_count > 1 and not str(image).endswith(".vsi"):
575575
series_names.append(ome_meta.getImageName(series))
576576
else:
577-
series_names.append(str(image))
578-
577+
series_names.append(os.path.basename(str(image)))
579578
current_position_x = getattr(
580579
ome_meta.getPlanePositionX(series, 0), "value", lambda: 0
581580
)()

src/imcflibs/imagej/resultstable.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,51 @@ def preset_results_column(results_table, column, value):
2121
results_table.show("Results")
2222

2323

24-
def add_results_to_resultstable(results_table, column, values):
25-
"""Add values to the ResultsTable starting from row 0 of a given column.
24+
def add_results_to_resultstable(results_table, column, values, rows=None):
25+
"""Add values to the ResultsTable in a specified column.
26+
27+
This function works in two ways, depending on the value of `rows`:
28+
29+
1. If rows is `None`, it adds values sequentially starting from row 0.
30+
2. If rows is a list of int, it adds values to the given row indices.
2631
2732
Parameters
2833
----------
2934
results_table : ij.measure.ResultsTable
30-
a reference of the IJ-ResultsTable
31-
column : string
32-
the column in which to add the values
33-
values : list(int, double or float)
34-
array with values to be added
35+
A reference to the IJ-ResultsTable
36+
column : str
37+
The column in which to add the values.
38+
values : list of int, float or str
39+
Values to be added.
40+
rows : list of int, optional
41+
Specific row indices where values should be added. If None, values are
42+
added sequentially starting from row 0.
43+
44+
Examples
45+
--------
46+
To add the same value (42) to a given `ResultsTable` to rows 1, 3 and 5:
47+
>>> add_results_to_resultstable(rt, "Intensity", 42, rows=[1, 3, 5])
3548
"""
36-
for index, value in enumerate(values):
37-
results_table.setValue(column, index, value)
49+
if not isinstance(values, list) and rows is not None:
50+
values = [values] * len(rows)
51+
52+
# Case 1: Add values sequentially from row 0
53+
if rows is None:
54+
for index, value in enumerate(values):
55+
results_table.setValue(column, index, value)
56+
57+
# Case 2: Add values to specific rows
58+
else:
59+
if len(values) != len(rows):
60+
raise ValueError(f"Length mismatch: values ({len(values)}) and rows ({len(rows)})")
61+
62+
for i, row_index in enumerate(rows):
63+
results_table.setValue(column, row_index, values[i])
3864

3965
results_table.show("Results")
4066

4167

68+
4269
def get_resultstable():
4370
"""Instantiate or get the ResultsTable instance.
4471

0 commit comments

Comments
 (0)