|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# deeptrack.backend.pint_definition\n", |
| 8 | + "<a href=\"https://colab.research.google.com/github/DeepTrackAI/DeepTrack2/blob/develop/tutorials/3-advanced-topics/DTAT399B_backend.pint_definition.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 1, |
| 14 | + "metadata": {}, |
| 15 | + "outputs": [], |
| 16 | + "source": [ |
| 17 | + "# !pip install deeptrack # Uncomment if running on Colab/Kaggle." |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "This advanced tutorial introduces the pint_definition module." |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "metadata": {}, |
| 30 | + "source": [ |
| 31 | + "## 1. What is `pint_definition`?\n", |
| 32 | + "\n", |
| 33 | + "The `pint_definition` module consolidates and extends the default definitions provided by Pint's \n", |
| 34 | + "`default_en.txt` and `constants_en.txt` files. It defines physical constants, \n", |
| 35 | + "unit systems, and project-specific adjustments necessary for DeepTrack2." |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "markdown", |
| 40 | + "metadata": {}, |
| 41 | + "source": [ |
| 42 | + "## 2. Unit Quantities\n", |
| 43 | + "Pint lets us include units when calculating quantities.\n" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": 21, |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [ |
| 51 | + { |
| 52 | + "name": "stdout", |
| 53 | + "output_type": "stream", |
| 54 | + "text": [ |
| 55 | + "Wavelength: 550 nanometer\n", |
| 56 | + "Frequency: 545.4545454545453 terahertz\n" |
| 57 | + ] |
| 58 | + } |
| 59 | + ], |
| 60 | + "source": [ |
| 61 | + "from pint import UnitRegistry\n", |
| 62 | + "from deeptrack.backend.pint_definition import pint_definitions\n", |
| 63 | + "\n", |
| 64 | + "# Initialize UnitRegistry with microscopy-related units\n", |
| 65 | + "units = UnitRegistry(pint_definitions.split(\"\\n\"))\n", |
| 66 | + "\n", |
| 67 | + "# Define wavelength in nanometers\n", |
| 68 | + "wavelength = 550 * units.nanometer # Green light\n", |
| 69 | + "\n", |
| 70 | + "c = 3e8 * units.meter / units.second\n", |
| 71 | + "\n", |
| 72 | + "frequency = c / wavelength\n", |
| 73 | + "\n", |
| 74 | + "print(f\"Wavelength: {wavelength}\")\n", |
| 75 | + "print(f\"Frequency: {frequency.to(units.terahertz)}\") " |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "metadata": {}, |
| 81 | + "source": [ |
| 82 | + "## 3. Diffraction Limit" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "code", |
| 87 | + "execution_count": 22, |
| 88 | + "metadata": {}, |
| 89 | + "outputs": [ |
| 90 | + { |
| 91 | + "name": "stdout", |
| 92 | + "output_type": "stream", |
| 93 | + "text": [ |
| 94 | + "Resolution limit: 178.57142857142858 nanometer\n" |
| 95 | + ] |
| 96 | + } |
| 97 | + ], |
| 98 | + "source": [ |
| 99 | + "Numerical_aperture = 1.4 \n", |
| 100 | + "wavelength = 500 * units.nanometer\n", |
| 101 | + "resolution = wavelength / (2 * Numerical_aperture)\n", |
| 102 | + "\n", |
| 103 | + "print(f\"Resolution limit: {resolution.to(units.nanometer)}\")" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "metadata": {}, |
| 109 | + "source": [ |
| 110 | + "## 4. Exposure Time and Motion Blur" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": null, |
| 116 | + "metadata": {}, |
| 117 | + "outputs": [ |
| 118 | + { |
| 119 | + "name": "stdout", |
| 120 | + "output_type": "stream", |
| 121 | + "text": [ |
| 122 | + "Motion blur: 19.999999999999996 nanometer\n" |
| 123 | + ] |
| 124 | + } |
| 125 | + ], |
| 126 | + "source": [ |
| 127 | + "exposure_time = 2 * units.millisecond \n", |
| 128 | + "\n", |
| 129 | + "sample_velocity = 10 * units.micrometer / units.second \n", |
| 130 | + "\n", |
| 131 | + "blur_distance = sample_velocity * exposure_time\n", |
| 132 | + "\n", |
| 133 | + "print(f\"Motion blur: {blur_distance.to(units.nanometer)}\")" |
| 134 | + ] |
| 135 | + } |
| 136 | + ], |
| 137 | + "metadata": { |
| 138 | + "kernelspec": { |
| 139 | + "display_name": "Python 3", |
| 140 | + "language": "python", |
| 141 | + "name": "python3" |
| 142 | + }, |
| 143 | + "language_info": { |
| 144 | + "codemirror_mode": { |
| 145 | + "name": "ipython", |
| 146 | + "version": 3 |
| 147 | + }, |
| 148 | + "file_extension": ".py", |
| 149 | + "mimetype": "text/x-python", |
| 150 | + "name": "python", |
| 151 | + "nbconvert_exporter": "python", |
| 152 | + "pygments_lexer": "ipython3", |
| 153 | + "version": "3.9.13" |
| 154 | + } |
| 155 | + }, |
| 156 | + "nbformat": 4, |
| 157 | + "nbformat_minor": 2 |
| 158 | +} |
0 commit comments