Skip to content

Commit

Permalink
add pixi task to manage changes in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocerrone committed Oct 14, 2024
1 parent 615c783 commit 906ea79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/notebooks/processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 6 additions & 11 deletions src/ngio/tables/v1/roi_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit 906ea79

Please sign in to comment.