{ "cells": [ { "cell_type": "markdown", "id": "b539ec69-af48-4780-9ab4-0dddc6755e33", "metadata": {}, "source": [ "# Subselecting Data" ] }, { "cell_type": "code", "execution_count": 1, "id": "010937e5-9ecd-41f7-8be3-0e489a3bf786", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import spatialproteomics\n", "import pandas as pd\n", "import xarray as xr\n", "\n", "xr.set_options(display_style=\"text\")" ] }, { "cell_type": "markdown", "id": "d0c0428c-6879-4cbd-8e19-1fa3039d16f6", "metadata": {}, "source": [ "One of the key features of `spatialproteomics` is the ability to slice our image data quickly and intuitively. We start by loading our _spatialproteomics_ object." ] }, { "cell_type": "code", "execution_count": 2, "id": "b563d01d-8498-4749-b532-9ca2a6e309c4", "metadata": { "tags": [] }, "outputs": [], "source": [ "ds = xr.open_zarr(\"../../data/BNHL_166_4_I2_LK_2.zarr\")" ] }, { "cell_type": "markdown", "id": "f4f44d5b-255d-47e6-b275-c0f36d20039b", "metadata": {}, "source": [ "## Slicing Channels and Spatial Coordinates\n", "\n", "To slice specific channels of the image we simply use `.pp` accessor together with the familiar bracket `[]` indexing." ] }, { "cell_type": "code", "execution_count": 3, "id": "e7ee6482-5fb0-4862-82dd-b30a2fb10b35", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 1, y: 3000, x: 3000, labels: 8, la_props: 2,\n",
       "                     cells: 12560, features: 3)\n",
       "Coordinates:\n",
       "  * cells           (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n",
       "  * channels        (channels) <U11 'CD4'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 1 2 3 4 5 6 7 8\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(1, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(8, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(6280, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 1, y: 3000, x: 3000, labels: 8, la_props: 2,\n", " cells: 12560, features: 3)\n", "Coordinates:\n", " * cells (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.pp[\"CD4\"]" ] }, { "cell_type": "markdown", "id": "8cc22e9c-e281-470e-ac62-c88593a93218", "metadata": {}, "source": [ "We can also select multiple channels by simply passing a list to the `.pp` accessor. As we will see later, this makes visualising image overlays easy." ] }, { "cell_type": "code", "execution_count": 4, "id": "b6419f5b-44ad-4bca-a98d-7e3e3d46c564", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 2, y: 3000, x: 3000, labels: 8, la_props: 2,\n",
       "                     cells: 12560, features: 3)\n",
       "Coordinates:\n",
       "  * cells           (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n",
       "  * channels        (channels) <U11 'CD4' 'CD8'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 1 2 3 4 5 6 7 8\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(2, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(8, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(6280, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 2, y: 3000, x: 3000, labels: 8, la_props: 2,\n", " cells: 12560, features: 3)\n", "Coordinates:\n", " * cells (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.pp[[\"CD4\", \"CD8\"]]" ] }, { "cell_type": "markdown", "id": "c4887ea9-5b2a-4ddf-b1f3-ea2a3a99949b", "metadata": {}, "source": [ "The `.pp` accessor also understands `x` and `y` coordinates. When `x` and `y` coordinates are sliced, we get ridd of all cells that do not belong to the respective image slice." ] }, { "cell_type": "code", "execution_count": 5, "id": "a76c4712-66aa-41d0-92a6-c9b7a7cd1235", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 56, y: 101, x: 101, labels: 8, la_props: 2,\n",
       "                     cells: 0, features: 3)\n",
       "Coordinates:\n",
       "  * cells           (cells) int64 \n",
       "  * channels        (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 1 2 3 4 5 6 7 8\n",
       "  * x               (x) int64 50 51 52 53 54 55 56 ... 145 146 147 148 149 150\n",
       "  * y               (y) int64 50 51 52 53 54 55 56 ... 145 146 147 148 149 150\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(7, 101, 101), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(8, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(0, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 56, y: 101, x: 101, labels: 8, la_props: 2,\n", " cells: 0, features: 3)\n", "Coordinates:\n", " * cells (cells) int64 \n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.pp[50:150, 50:150]" ] }, { "cell_type": "markdown", "id": "dd95a3a9-1089-4680-9eb4-056e64637adb", "metadata": {}, "source": [ "Note that we can also pass `channels` and `x, y` coordinates at the same time." ] }, { "cell_type": "code", "execution_count": 6, "id": "635678d6-1c07-4f25-b27f-704fbc67c363", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 2, y: 101, x: 101, labels: 8, la_props: 2,\n",
       "                     cells: 0, features: 3)\n",
       "Coordinates:\n",
       "  * cells           (cells) int64 \n",
       "  * channels        (channels) <U11 'CD4' 'CD8'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 1 2 3 4 5 6 7 8\n",
       "  * x               (x) int64 50 51 52 53 54 55 56 ... 145 146 147 148 149 150\n",
       "  * y               (y) int64 50 51 52 53 54 55 56 ... 145 146 147 148 149 150\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(2, 101, 101), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(8, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(0, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 2, y: 101, x: 101, labels: 8, la_props: 2,\n", " cells: 0, features: 3)\n", "Coordinates:\n", " * cells (cells) int64 \n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.pp[[\"CD4\", \"CD8\"], 50:150, 50:150]" ] }, { "cell_type": "markdown", "id": "a795cf6b-e946-4471-8baa-765a0728ce44", "metadata": {}, "source": [ "## Slicing Labels\n", "\n", "The labels accessor `.la` allows to select specific cell types by their label number or name." ] }, { "cell_type": "code", "execution_count": 7, "id": "11388747-b1b0-4606-b761-24661b56609b", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 56, y: 3000, x: 3000, labels: 1, la_props: 2,\n",
       "                     cells: 1073, features: 3)\n",
       "Coordinates:\n",
       "  * channels        (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 4\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * cells           (cells) int64 3 11 49 71 80 ... 12504 12516 12554 12558\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(7, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(1, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(1073, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 56, y: 3000, x: 3000, labels: 1, la_props: 2,\n", " cells: 1073, features: 3)\n", "Coordinates:\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.la[4]" ] }, { "cell_type": "code", "execution_count": 8, "id": "76a4352d-3ddd-4c95-8dd0-ee97f2827e58", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 56, y: 3000, x: 3000, labels: 1, la_props: 2,\n",
       "                     cells: 5891, features: 3)\n",
       "Coordinates:\n",
       "  * channels        (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 7\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * cells           (cells) int64 1 4 8 10 12 ... 12444 12469 12473 12505 12522\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(7, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(1, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(5891, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 56, y: 3000, x: 3000, labels: 1, la_props: 2,\n", " cells: 5891, features: 3)\n", "Coordinates:\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.la[\"T (CD3)\"]" ] }, { "cell_type": "markdown", "id": "c46a7e69-1ed1-47b3-b7f1-9fdbe21aed19", "metadata": {}, "source": [ "Again it is possible to pass multiple cell labels." ] }, { "cell_type": "code", "execution_count": 9, "id": "97c4dd3a-cb35-4cb4-a797-2464904cc908", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 56, y: 3000, x: 3000, labels: 3, la_props: 2,\n",
       "                     cells: 3571, features: 3)\n",
       "Coordinates:\n",
       "  * channels        (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 4 5 6\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * cells           (cells) int64 2 3 5 6 9 11 ... 12539 12554 12555 12557 12558\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(7, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(3, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(3571, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 56, y: 3000, x: 3000, labels: 3, la_props: 2,\n", " cells: 3571, features: 3)\n", "Coordinates:\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.la[4, 5, 6]" ] }, { "cell_type": "markdown", "id": "488b5269-d68c-4591-acdf-f2bea2ebb4b8", "metadata": {}, "source": [ "Finally, we can select all cells except a cell type using `la.deselect`." ] }, { "cell_type": "code", "execution_count": 10, "id": "9915a6f9-6c17-48ae-9f76-0a78b41115fc", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:         (channels: 56, y: 3000, x: 3000, labels: 7, la_props: 2,\n",
       "                     cells: 10488, features: 3)\n",
       "Coordinates:\n",
       "  * channels        (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features        (features) <U10 '_labels' 'centroid-0' 'centroid-1'\n",
       "  * la_props        (la_props) <U6 '_color' '_name'\n",
       "  * labels          (labels) int64 2 3 4 5 6 7 8\n",
       "  * x               (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y               (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * cells           (cells) int64 1 2 3 4 5 6 ... 10484 10485 10486 10487 10488\n",
       "Data variables:\n",
       "    _image          (channels, y, x) uint8 dask.array<chunksize=(7, 375, 750), meta=np.ndarray>\n",
       "    _la_properties  (labels, la_props) <U20 dask.array<chunksize=(7, 2), meta=np.ndarray>\n",
       "    _obs            (cells, features) float64 dask.array<chunksize=(6280, 3), meta=np.ndarray>\n",
       "    _segmentation   (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (channels: 56, y: 3000, x: 3000, labels: 7, la_props: 2,\n", " cells: 10488, features: 3)\n", "Coordinates:\n", " * channels (channels) \n", " _la_properties (labels, la_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.la.deselect([1])" ] }, { "cell_type": "markdown", "id": "d04540a4-0d90-4c3b-b5ee-e0b38e76a35b", "metadata": { "tags": [] }, "source": [ "## Slicing Neighborhoods\n", "We can also select by neighborhoods with the `nh` accessor. The syntax is identical to the one in the label subsetting." ] }, { "cell_type": "code", "execution_count": 11, "id": "75698711-eb02-4eed-bee3-ac80edc40872", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:                (cells: 6901, celltype_levels: 3, channels: 56,\n",
       "                            y: 2000, x: 2000, labels: 9, la_props: 2,\n",
       "                            neighborhoods: 4, nh_props: 2, features: 18)\n",
       "Coordinates:\n",
       "  * cells                  (cells) int64 1 2 3 4 5 ... 6897 6898 6899 6900 6901\n",
       "  * celltype_levels        (celltype_levels) <U8 'labels' 'labels_1' 'labels_2'\n",
       "  * channels               (channels) <U11 'DAPI' 'TIM3' ... 'ki-67' 'CD38'\n",
       "  * features               (features) <U14 'BCL-2' 'BCL-6' ... 'ki-67'\n",
       "  * la_props               (la_props) <U6 '_color' '_name'\n",
       "  * labels                 (labels) int64 1 2 3 4 5 6 7 8 9\n",
       "  * neighborhoods          (neighborhoods) int64 0 1 3 4\n",
       "  * nh_props               (nh_props) <U6 '_color' '_name'\n",
       "  * x                      (x) int64 0 1 2 3 4 5 ... 1995 1996 1997 1998 1999\n",
       "  * y                      (y) int64 0 1 2 3 4 5 ... 1995 1996 1997 1998 1999\n",
       "Data variables:\n",
       "    _celltype_predictions  (cells, celltype_levels) <U11 dask.array<chunksize=(3451, 2), meta=np.ndarray>\n",
       "    _image                 (channels, y, x) uint8 dask.array<chunksize=(7, 500, 500), meta=np.ndarray>\n",
       "    _la_properties         (labels, la_props) <U11 dask.array<chunksize=(9, 2), meta=np.ndarray>\n",
       "    _nh_properties         (neighborhoods, nh_props) <U14 dask.array<chunksize=(4, 2), meta=np.ndarray>\n",
       "    _obs                   (cells, features) float64 dask.array<chunksize=(3451, 9), meta=np.ndarray>\n",
       "    _segmentation          (y, x) int64 dask.array<chunksize=(250, 500), meta=np.ndarray>
" ], "text/plain": [ "\n", "Dimensions: (cells: 6901, celltype_levels: 3, channels: 56,\n", " y: 2000, x: 2000, labels: 9, la_props: 2,\n", " neighborhoods: 4, nh_props: 2, features: 18)\n", "Coordinates:\n", " * cells (cells) int64 1 2 3 4 5 ... 6897 6898 6899 6900 6901\n", " * celltype_levels (celltype_levels) \n", " _image (channels, y, x) uint8 dask.array\n", " _la_properties (labels, la_props) \n", " _nh_properties (neighborhoods, nh_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 dask.array" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds = xr.open_zarr(\"../../data/sample_1_with_neighborhoods.zarr\")\n", "ds" ] }, { "cell_type": "code", "execution_count": 12, "id": "c5aa621d-4309-443f-8c65-7f3b25e73731", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
       "Dimensions:                (cells: 709, celltype_levels: 3, channels: 56,\n",
       "                            y: 2000, x: 2000, labels: 9, la_props: 2,\n",
       "                            neighborhoods: 1, nh_props: 2, features: 18)\n",
       "Coordinates:\n",
       "  * celltype_levels        (celltype_levels) <U8 'labels' 'labels_1' 'labels_2'\n",
       "  * channels               (channels) <U11 'DAPI' 'TIM3' ... 'ki-67' 'CD38'\n",
       "  * features               (features) <U14 'BCL-2' 'BCL-6' ... 'ki-67'\n",
       "  * la_props               (la_props) <U6 '_color' '_name'\n",
       "  * labels                 (labels) int64 1 2 3 4 5 6 7 8 9\n",
       "  * neighborhoods          (neighborhoods) int64 0\n",
       "  * nh_props               (nh_props) <U6 '_color' '_name'\n",
       "  * x                      (x) int64 0 1 2 3 4 5 ... 1995 1996 1997 1998 1999\n",
       "  * y                      (y) int64 0 1 2 3 4 5 ... 1995 1996 1997 1998 1999\n",
       "  * cells                  (cells) int64 1571 1858 1895 1912 ... 6204 6247 6293\n",
       "Data variables:\n",
       "    _celltype_predictions  (cells, celltype_levels) <U11 dask.array<chunksize=(709, 2), meta=np.ndarray>\n",
       "    _image                 (channels, y, x) uint8 dask.array<chunksize=(7, 500, 500), meta=np.ndarray>\n",
       "    _la_properties         (labels, la_props) <U11 dask.array<chunksize=(9, 2), meta=np.ndarray>\n",
       "    _nh_properties         (neighborhoods, nh_props) <U14 dask.array<chunksize=(1, 2), meta=np.ndarray>\n",
       "    _obs                   (cells, features) float64 dask.array<chunksize=(709, 9), meta=np.ndarray>\n",
       "    _segmentation          (y, x) int64 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0
" ], "text/plain": [ "\n", "Dimensions: (cells: 709, celltype_levels: 3, channels: 56,\n", " y: 2000, x: 2000, labels: 9, la_props: 2,\n", " neighborhoods: 1, nh_props: 2, features: 18)\n", "Coordinates:\n", " * celltype_levels (celltype_levels) \n", " _image (channels, y, x) uint8 dask.array\n", " _la_properties (labels, la_props) \n", " _nh_properties (neighborhoods, nh_props) \n", " _obs (cells, features) float64 dask.array\n", " _segmentation (y, x) int64 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# subsetting only neighborhood 0\n", "ds.nh[0]" ] } ], "metadata": { "kernelspec": { "display_name": "tmp_env_2", "language": "python", "name": "tmp_env_2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 5 }