From 44d05fc0dedbcc6b9496a907557d44cea576eefc Mon Sep 17 00:00:00 2001 From: lorenzo Date: Wed, 9 Oct 2024 15:24:32 +0200 Subject: [PATCH] fix minor issues for docs creation --- docs/notebooks/basic_usage.ipynb | 8 ++++---- docs/notebooks/image.ipynb | 31 ++++++++++++++----------------- docs/notebooks/processing.ipynb | 8 ++++---- pyproject.toml | 1 + 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docs/notebooks/basic_usage.ipynb b/docs/notebooks/basic_usage.ipynb index 651a5c6..45afc49 100644 --- a/docs/notebooks/basic_usage.ipynb +++ b/docs/notebooks/basic_usage.ipynb @@ -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=}\")" ] @@ -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" ] }, @@ -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", @@ -199,7 +199,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.6" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/docs/notebooks/image.ipynb b/docs/notebooks/image.ipynb index 6ff48bf..618034b 100644 --- a/docs/notebooks/image.ipynb +++ b/docs/notebooks/image.ipynb @@ -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" ] @@ -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)." ] }, { @@ -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=}\")" ] @@ -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" ] }, @@ -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", @@ -168,7 +165,7 @@ "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", @@ -176,7 +173,7 @@ "\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", @@ -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", @@ -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", @@ -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", diff --git a/docs/notebooks/processing.ipynb b/docs/notebooks/processing.ipynb index 831a487..da1c57d 100644 --- a/docs/notebooks/processing.ipynb +++ b/docs/notebooks/processing.ipynb @@ -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", @@ -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", @@ -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", diff --git a/pyproject.toml b/pyproject.toml index bad0aff..b66392f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ test = ["zarr<3", "pytest", "pytest-cov"] dev2 = [ "zarr<3", "fractal-tasks-core==1.3.1", + "scikit-image", "matplotlib", "ipython", "pytest",