Skip to content

Commit

Permalink
fix minor issues for docs creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocerrone committed Oct 9, 2024
1 parent a11e12c commit 44d05fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
8 changes: 4 additions & 4 deletions docs/notebooks/basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"source": [
"print(\"List of Labels: \", ngff_image.label.list())\n",
"\n",
"label_nuclei = ngff_image.label.get(\"nuclei\", path=\"0\")\n",
"label_nuclei = ngff_image.label.get_label(\"nuclei\", path=\"0\")\n",
"print(f\"{label_nuclei.shape=}\")\n",
"print(f\"{label_nuclei.pixel_size=}\")"
]
Expand Down Expand Up @@ -131,7 +131,7 @@
"outputs": [],
"source": [
"# Loading a table\n",
"feature_table = ngff_image.table.get(\"regionprops_DAPI\")\n",
"feature_table = ngff_image.table.get_table(\"regionprops_DAPI\")\n",
"feature_table.table"
]
},
Expand All @@ -142,7 +142,7 @@
"outputs": [],
"source": [
"# Loading a roi table\n",
"roi_table = ngff_image.table.get(\"FOV_ROI_table\")\n",
"roi_table = ngff_image.table.get_table(\"FOV_ROI_table\")\n",
"\n",
"print(f\"{roi_table.list_field_indexes=}\")\n",
"print(f\"{roi_table.get_roi(\"FOV_1\")=}\")\n",
Expand Down Expand Up @@ -199,7 +199,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
31 changes: 14 additions & 17 deletions docs/notebooks/image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Get image as a zarr.Array\n",
"array = image.array\n",
"print(f\"{array}\")\n",
"\n",
"# Get image as a dask array\n",
"dask_array = image.on_disk_dask_array\n",
"dask_array"
]
Expand All @@ -82,7 +79,7 @@
"source": [
"Note, directly accessing the `.on_disk_array` or `.on_disk_dask_array` attributes will load the image as stored in the file.\n",
"\n",
"Since in principle the images can have different axes order. A safer way to access the image data is to use the `.array` method, which will return the image data in canonical order (TCZYX)."
"Since in principle the images can have different axes order. A safer way to access the image data is to use the `.get_array()` method, which will return the image data in canonical order (TCZYX)."
]
},
{
Expand All @@ -91,7 +88,7 @@
"metadata": {},
"outputs": [],
"source": [
"image_numpy = image.array(c=0, x=slice(0, 250), y=slice(0, 250), preserve_dimensions=False, mode=\"numpy\")\n",
"image_numpy = image.get_array(c=0, x=slice(0, 250), y=slice(0, 250), preserve_dimensions=False, mode=\"numpy\")\n",
"\n",
"print(f\"{image_numpy.shape=}\")"
]
Expand All @@ -111,11 +108,11 @@
"metadata": {},
"outputs": [],
"source": [
"roi_table = ngff_image.table.get(\"FOV_ROI_table\")\n",
"roi_table = ngff_image.table.get_table(\"FOV_ROI_table\")\n",
"roi = roi_table.get_roi(\"FOV_1\")\n",
"print(f\"{roi=}\")\n",
"\n",
"image_roi_1 = image.array_from_roi(roi=roi, c=0, preserve_dimensions=True, mode=\"dask\")\n",
"image_roi_1 = image.get_array_from_roi(roi=roi, c=0, preserve_dimensions=True, mode=\"dask\")\n",
"image_roi_1"
]
},
Expand All @@ -138,10 +135,10 @@
"print(f\"{image_2.pixel_size=}\")\n",
"\n",
"# Get roi for higher resolution image\n",
"image_1_roi_1 = image.array_from_roi(roi=roi, c=0, preserve_dimensions=False)\n",
"image_1_roi_1 = image.get_array_from_roi(roi=roi, c=0, preserve_dimensions=False)\n",
"\n",
"# Get roi for lower resolution image\n",
"image_2_roi_1 = image_2.array_from_roi(roi=roi, c=0, preserve_dimensions=False)\n",
"image_2_roi_1 = image_2.get_array_from_roi(roi=roi, c=0, preserve_dimensions=False)\n",
"\n",
"# Plot the two images side by side\n",
"fig, axs = plt.subplots(1, 2, figsize=(10, 5))\n",
Expand All @@ -168,15 +165,15 @@
"import numpy as np\n",
"\n",
"# Get a small slice of the image\n",
"small_slice = image.array(x=slice(1000, 2000), y=slice(1000, 2000))\n",
"small_slice = image.get_array(x=slice(1000, 2000), y=slice(1000, 2000))\n",
"\n",
"# Set the sample slice to zeros\n",
"zeros_slice = np.zeros_like(small_slice)\n",
"image.set_array(patch=zeros_slice, x=slice(1000, 2000), y=slice(1000, 2000))\n",
"\n",
"\n",
"# Load the image from disk and show the edited image\n",
"nuclei = ngff_image.label.get(\"nuclei\")\n",
"nuclei = ngff_image.label.get_label(\"nuclei\")\n",
"fig, axs = plt.subplots(1, 2, figsize=(10, 5))\n",
"axs[0].imshow(image.on_disk_array[0, 0], cmap=\"gray\")\n",
"axs[1].imshow(nuclei.on_disk_array[0])\n",
Expand Down Expand Up @@ -237,8 +234,8 @@
"metadata": {},
"outputs": [],
"source": [
"label_0 = ngff_image.label.get(\"new_label\", path=\"0\")\n",
"label_2 = ngff_image.label.get(\"new_label\", path=\"2\")\n",
"label_0 = ngff_image.label.get_label(\"new_label\", path=\"0\")\n",
"label_2 = ngff_image.label.get_label(\"new_label\", path=\"2\")\n",
"\n",
"label_before_consolidation = label_2.on_disk_array[...]\n",
"\n",
Expand Down Expand Up @@ -280,12 +277,12 @@
"print(f\"List of feature table: {ngff_image.table.list(type='feature_table')}\")\n",
"\n",
"\n",
"nuclei = ngff_image.label.get('nuclei')\n",
"nuclei = ngff_image.label.get_label('nuclei')\n",
"\n",
"# Create a table with random features for each nuclei in each ROI\n",
"list_of_records = []\n",
"for roi in roi_table.list_rois:\n",
" nuclei_in_roi = nuclei.array_from_roi(roi, mode='numpy')\n",
" nuclei_in_roi = nuclei.get_array_from_roi(roi, mode='numpy')\n",
" for nuclei_id in np.unique(nuclei_in_roi)[1:]:\n",
" list_of_records.append(\n",
" {\"label\": nuclei_id,\n",
Expand All @@ -298,7 +295,7 @@
"\n",
"# Create a new feature table\n",
"feat_table = ngff_image.table.new(name='new_feature_table',\n",
" region='../nuclei',\n",
" label_image='../nuclei',\n",
" table_type='feature_table',\n",
" overwrite=True)\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/notebooks/processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"print(\"MIP image loaded with shape:\", mip_image.shape)\n",
"\n",
"# Get a ROI table\n",
"roi_table = ngff_image.table.get(\"FOV_ROI_table\")\n",
"roi_table = ngff_image.table.get_table(\"FOV_ROI_table\")\n",
"print(\"ROI table loaded with\", len(roi_table.list_rois), \"ROIs\")\n",
"\n",
"# For each ROI in the table\n",
Expand All @@ -91,7 +91,7 @@
"# - set the data in the MIP image\n",
"for roi in roi_table.list_rois:\n",
" print(f\" - Processing ROI {roi.infos.get(\"field_index\")}\")\n",
" patch = source_image.array_from_roi(roi)\n",
" patch = source_image.get_array_from_roi(roi)\n",
" mip_patch = patch.max(axis=1, keepdims=True)\n",
" mip_image.set_array_from_roi(patch=mip_patch, roi=roi)\n",
" \n",
Expand Down Expand Up @@ -124,12 +124,12 @@
"# Get the MIP image at a lower resolution\n",
"mip_image_2 = mip_ngff.get_image(path=\"2\")\n",
"\n",
"image_before_consolidation = mip_image_2.array(c=0, z=0)\n",
"image_before_consolidation = mip_image_2.get_array(c=0, z=0)\n",
"\n",
"# Consolidate the pyramid\n",
"mip_image.consolidate()\n",
"\n",
"image_after_consolidation = mip_image_2.array(c=0, z=0)\n",
"image_after_consolidation = mip_image_2.get_array(c=0, z=0)\n",
"\n",
"fig, axs = plt.subplots(2, 1, figsize=(10, 5))\n",
"axs[0].set_title(\"Before consolidation\")\n",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test = ["zarr<3", "pytest", "pytest-cov"]
dev2 = [
"zarr<3",
"fractal-tasks-core==1.3.1",
"scikit-image",
"matplotlib",
"ipython",
"pytest",
Expand Down

0 comments on commit 44d05fc

Please sign in to comment.