diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py index 5ef19a6..203002c 100644 --- a/src/imcflibs/imagej/bioformats.py +++ b/src/imcflibs/imagej/bioformats.py @@ -569,8 +569,7 @@ def get_stage_coords(filenames): if series_count > 1 and not str(image).endswith(".vsi"): series_names.append(ome_meta.getImageName(series)) else: - series_names.append(str(image)) - + series_names.append(os.path.basename(str(image))) current_position_x = getattr( ome_meta.getPlanePositionX(series, 0), "value", lambda: 0 )() diff --git a/src/imcflibs/imagej/resultstable.py b/src/imcflibs/imagej/resultstable.py index fbff104..c2c664a 100644 --- a/src/imcflibs/imagej/resultstable.py +++ b/src/imcflibs/imagej/resultstable.py @@ -21,24 +21,50 @@ def preset_results_column(results_table, column, value): results_table.show("Results") -def add_results_to_resultstable(results_table, column, values): - """Add values to the ResultsTable starting from row 0 of a given column. +def add_results_to_resultstable(results_table, column, values, rows=None): + """Add values to the ResultsTable in a specified column. + + This function can work in two ways: + 1. If rows=None: adds values sequentially starting from row 0. + 2. If rows is provided: adds values to specific row indices. Parameters ---------- results_table : ij.measure.ResultsTable - a reference of the IJ-ResultsTable - column : string - the column in which to add the values - values : list(int, double or float) - array with values to be added + A reference to the IJ-ResultsTable + column : str + The column in which to add the values. + values : list of int, float or str + Values to be added. + rows : list of int, optional + Specific row indices where values should be added. If None, values are + added sequentially starting from row 0. + + Examples + -------- + # Add the same value (42) to a given ResultsTable to specific rows (1, 3, 5) + add_results_to_resultstable(rt, "Intensity", 42, rows=[1, 3, 5]) """ - for index, value in enumerate(values): - results_table.setValue(column, index, value) + if not isinstance(values, list) and rows is not None: + values = [values] * len(rows) + + # Case 1: Add values sequentially from row 0 + if rows is None: + for index, value in enumerate(values): + results_table.setValue(column, index, value) + + # Case 2: Add values to specific rows + else: + if len(values) != len(rows): + raise ValueError(f"Length mismatch: values ({len(values)}) and rows ({len(rows)})") + + for i, row_index in enumerate(rows): + results_table.setValue(column, row_index, values[i]) results_table.show("Results") + def get_resultstable(): """Instantiate or get the ResultsTable instance.