diff --git a/conversion_widget.ipynb b/conversion_widget.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..b0fbe7566afef28b0241534de947116f7fd13466 --- /dev/null +++ b/conversion_widget.ipynb @@ -0,0 +1,357 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 35, + "id": "0680c4c1-3b25-4a86-a58a-4feefdf92df5", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/aaristov/miniconda3/envs/nd2/lib/python3.8/site-packages/napari_tools_menu/__init__.py:179: FutureWarning: Public access to Window.qt_viewer is deprecated and will be removed in\n", + "v0.5.0. It is considered an \"implementation detail\" of the napari\n", + "application, not part of the napari viewer model. If your use case\n", + "requires access to qt_viewer, please open an issue to discuss.\n", + " self.tools_menu = ToolsMenu(self, self.qt_viewer.viewer)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "opening /home/aaristov/Anchor/Lena/Data/E.coli/Ciprofloxacin/20220827-ecoli-cipro/day1/TRITC.nd2\n", + "{'P': 6, 'Z': 31, 'Y': 7138, 'X': 22543}\n", + "No channels, {'P': 6, 'Z': 31, 'Y': 7138, 'X': 22543}\n", + "[6, 31, 7138, 22543] 6\n" + ] + } + ], + "source": [ + "from napari import Viewer, run\n", + "from napari.layers import Image, Layer\n", + "\n", + "from qtpy.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QPushButton\n", + "\n", + "from magicgui.widgets import create_widget, Label\n", + "\n", + "from matplotlib.backends.backend_qtagg import (\n", + " FigureCanvas, NavigationToolbar2QT as NavigationToolbar)\n", + "from matplotlib.figure import Figure\n", + "\n", + "\n", + "class SamplePlugin(QWidget):\n", + " def __init__(self, viewer: Viewer):\n", + " super().__init__()\n", + " self.viewer = viewer\n", + " self.select_image = create_widget(label=\"BF\", annotation=Image)\n", + " self.select_mask = create_widget(label=\"mask\", annotation=Layer)\n", + " self.canvas = FigureCanvas(Figure(figsize=(5,5)))\n", + " self.ax = self.canvas.figure.subplots()\n", + "\n", + " self.ax.plot([0, 5, 6], [2, 7, 14])\n", + " \n", + " self.dims = []\n", + " \n", + " ll = QLabel()\n", + " ll.setText('BF')\n", + " self.mm = QLabel()\n", + " self.mm.setText('mask')\n", + " \n", + " self.btn = QPushButton(\"Add operation\")\n", + " self.btn.clicked.connect(self.add_op)\n", + " \n", + " self.layout = QVBoxLayout()\n", + " self.layout.addWidget(ll)\n", + " self.layout.addWidget(self.select_image.native)\n", + " self.layout.addStrut(1)\n", + " self.layout.addWidget(self.mm)\n", + " # layout.addWidget(self.select_mask.native)\n", + " # layout.addWidget(self.canvas)\n", + "\n", + " self.setLayout(self.layout)\n", + " \n", + " def reset_choices(self, event=None):\n", + " self.select_image.reset_choices(event)\n", + " self.select_mask.reset_choices(event)\n", + " \n", + " self.dims.append(viewer.layers[self.select_image.current_choice].data.shape)\n", + " \n", + " self.mm.setText(str(self.dims[-1]))\n", + " \n", + " self.combo = QComboBox()\n", + " self.combo.addItems(['max_projection', 'split_dims', 'export'])\n", + " self.combo.currentIndexChanged.connect(self.choose_op)\n", + " self.layout.addWidget(self.combo)\n", + " self.layout.addWidget(self.btn)\n", + " \n", + " def choose_op(self, i):\n", + " print(f'{i} selected: {self.combo.currentText()}')\n", + " \n", + " def add_op(self):\n", + " op = QLabel()\n", + " op.setText(self.combo.currentText())\n", + " self.layout.addWidget(op)\n", + " \n", + " combo = QComboBox()\n", + " combo.addItems(map(str, self.dims[-1]))\n", + " self.layout.addWidget(combo)\n", + " \n", + " qdim = QLabel()\n", + " self.layout.addWidget(qdim)\n", + " self.dims.append(rm_dim(self.dims[-1], combo.currentText()))\n", + " combo.currentIndexChanged.connect(lambda: qdim.setText('Output shape: ' + str(self.dims[-1])))\n", + " \n", + " \n", + "\n", + "\n", + "\n", + "viewer = Viewer()\n", + "\n", + "plugin = SamplePlugin(viewer)\n", + "\n", + "viewer.window.add_dock_widget(plugin)\n", + "\n", + "run()" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "9d844484-94ab-4979-b4ac-8c9d8063d957", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<table>\n", + " <tr>\n", + " <td>\n", + " <table>\n", + " <thead>\n", + " <tr>\n", + " <td> </td>\n", + " <th> Array </th>\n", + " <th> Chunk </th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " \n", + " <tr>\n", + " <th> Bytes </th>\n", + " <td> 55.75 GiB </td>\n", + " <td> 306.92 MiB </td>\n", + " </tr>\n", + " \n", + " <tr>\n", + " <th> Shape </th>\n", + " <td> (6, 31, 7138, 22543) </td>\n", + " <td> (1, 1, 7138, 22543) </td>\n", + " </tr>\n", + " <tr>\n", + " <th> Count </th>\n", + " <td> 372 Tasks </td>\n", + " <td> 186 Chunks </td>\n", + " </tr>\n", + " <tr>\n", + " <th> Type </th>\n", + " <td> uint16 </td>\n", + " <td> numpy.ndarray </td>\n", + " </tr>\n", + " </tbody>\n", + " </table>\n", + " </td>\n", + " <td>\n", + " <svg width=\"374\" height=\"108\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n", + "\n", + " <!-- Horizontal lines -->\n", + " <line x1=\"0\" y1=\"0\" x2=\"25\" y2=\"0\" style=\"stroke-width:2\" />\n", + " <line x1=\"0\" y1=\"25\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Vertical lines -->\n", + " <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n", + " <line x1=\"4\" y1=\"0\" x2=\"4\" y2=\"25\" />\n", + " <line x1=\"8\" y1=\"0\" x2=\"8\" y2=\"25\" />\n", + " <line x1=\"12\" y1=\"0\" x2=\"12\" y2=\"25\" />\n", + " <line x1=\"16\" y1=\"0\" x2=\"16\" y2=\"25\" />\n", + " <line x1=\"21\" y1=\"0\" x2=\"21\" y2=\"25\" />\n", + " <line x1=\"25\" y1=\"0\" x2=\"25\" y2=\"25\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Colored Rectangle -->\n", + " <polygon points=\"0.0,0.0 25.412616514582485,0.0 25.412616514582485,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", + "\n", + " <!-- Text -->\n", + " <text x=\"12.706308\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >6</text>\n", + " <text x=\"45.412617\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,45.412617,12.706308)\">1</text>\n", + "\n", + "\n", + " <!-- Horizontal lines -->\n", + " <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", + " <line x1=\"95\" y1=\"43\" x2=\"109\" y2=\"58\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Vertical lines -->\n", + " <line x1=\"95\" y1=\"0\" x2=\"95\" y2=\"43\" style=\"stroke-width:2\" />\n", + " <line x1=\"95\" y1=\"0\" x2=\"95\" y2=\"44\" />\n", + " <line x1=\"95\" y1=\"0\" x2=\"95\" y2=\"44\" />\n", + " <line x1=\"96\" y1=\"1\" x2=\"96\" y2=\"45\" />\n", + " <line x1=\"96\" y1=\"1\" x2=\"96\" y2=\"45\" />\n", + " <line x1=\"97\" y1=\"2\" x2=\"97\" y2=\"46\" />\n", + " <line x1=\"97\" y1=\"2\" x2=\"97\" y2=\"46\" />\n", + " <line x1=\"98\" y1=\"3\" x2=\"98\" y2=\"47\" />\n", + " <line x1=\"98\" y1=\"3\" x2=\"98\" y2=\"47\" />\n", + " <line x1=\"99\" y1=\"4\" x2=\"99\" y2=\"48\" />\n", + " <line x1=\"99\" y1=\"4\" x2=\"99\" y2=\"48\" />\n", + " <line x1=\"100\" y1=\"5\" x2=\"100\" y2=\"49\" />\n", + " <line x1=\"100\" y1=\"5\" x2=\"100\" y2=\"49\" />\n", + " <line x1=\"101\" y1=\"6\" x2=\"101\" y2=\"49\" />\n", + " <line x1=\"101\" y1=\"6\" x2=\"101\" y2=\"50\" />\n", + " <line x1=\"102\" y1=\"7\" x2=\"102\" y2=\"50\" />\n", + " <line x1=\"102\" y1=\"7\" x2=\"102\" y2=\"51\" />\n", + " <line x1=\"103\" y1=\"8\" x2=\"103\" y2=\"51\" />\n", + " <line x1=\"103\" y1=\"8\" x2=\"103\" y2=\"52\" />\n", + " <line x1=\"104\" y1=\"9\" x2=\"104\" y2=\"52\" />\n", + " <line x1=\"104\" y1=\"9\" x2=\"104\" y2=\"53\" />\n", + " <line x1=\"105\" y1=\"10\" x2=\"105\" y2=\"53\" />\n", + " <line x1=\"105\" y1=\"10\" x2=\"105\" y2=\"54\" />\n", + " <line x1=\"106\" y1=\"11\" x2=\"106\" y2=\"54\" />\n", + " <line x1=\"106\" y1=\"11\" x2=\"106\" y2=\"55\" />\n", + " <line x1=\"107\" y1=\"12\" x2=\"107\" y2=\"55\" />\n", + " <line x1=\"107\" y1=\"12\" x2=\"107\" y2=\"56\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"108\" y2=\"56\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"108\" y2=\"57\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"108\" y2=\"57\" />\n", + " <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"58\" />\n", + " <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"58\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Colored Rectangle -->\n", + " <polygon points=\"95.0,0.0 109.9485979497544,14.948597949754403 109.9485979497544,58.67104320508231 95.0,43.72244525532791\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", + "\n", + " <!-- Horizontal lines -->\n", + " <line x1=\"95\" y1=\"0\" x2=\"215\" y2=\"0\" style=\"stroke-width:2\" />\n", + " <line x1=\"95\" y1=\"0\" x2=\"215\" y2=\"0\" />\n", + " <line x1=\"95\" y1=\"0\" x2=\"215\" y2=\"0\" />\n", + " <line x1=\"96\" y1=\"1\" x2=\"216\" y2=\"1\" />\n", + " <line x1=\"96\" y1=\"1\" x2=\"216\" y2=\"1\" />\n", + " <line x1=\"97\" y1=\"2\" x2=\"217\" y2=\"2\" />\n", + " <line x1=\"97\" y1=\"2\" x2=\"217\" y2=\"2\" />\n", + " <line x1=\"98\" y1=\"3\" x2=\"218\" y2=\"3\" />\n", + " <line x1=\"98\" y1=\"3\" x2=\"218\" y2=\"3\" />\n", + " <line x1=\"99\" y1=\"4\" x2=\"219\" y2=\"4\" />\n", + " <line x1=\"99\" y1=\"4\" x2=\"219\" y2=\"4\" />\n", + " <line x1=\"100\" y1=\"5\" x2=\"220\" y2=\"5\" />\n", + " <line x1=\"100\" y1=\"5\" x2=\"220\" y2=\"5\" />\n", + " <line x1=\"101\" y1=\"6\" x2=\"221\" y2=\"6\" />\n", + " <line x1=\"101\" y1=\"6\" x2=\"221\" y2=\"6\" />\n", + " <line x1=\"102\" y1=\"7\" x2=\"222\" y2=\"7\" />\n", + " <line x1=\"102\" y1=\"7\" x2=\"222\" y2=\"7\" />\n", + " <line x1=\"103\" y1=\"8\" x2=\"223\" y2=\"8\" />\n", + " <line x1=\"103\" y1=\"8\" x2=\"223\" y2=\"8\" />\n", + " <line x1=\"104\" y1=\"9\" x2=\"224\" y2=\"9\" />\n", + " <line x1=\"104\" y1=\"9\" x2=\"224\" y2=\"9\" />\n", + " <line x1=\"105\" y1=\"10\" x2=\"225\" y2=\"10\" />\n", + " <line x1=\"105\" y1=\"10\" x2=\"225\" y2=\"10\" />\n", + " <line x1=\"106\" y1=\"11\" x2=\"226\" y2=\"11\" />\n", + " <line x1=\"106\" y1=\"11\" x2=\"226\" y2=\"11\" />\n", + " <line x1=\"107\" y1=\"12\" x2=\"227\" y2=\"12\" />\n", + " <line x1=\"107\" y1=\"12\" x2=\"227\" y2=\"12\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"228\" y2=\"13\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"228\" y2=\"13\" />\n", + " <line x1=\"108\" y1=\"13\" x2=\"228\" y2=\"13\" />\n", + " <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" />\n", + " <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Vertical lines -->\n", + " <line x1=\"95\" y1=\"0\" x2=\"109\" y2=\"14\" style=\"stroke-width:2\" />\n", + " <line x1=\"215\" y1=\"0\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Colored Rectangle -->\n", + " <polygon points=\"95.0,0.0 215.0,0.0 229.9485979497544,14.948597949754403 109.9485979497544,14.948597949754403\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", + "\n", + " <!-- Horizontal lines -->\n", + " <line x1=\"109\" y1=\"14\" x2=\"229\" y2=\"14\" style=\"stroke-width:2\" />\n", + " <line x1=\"109\" y1=\"58\" x2=\"229\" y2=\"58\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Vertical lines -->\n", + " <line x1=\"109\" y1=\"14\" x2=\"109\" y2=\"58\" style=\"stroke-width:2\" />\n", + " <line x1=\"229\" y1=\"14\" x2=\"229\" y2=\"58\" style=\"stroke-width:2\" />\n", + "\n", + " <!-- Colored Rectangle -->\n", + " <polygon points=\"109.9485979497544,14.948597949754403 229.9485979497544,14.948597949754403 229.9485979497544,58.67104320508231 109.9485979497544,58.67104320508231\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n", + "\n", + " <!-- Text -->\n", + " <text x=\"169.948598\" y=\"78.671043\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >22543</text>\n", + " <text x=\"249.948598\" y=\"36.809821\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,249.948598,36.809821)\">7138</text>\n", + " <text x=\"92.474299\" y=\"71.196744\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,92.474299,71.196744)\">31</text>\n", + "</svg>\n", + " </td>\n", + " </tr>\n", + "</table>" + ], + "text/plain": [ + "dask.array<_dask_block, shape=(6, 31, 7138, 22543), dtype=uint16, chunksize=(1, 1, 7138, 22543), chunktype=numpy.ndarray>" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "viewer.layers[plugin.select_image.current_choice].data" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "4ffc2f5f-fd24-4a0f-a496-6d1437919f07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[31, 7138, 22543]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ll=[6, 31, 7138, 22543]\n", + "ll.remove(6)\n", + "ll" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83479001-943b-49e1-9f47-8bf1c7d09a7b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "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.8.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}