{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Development" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "# import skimage.io\n", "# import matplotlib\n", "# import matplotlib.pyplot as plt\n", "# %matplotlib inline\n", "# nd2 = \"/home/dan/pims/pims/tests/data/bioformats/cluster.nd2\"\n", "from pathlib import Path\n", "\n", "import nima_io.read as ir\n", "\n", "tdata = Path(\"../../tests/data/\")\n", "\n", "lif = tdata / \"2015Aug28_TransHXB2_50min+DMSO.lif\"\n", "img_tile = tdata / \"t4_1.tif\" # C=3 T=4 S=15\n", "img_void_tile = tdata / \"tile6_1.tif\" # C=4 T=3 S=14 scattered\n", "# imgsingle = tdata / \"exp2_2.tif\" # C=2 T=81\n", "\n", "# mcts = tdata / \"multi-channel-time-series.ome.tif\" # C=3 T=7\n", "# bigtiff = tdata / \"LC26GFP_1.tf8\" # bigtiff\n", "\n", "slif = str(lif)\n", "simg_tile = str(img_tile)\n", "simg_void_tile = str(img_void_tile)\n", "# simgsingle = str(imgsingle)\n", "# smcts = str(mcts)Z`Z\n", "# sbigtiff = str(bigtiff)" ] }, { "cell_type": "markdown", "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Core metadata list at:\n", "https://docs.openmicroscopy.org/bio-formats/7.1.0/developers/file-reader.html\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "md, wr = ir.read(slif)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wr.rdr.setSeries(4)\n", "wr.rdr.getImageCount()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wr.rdr.getDimensionOrder()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "TODO: test convert value" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ome_store = wr.rdr.getMetadataStore()" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "## XML\n", "getRoot was used in imgread-0.2.1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "root = ome_store.getRoot()\n", "instrument = root.getInstrument(0)\n", "detector = instrument.getDetector(0)\n", "detector.getModel()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wr.rdr.getMetadataStoreRoot().getInstrument(0).getDetector(0).getModel()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wr.rdr.getMetadataStore().getRoot().getInstrument(0).getDetector(0).getModel()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "[m for m in root.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "image = root.getImage(3)\n", "[m for m in image.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "obj = image.getObjectiveSettings()\n", "[m for m in obj.__dir__() if m[:3] == \"get\"]\n", "obj.getID()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "pixels = image.getPixels()\n", "[m for m in pixels.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "scrolled": true, "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "ch = pixels.getChannel(0)\n", "[m for m in ch.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "lp = ch.getLightPath()\n", "[m for m in lp.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "pixels.getTimeIncrement()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "plane = pixels.getPlane(11)\n", "[m for m in plane.__dir__() if m[:3] == \"get\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "import jpype\n", "\n", "jpype.JObject(plane.getTheC()), plane.getDeltaT(), plane.getExposureTime()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "for k in root.__dir__():\n", " if k[:3] == \"get\":\n", " print(k)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "im = root.getImage(0)\n", "obj = im.getObjectiveSettings()\n", "(\n", " obj.getID(),\n", " obj.getMedium(),\n", " obj.getRefractiveIndex(),\n", " obj.getCorrectionCollar(),\n", " obj.getObjective(),\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "(\n", " wr.rdr.getMetadataStore().getObjectiveID(0, 0) == obj.getID(),\n", " wr.rdr.getMetadataStore().getObjectiveLensNA(0, 0),\n", ")" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "## md vs root (to remember)\n", "\n", "from md i can get info on camera, objectives ...\n", "\n", "but also key parameters like exposuretime, DeltaT, planePositionXYZ" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "md_vtile, wr_vtile = ir.read(simg_void_tile)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wr_vtile.rdr.getMetadataStore().getObjectiveCount(0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ome_store = wr_vtile.rdr.getMetadataStore()\n", "ome_store.getXMLAnnotationValue(\n", " 0\n", ") == ome_store.getRoot().getStructuredAnnotations().getXMLAnnotation(0).getValue()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "# import bioformats\n", "\n", "# md = bioformats.get_omexml_metadata(slif)\n", "from xml.etree import ElementTree as ET\n", "\n", "# mdroot = ET.fromstring(wr.rdr.getMetadataStore().dumpXML())\n", "java_string = (\n", " wr_vtile.rdr.getMetadataStoreRoot()\n", " .getStructuredAnnotations()\n", " .getXMLAnnotation(0)\n", " .getValue()\n", ")\n", "python_string = jpype.java.lang.String(java_string).toString()\n", "mdroot = ET.fromstring(python_string.getBytes())\n", "\n", "for a in mdroot:\n", " print((a.tag, a.attrib))\n", " for aa in a:\n", " print((\" GGSSS \", aa.tag, aa.attrib))\n", " for aaa in aa:\n", " print((\" GGSSS2 \", aaa.tag, aaa.attrib))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "import xmltodict\n", "\n", "m1 = xmltodict.parse(ome_store.dumpXML().getBytes())\n", "list(m1[\"OME\"]), m1[\"OME\"][\"Instrument\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "metalist = [\n", " (child.tag, [[child.attrib]])\n", " for child in ET.fromstring(ome_store.dumpXML().getBytes()).iter()\n", "]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "m = metalist[10]\n", "m[0], m[1][0][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "for child in mdroot:\n", " if child.tag.endswith(\"\"):\n", " for grandchild in child:\n", " print((grandchild.tag, grandchild.attrib))" ] } ], "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.11.7" }, "name": "general_reading_and_development.ipynb" }, "nbformat": 4, "nbformat_minor": 4 }