{ "cells": [ { "cell_type": "markdown", "id": "aefafe4b-7cd8-4f38-95dc-007ab198b52c", "metadata": {}, "source": [ "# dev with dask" ] }, { "cell_type": "code", "execution_count": null, "id": "120e548c-40f1-44bb-918b-004c5a01f640", "metadata": {}, "outputs": [], "source": [ "from collections import defaultdict\n", "\n", "import dask.array as da\n", "import holoviews as hv\n", "import hvplot\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import skimage\n", "import tifffile as tff\n", "from scipy import ndimage\n", "\n", "from nima import nima, utils\n", "\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "fp = \"../../tests/data/1b_c16_15.tif\"" ] }, { "cell_type": "code", "execution_count": null, "id": "ba83f3bd-2739-48ad-a19b-2dd31b8d1ce3", "metadata": {}, "outputs": [], "source": [ "daimg = da.from_zarr(tff.imread(fp, aszarr=True))\n", "daimg" ] }, { "cell_type": "code", "execution_count": null, "id": "0cf8001d-0d50-4345-8703-ae0b43b076b4", "metadata": {}, "outputs": [], "source": [ "utils.bg(daimg[0, 0].compute())" ] }, { "cell_type": "code", "execution_count": null, "id": "4fbf586e-91ea-4a4a-8dfc-c7feb2323e6c", "metadata": {}, "outputs": [], "source": [ "def dabg(daimg):\n", " r = defaultdict(list)\n", " n_t, n_c = daimg.shape[:2]\n", " for t in range(n_t):\n", " for c in range(n_c):\n", " r[c].append(utils.bg(daimg[t, c].compute())[0])\n", " return pd.DataFrame(r)\n", "\n", "\n", "dabg(daimg)" ] }, { "cell_type": "code", "execution_count": null, "id": "901a3ed6-7e3b-40b8-86ea-f3b61762aef7", "metadata": {}, "outputs": [], "source": [ "def dabg_fg(daimg, erf_pvalue=1e-100, size=10):\n", " n_t, n_c = daimg.shape[:2]\n", " bgs = defaultdict(list)\n", " fgs = defaultdict(list)\n", " for t in range(n_t):\n", " p = np.ones(daimg.shape[-2:])\n", " multichannel = daimg[t].compute()\n", " for c in range(n_c):\n", " av, sd = utils.bg(multichannel[c])\n", " p = p * utils.prob(multichannel[c], av, sd)\n", " bgs[c].append(av)\n", " mask = ndimage.median_filter((p) ** (1 / n_c), size=size) < erf_pvalue\n", " for c in range(n_c):\n", " fgs[c].append(np.ma.mean(np.ma.masked_array(multichannel[c], mask=~mask)))\n", " return pd.DataFrame(bgs), pd.DataFrame(fgs)\n", "\n", "\n", "dfb, dff = dabg_fg(daimg)" ] }, { "cell_type": "code", "execution_count": null, "id": "a67d7fb9-c6ae-4722-bc8b-06c0469f37be", "metadata": {}, "outputs": [], "source": [ "plt.subplot(121)\n", "((dff - dfb)[0] / (dff - dfb)[2]).plot(marker=\"s\")\n", "plt.grid()\n", "plt.subplot(122)\n", "((dff - dfb)[2] / (dff - dfb)[1]).plot(marker=\"o\")\n", "plt.grid()" ] }, { "cell_type": "markdown", "id": "6995aaca-2982-40be-9945-b2574ff2121b", "metadata": {}, "source": [ "NEXT:\n", "- make utils.bg and utils.prob work with dask arrays" ] }, { "cell_type": "code", "execution_count": null, "id": "b0fe2baa-e299-4083-9182-7cd22379517b", "metadata": {}, "outputs": [], "source": [ "def dmask(daim, erf_pvalue=1e-100, size=10):\n", " n_c = daim.shape[0]\n", " im = daim[0].compute()\n", " p = utils.prob(im, *utils.bg(im))\n", " for c in range(1, n_c):\n", " im = daim[c].compute()\n", " p = p * utils.prob(im, *utils.bg(im))\n", " p = ndimage.median_filter((p) ** (1 / n_c), size=size)\n", " mask = p < erf_pvalue\n", " return skimage.morphology.remove_small_objects(mask)\n", " # mask = skimage.morphology.remove_small_holes(mask)\n", " # return np.ma.masked_array(plane, mask=~mask), np.ma.masked_array(plane, mask=mask)\n", "\n", "\n", "mask = dmask(daimg[2])\n", "\n", "lab, nlab = ndimage.label(mask)\n", "lab, nlab" ] }, { "cell_type": "code", "execution_count": null, "id": "028f85b4-dce4-4a7e-8bcd-90f878eb25b2", "metadata": {}, "outputs": [], "source": [ "pr = skimage.measure.regionprops(lab, intensity_image=daimg[0][0])\n", "pr[1].equivalent_diameter" ] }, { "cell_type": "code", "execution_count": null, "id": "0f5c915c-7ee1-49af-8d04-d54966e0e5c6", "metadata": {}, "outputs": [], "source": [ "max_diameter = pr[0].equivalent_diameter\n", "size = int(max_diameter * 0.3)\n", "size" ] }, { "cell_type": "code", "execution_count": null, "id": "744f72c6-fa7a-4846-a815-36f988e2ccda", "metadata": {}, "outputs": [], "source": [ "t = 0\n", "mask = dmask(daimg[t])\n", "# skimage.io.imshow(mask)\n", "lab, nlab = ndimage.label(mask)\n", "\n", "distance = ndimage.distance_transform_edt(mask)\n", "# distance = skimage.filters.gaussian(distance, sigma=0) min_distance=size,\n", "coords = skimage.feature.peak_local_max(\n", " distance, footprint=np.ones((size, size)), labels=lab\n", ")\n", "mm = np.zeros(distance.shape, dtype=bool)\n", "mm[tuple(coords.T)] = True\n", "# markers, _ = ndimage.label(mm)\n", "markers = skimage.measure.label(mm)\n", "\n", "labels = skimage.segmentation.watershed(-distance, markers, mask=mask)\n", "\n", "_, (ax0, ax1, ax2) = plt.subplots(1, 3)\n", "ax0.imshow(distance)\n", "ax1.imshow(labels)\n", "ax2.imshow(labels == 3)\n", "coords" ] }, { "cell_type": "code", "execution_count": null, "id": "4854b994-c574-4949-9ef3-4faa3926454b", "metadata": {}, "outputs": [], "source": [ "masks = [dmask(daimg[t]) for t in range(4)]" ] }, { "cell_type": "code", "execution_count": null, "id": "91dc643e-274c-4650-ba2f-1361f64ada27", "metadata": {}, "outputs": [], "source": [ "masks = np.stack(masks)\n", "masks.shape" ] }, { "cell_type": "code", "execution_count": null, "id": "42f4e175-7640-470a-916f-6ffafd068f22", "metadata": {}, "outputs": [], "source": [ "tff.imshow(masks)" ] }, { "cell_type": "code", "execution_count": null, "id": "46f527ea-fa57-4485-bef8-4815a629a621", "metadata": {}, "outputs": [], "source": [ "distance = ndimage.distance_transform_edt(masks)\n", "\n", "distance = skimage.filters.gaussian(distance, sigma=5)" ] }, { "cell_type": "code", "execution_count": null, "id": "58e38b04-c874-4a1a-8869-46a7e00cb8a4", "metadata": {}, "outputs": [], "source": [ "import impy\n", "\n", "impy.array(distance).imshow()" ] }, { "cell_type": "code", "execution_count": null, "id": "283b801c-6a46-41f1-ac45-a9ecbe856c7a", "metadata": {}, "outputs": [], "source": [ "for t in range(4):\n", " coords = skimage.feature.peak_local_max(distance[t], footprint=np.ones((130, 130)))\n", " print(coords)" ] }, { "cell_type": "code", "execution_count": null, "id": "4e767287-b4f2-4864-b39b-543d2130956e", "metadata": {}, "outputs": [], "source": [ "co = np.stack([coords, coords, coords, coords])" ] }, { "cell_type": "code", "execution_count": null, "id": "2fc44f0b-8a9a-48c8-9cb4-e88aba0aebf0", "metadata": {}, "outputs": [], "source": [ "coords.T" ] }, { "cell_type": "code", "execution_count": null, "id": "9b1f6b35-963e-4a02-a2ec-abb0b03671f3", "metadata": {}, "outputs": [], "source": [ "mm = np.zeros(masks[0].shape, dtype=bool)\n", "mm[tuple(co.T)] = True\n", "# markers, _ = ndimage.label(mm)\n", "markers = skimage.measure.label(np.stack([mm, mm, mm, mm]))\n", "\n", "labels = skimage.segmentation.watershed(-distance, markers, mask=masks)\n", "\n", "_, (ax1, ax2) = plt.subplots(1, 2)\n", "ax1.imshow(labels[3])\n", "ax2.imshow(labels[3] == 4)" ] }, { "cell_type": "code", "execution_count": null, "id": "4721f4c2-da1e-44db-a6c4-a20c32965df3", "metadata": {}, "outputs": [], "source": [ "img = tff.imread(fp)" ] }, { "cell_type": "code", "execution_count": null, "id": "57401060-9244-49eb-b19a-31986e814935", "metadata": {}, "outputs": [], "source": [ "dim, _, _ = nima.read_tiff(fp, channels=[\"R\", \"G\", \"C\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "c17ba10f-628f-4196-a3d9-4f44004d8047", "metadata": {}, "outputs": [], "source": [ "res = nima.d_bg(dim)\n", "bgs = res[1]" ] }, { "cell_type": "code", "execution_count": null, "id": "4e0f5786-c515-4f6f-9246-af7befe0b84d", "metadata": {}, "outputs": [], "source": [ "def ratio(t, roi):\n", " g = img[t, 0][labels[t] == roi].mean() - bgs[\"G\"][t]\n", " r = img[t, 1][labels[t] == roi].mean() - bgs[\"R\"][t]\n", " c = img[t, 2][labels[t] == roi].mean() - bgs[\"C\"][t]\n", " return g / c, c / r\n", "\n", "\n", "ratio(1, 4)" ] }, { "cell_type": "code", "execution_count": null, "id": "0f9a393f-c754-4b99-b705-7a58f0f9905d", "metadata": {}, "outputs": [], "source": [ "rph = defaultdict(list)\n", "rcl = defaultdict(list)\n", "for roi in range(1, 5):\n", " for t in range(4):\n", " ph, cl = ratio(t, roi)\n", " rph[roi].append(ph)\n", " rcl[roi].append(cl)\n", "\n", "plt.plot(rph[1])\n", "plt.plot(rph[2])\n", "plt.plot(rph[3])\n", "plt.plot(rph[4])" ] }, { "cell_type": "code", "execution_count": null, "id": "21b02a3b-bdb9-4761-b95c-ecd21f9f96e0", "metadata": {}, "outputs": [], "source": [ "plt.plot(rcl[1])\n", "plt.plot(rcl[2])\n", "plt.plot(rcl[3])\n", "plt.plot(rcl[4])" ] }, { "cell_type": "code", "execution_count": null, "id": "631038fd-c0f2-4826-b266-38f849045415", "metadata": {}, "outputs": [], "source": [ "t = 2\n", "mask = dmask(daimg[t])\n", "# skimage.io.imshow(mask)\n", "lab, nlab = ndimage.label(mask)\n", "lab[~mask] = -1\n", "# lab[lab==1] = -1\n", "labels_ws = skimage.segmentation.random_walker(\n", " daimg[t, 1].compute(), lab, beta=1e10, mode=\"bf\"\n", ")\n", "# labels_ws = skimage.segmentation.random_walker(-distance, lab, beta=10000, mode=\"bf\")\n", "\n", "_, (ax1, ax2) = plt.subplots(1, 2)\n", "ax1.imshow(labels_ws)\n", "ax2.imshow(labels_ws == 2)" ] }, { "cell_type": "code", "execution_count": null, "id": "48bb4cd4-4702-4db7-b604-b6281300c2c7", "metadata": {}, "outputs": [], "source": [ "imar = impy.imread(fp)\n", "\n", "imar.label_threshold()" ] }, { "cell_type": "code", "execution_count": null, "id": "ed4b1864-c068-4dbf-b547-7e86f14ede74", "metadata": {}, "outputs": [], "source": [ "imar[:, 2].imshow(label=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "9c96fcb6-2ab4-466a-b5c8-c7cc06136c6f", "metadata": {}, "outputs": [], "source": [ "def dmask0(im, erf_pvalue=1e-100, size=10):\n", " p = utils.prob(im[0], *utils.bg(im[0]))\n", " for img in im[1:]:\n", " p = p * utils.prob(img, *utils.bg(img))\n", " p = ndimage.median_filter((p) ** (1 / len(im)), size=size)\n", " mask = p < erf_pvalue\n", " return skimage.morphology.remove_small_objects(mask)" ] }, { "cell_type": "code", "execution_count": null, "id": "887d8bfa-958c-4a7c-a019-ae3e621b9dd7", "metadata": {}, "outputs": [], "source": [ "dmask0(imar[1])" ] }, { "cell_type": "code", "execution_count": null, "id": "7e24fc35-d980-4cba-b8ad-3e4163f9ef7b", "metadata": {}, "outputs": [], "source": [ "plt.imshow(skimage.measure.label(mask))" ] }, { "cell_type": "code", "execution_count": null, "id": "166a2af7-81ba-4ce2-9c02-d26b4be869b6", "metadata": {}, "outputs": [], "source": [ "distance = skimage.filters.gaussian(distance, sigma=30)\n", "tff.imshow(distance)" ] }, { "cell_type": "code", "execution_count": null, "id": "5c0184c2-79f1-4107-95e1-b13ccfc6fd05", "metadata": { "tags": [] }, "outputs": [], "source": [ "np.transpose(np.nonzero(skimage.morphology.local_maxima(distance)))" ] }, { "cell_type": "code", "execution_count": null, "id": "22525a5b-bbac-4827-8176-80144616e73d", "metadata": {}, "outputs": [], "source": [ "tff.imshow(ndimage.label(mask)[0])" ] }, { "cell_type": "code", "execution_count": null, "id": "1c615373-213d-4a75-8e04-31a693d74aa8", "metadata": {}, "outputs": [], "source": [ "res[1]" ] }, { "cell_type": "code", "execution_count": null, "id": "815666e8", "metadata": {}, "outputs": [], "source": [ "res[2][\"G\"][2][0]" ] }, { "cell_type": "code", "execution_count": null, "id": "e4baf99b-6fed-4de2-8859-939fa160599d", "metadata": {}, "outputs": [], "source": [ "res[1].plot()" ] }, { "cell_type": "code", "execution_count": null, "id": "72b580d2-3560-4fe6-aace-be12a0fed4d1", "metadata": {}, "outputs": [], "source": [ "import hvplot.pandas" ] }, { "cell_type": "code", "execution_count": null, "id": "b4bafd8b-5d5f-4fd3-a8b4-ab4ffb58bf2d", "metadata": {}, "outputs": [], "source": [ "res[1].hvplot()" ] }, { "cell_type": "code", "execution_count": null, "id": "de704ca4-0b76-4080-b986-bd9f81e38dd4", "metadata": {}, "outputs": [], "source": [ "import xarray as xr" ] }, { "cell_type": "code", "execution_count": null, "id": "68a79634-62b7-44e5-ba00-f63fd5c8a01e", "metadata": {}, "outputs": [], "source": [ "xim = xr.DataArray(\n", " data=[dim[\"G\"], dim[\"R\"], dim[\"C\"]],\n", " dims=[\"channel\", \"time\", \"y\", \"x\"],\n", " coords={\n", " \"channel\": [\"Green\", \"Red\", \"Cyan\"],\n", " \"time\": [0, 1, 2, 3],\n", " \"y\": range(512),\n", " \"x\": range(512),\n", " },\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "a95c7eae-de39-4a9c-8462-4e9963dfe02b", "metadata": {}, "outputs": [], "source": [ "import hvplot.xarray" ] }, { "cell_type": "code", "execution_count": null, "id": "c9c1a99b-66b1-4ca0-8eaf-23e4462f3318", "metadata": {}, "outputs": [], "source": [ "xim.sel(time=0, channel=\"Green\").hvplot(width=400, height=300)" ] }, { "cell_type": "code", "execution_count": null, "id": "e0889537-3fdd-4264-a501-8f242077c399", "metadata": {}, "outputs": [], "source": [ "xim.sel(time=0).hvplot(\n", " width=300,\n", " subplots=True,\n", " by=\"channel\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "5afa4630-4653-4533-adc8-0207bacfd86b", "metadata": {}, "outputs": [], "source": [ "hvplot.extension(\n", " \"bokeh\",\n", " \"matplotlib\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "97afb6a1-22c2-4eb6-8765-0244611e6e21", "metadata": {}, "outputs": [], "source": [ "img = xim.sel(time=0).sel(channel=\"Red\")" ] }, { "cell_type": "code", "execution_count": null, "id": "205a24f2-c84f-4a8b-bc4a-1fb8449bf08a", "metadata": {}, "outputs": [], "source": [ "hvimg = hv.Image(img)" ] }, { "cell_type": "raw", "id": "80659a83-311c-45e8-8c28-0104976484e2", "metadata": {}, "source": [ "#%%opts Image style(cmap='viridis')\n", "#%%opts Image [aspect=1388/1038] \n", "#%%output size=300\n", "f = xim.hvplot(frame_width=170, \n", " subplots=True, row=\"channel\", col=\"time\", yaxis=False, colorbar=False, xaxis=False)\n", "f" ] }, { "cell_type": "raw", "id": "2f5fb441-738f-49c1-8424-5ac25e2007e8", "metadata": {}, "source": [ "hv.save(f, \"b.png\", dpi=200)" ] }, { "cell_type": "code", "execution_count": null, "id": "e538208a-1244-4598-876c-793c09a6b625", "metadata": {}, "outputs": [], "source": [ "# %%opts Image [aspect=1388/1038]\n", "\n", "f = xim.sel(channel=\"Red\").hvplot(\n", " frame_width=300,\n", " frame_height=200,\n", " subplots=True,\n", " col=\"time\",\n", " yaxis=False,\n", " colorbar=False,\n", " xaxis=False,\n", " cmap=\"Reds\",\n", ") + xim.sel(channel=\"Cyan\").hvplot(\n", " subplots=True, col=\"time\", yaxis=False, colorbar=False, xaxis=False, cmap=\"Greens\"\n", ")\n", "f" ] }, { "cell_type": "code", "execution_count": null, "id": "4b7db3a2-ac2c-4490-81d7-8527b6fcb72a", "metadata": {}, "outputs": [], "source": [ "import aicsimageio\n", "\n", "aicsimageio.__version__" ] }, { "cell_type": "code", "execution_count": null, "id": "8f0e2b41-225b-4f3c-9cb7-387d2b18635c", "metadata": {}, "outputs": [], "source": [ "reader = aicsimageio.readers.tiff_reader.TiffReader\n", "aim1 = aicsimageio.AICSImage(\n", " \"/home/dati/dt-evolv/data/2022-06-17/images/Vero-Hek/2022-06-14/13080/TimePoint_1/6w-20Xph1-SpikeTest3_A02_s570_w14510D534-71A3-4EB5-B48F-F4331FE96517.tif\",\n", " reader=reader,\n", ")\n", "aim2 = aicsimageio.AICSImage(\n", " \"/home/dati/dt-evolv/data/2022-06-17/images/Vero-Hek/2022-06-14/13080/TimePoint_1/6w-20Xph1-SpikeTest3_A02_s570_w25049D5AC-5888-492F-891D-8BECC1AB67DF.tif\",\n", " reader=reader,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "df62aaa3-f901-47b4-9d79-b403ef2ae058", "metadata": {}, "outputs": [], "source": [ "x1 = aim1.xarray_data\n", "x2 = aim2.xarray_data" ] }, { "cell_type": "code", "execution_count": null, "id": "b57cd3ad-f5dc-4be4-a8a8-cc0b76d6067e", "metadata": {}, "outputs": [], "source": [ "# Create a new Dataset with new coordinates\n", "ds = xr.Dataset({\"c1\": x1, \"c2\": x2})\n", "\n", "# Assuming ds is your Dataset\n", "new_coords = {\"Frame\": [1, 2], \"excitation_wavelength\": [400, 500]}\n", "\n", "# Use assign_coords to set new coordinates\n", "ds_assigned = ds.assign_coords(**new_coords)\n", "\n", "ds_assigned" ] }, { "cell_type": "code", "execution_count": null, "id": "b39c4950-58c2-48e2-b7fe-b83e2aca4d92", "metadata": {}, "outputs": [], "source": [ "aim2.metadata[220:230] == aim1.metadata[220:230]" ] }, { "cell_type": "code", "execution_count": null, "id": "68f464df-66dc-440c-8b35-ae500a20aaab", "metadata": {}, "outputs": [], "source": [ "im = x1.to_numpy()[0, 0, 0]" ] }, { "cell_type": "code", "execution_count": null, "id": "81ad45de-1337-465d-828b-54be6d6beff7", "metadata": {}, "outputs": [], "source": [ "im1 = tff.imread(\"/home/dati/dt-evolv/data/2022-06-17/flat_w1.tif\")\n", "im2 = tff.imread(\"/home/dati/dt-evolv/data/2022-06-17/flat_w2.tif\")" ] }, { "cell_type": "code", "execution_count": null, "id": "f75da84d-cc83-4b08-a90a-bed3dc8a4953", "metadata": {}, "outputs": [], "source": [ "%%opts Image [aspect=1388/1038] \n", "\n", "%%opts Image.Cyan style(cmap=plt.cm.Blues)\n", "%%opts Image.Green style(cmap=plt.cm.Greens)\n", "%%opts Image.Red style(cmap=plt.cm.Reds)" ] }, { "cell_type": "code", "execution_count": null, "id": "d94768d0-dd19-4bf1-9c1a-050ad45c173f", "metadata": {}, "outputs": [], "source": [ "chans = (\n", " hv.Image(dim[\"C\"][0], group=\"cyan\")\n", " + hv.Image(dim[\"G\"][2], group=\"green\")\n", " + hv.Image(dim[\"R\"][1], group=\"red\")\n", ")\n", "\n", "chans" ] }, { "cell_type": "code", "execution_count": null, "id": "07f0fea1-d437-414f-b284-92b4afab4ba4", "metadata": {}, "outputs": [], "source": [ "hv.save(chans, \"a.png\")" ] }, { "cell_type": "markdown", "id": "5e11c5c8", "metadata": {}, "source": [ "# Holoviews" ] }, { "cell_type": "code", "execution_count": null, "id": "349d02fb", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "hv.notebook_extension()\n", "cm = plt.cm.inferno_r\n", "channels = [\"G\", \"R\", \"C\"]\n", "dim, n_ch, times = nima.read_tiff(fp, channels)\n", "\n", "dimm = nima.d_median(dim)\n", "f = nima.d_show(dimm, cmap=cm)" ] }, { "cell_type": "code", "execution_count": null, "id": "c9043c27", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "%%opts Image [aspect=512/512] \n", "\n", "%%opts Image.Cyan style(cmap=plt.cm.Blues)\n", "%%opts Image.Green style(cmap=plt.cm.Greens)\n", "%%opts Image.Red style(cmap=plt.cm.Reds)\n", "\n", "chans = hv.Image(dim['C'][0], group='cyan') \\\n", " + hv.Image(dim['G'][0], group='green') \\\n", " + hv.Image(dim['R'][0], group='red')\n", "\n", "chans" ] }, { "cell_type": "code", "execution_count": null, "id": "b62f2c28", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "c = [(i, hv.Image(im)) for i, im in enumerate(dim[\"C\"])]\n", "c = hv.HoloMap(c, kdims=[\"Frame\"])\n", "g = [(i, hv.Image(im)) for i, im in enumerate(dim[\"G\"])]\n", "g = hv.HoloMap(g, kdims=[\"Frame\"])\n", "r = [(i, hv.Image(im)) for i, im in enumerate(dim[\"R\"])]\n", "r = hv.HoloMap(r, kdims=[\"Frame\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "8b36acde", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "%%output holomap='auto'\n", "%%opts Image style(cmap='viridis')\n", "(c + g).select(Frame={0,5,6,7,10,30}).cols(2)" ] }, { "cell_type": "code", "execution_count": null, "id": "6ee63a6c", "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "c[::20].overlay(\"Frame\")" ] }, { "cell_type": "code", "execution_count": null, "id": "7ab7a811", "metadata": {}, "outputs": [], "source": [ "wl = hv.Dimension(\"excitation wavelength\", unit=\"nm\")\n", "c = c.add_dimension(wl, 1, 458)\n", "g = g.add_dimension(wl, 1, 488)\n", "r = r.add_dimension(wl, 1, 561)\n", "\n", "channels = c.clone()\n", "channels.update(g)\n", "channels.update(r)" ] }, { "cell_type": "code", "execution_count": null, "id": "b2bd59c4", "metadata": {}, "outputs": [], "source": [ "%%opts Image style(cmap='viridis')\n", "%%output size=300\n", "channels[::5].grid(['Frame', 'excitation wavelength'])" ] }, { "cell_type": "code", "execution_count": null, "id": "273d550c", "metadata": {}, "outputs": [], "source": [ "t = [(i, hv.Image(im)) for i, im in enumerate(dim[\"C\"])]" ] }, { "cell_type": "code", "execution_count": null, "id": "dfe4e459", "metadata": {}, "outputs": [], "source": [ "hv.HoloMap([(i, hv.Image(im)) for i, im in enumerate(dim[\"C\"])], kdims=[\"frame\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "150e0d3a", "metadata": {}, "outputs": [], "source": [ "hv.NdLayout(\n", " {\n", " k: hv.HoloMap(\n", " [(i, hv.Image(im)) for i, im in enumerate(dim[k])], kdims=[\"frame\"]\n", " )\n", " for k in dim\n", " },\n", " kdims=[\"channels\"],\n", ")[::4]" ] }, { "cell_type": "code", "execution_count": null, "id": "d5e18d8b", "metadata": {}, "outputs": [], "source": [ "%%opts Image (cmap='viridis') \n", "%%opts Image.A [aspect=2]\n", "im = hv.Image(dim[\"G\"][1], bounds=(0, 0, 512, 512))\n", "im2 = hv.Image(dim['C'][1], bounds=(0, 0, 512, 512))\n", "im3 = hv.Image(dimm['C'][1], bounds=(0, 0, 512, 512))\n", "((im * hv.HLine(y=350)) + im.sample(y=350) + (im2 * hv.HLine(y=150)) + im2.sample(y=150) * im3.sample(y=150)).cols(3)" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }