From 906ea792c9b6545908d35be393f467c8d81d4c7f Mon Sep 17 00:00:00 2001 From: lorenzo Date: Mon, 14 Oct 2024 15:21:08 +0200 Subject: [PATCH] add pixi task to manage changes in notebooks --- docs/notebooks/processing.ipynb | 2 +- pyproject.toml | 3 +++ src/ngio/tables/v1/roi_tables.py | 17 ++++++----------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/notebooks/processing.ipynb b/docs/notebooks/processing.ipynb index 28c9898..0e4c67e 100644 --- a/docs/notebooks/processing.ipynb +++ b/docs/notebooks/processing.ipynb @@ -166,7 +166,7 @@ " roi.z_length = 1 # In the MIP image, the z dimension is 1\n", " roi_list.append(roi)\n", "\n", - "mip_roi_table.append_rois(roi_list)\n", + "mip_roi_table.set_rois(roi_list, overwrite=True)\n", "mip_roi_table.write()\n", "\n", "mip_roi_table.table" diff --git a/pyproject.toml b/pyproject.toml index 6e59377..a2b428c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -214,3 +214,6 @@ dev3 = { features = ["dev3"], solve-group = "v3" } test = { features = ["test"], solve-group = "v2_test" } docs = { features = ["dev2", "docs"], solve-group = "v2" } +[tool.pixi.tasks] +run_nb = "jupyter-execute ./docs/notebooks/*.ipynb" +run_docs = "mkdocs serve" diff --git a/src/ngio/tables/v1/roi_tables.py b/src/ngio/tables/v1/roi_tables.py index 65d199f..996d120 100644 --- a/src/ngio/tables/v1/roi_tables.py +++ b/src/ngio/tables/v1/roi_tables.py @@ -170,15 +170,15 @@ def field_indexes(self) -> list[str]: def set_rois( self, rois: Iterable[WorldCooROI] | WorldCooROI, - mode: Literal["override", "append"] = "append", + overwrite: bool = False, ) -> None: """Append ROIs to the current table. Args: rois (Iterable[WorldCooROI] | WorldCooROI): The ROIs to append. - mode (str): The mode to use when appending the ROIs. - override: Override the current table with the new ROIs. - append: Append the new ROIs to the current table. + overwrite (bool): Whether to overwrite the ROIs if they already exist. + If False, the ROIs will be appended. If True, the ROIs will be + overwritten. """ if isinstance(rois, WorldCooROI): rois = [rois] @@ -205,15 +205,10 @@ def set_rois( table_df = self.table new_table_df = pd.DataFrame.from_dict(rois_dict, orient="index") - if mode == "override" or table_df.empty: + if overwrite or table_df.empty: table_df = new_table_df - elif mode == "append": - table_df = pd.concat([table_df, new_table_df], axis=0) else: - raise ValueError( - f"Invalid mode: {mode} for setting the ROIs. " - "Use 'override' or 'append'." - ) + table_df = pd.concat([table_df, new_table_df], axis=0) table_df.index.name = "FieldIndex" table_df.index = table_df.index.astype(str)