{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Ray-traced images\n", "===" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, I simulated the fast-visible camera equiped with PHiX using raysect, and considered the reflected light effect by comparing a non-reflected image with normal one." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from mpl_toolkits.axes_grid1 import ImageGrid\n", "\n", "plt.rcParams[\"figure.dpi\"] = 150\n", "plt.rcParams[\"font.size\"] = 13" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set file paths and show the information about ray-tracing conditions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# path to folder storing ray-traced data\n", "DATA_SYNTHETIC_DIR = Path().cwd().parent / \"data\" / \"synthetic_data\"\n", "W_REFLECTION = DATA_SYNTHETIC_DIR / \"2020_07_25_01_51_55\"\n", "WO_REFLECTION = DATA_SYNTHETIC_DIR / \"2020_07_24_20_39_22_wo_ref\"\n", "\n", "# header information\n", "print(\"With the effect of reflected light:\")\n", "print((W_REFLECTION / \"result.txt\").read_text())\n", "\n", "print(\"Without the effect of reflected light:\")\n", "print((WO_REFLECTION / \"result.txt\").read_text())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "show the typcal ray-traced image with reflection." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load ray-traced images\n", "power_wo = np.load(WO_REFLECTION / \"Power.npy\")\n", "power_total = np.load(W_REFLECTION / \"Power.npy\")\n", "power_ref = power_total - power_wo\n", "A_1px = (20e-6) ** 2 # Area of 1 pixel" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure()\n", "vmax = power_total.max() / A_1px\n", "vmin = 0.0\n", "grid = ImageGrid(\n", " fig, 111, nrows_ncols=(1, 1), axes_pad=0.02, label_mode=\"L\", cbar_mode=\"single\", cbar_pad=0\n", ")\n", "im1 = grid[0].imshow(np.transpose(power_total) / A_1px, cmap=\"jet\", vmax=vmax, vmin=vmin)\n", "grid[0].set_xlabel(\"x [px]\")\n", "grid[0].set_ylabel(\"y [px]\")\n", "grid[0].set_title(\"total\")\n", "cbar1 = plt.colorbar(im1, grid.cbar_axes[0])\n", "cbar1.set_label(\"Irradiance [W/m$^2$]\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Compare with w/o reflection light by subtracting without reflection irradiance from total Irradiance.\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [], "source": [ "fig = plt.figure(figsize=(7, 100))\n", "vmax = power_total.max() / A_1px\n", "vmin = 0.0\n", "grid = ImageGrid(\n", " fig, 111, nrows_ncols=(1, 3), axes_pad=0.02, label_mode=\"L\", cbar_mode=\"single\", cbar_pad=0\n", ")\n", "im1 = grid[0].imshow(np.transpose(power_total) / A_1px, cmap=\"jet\", vmax=vmax, vmin=vmin)\n", "im2 = grid[1].imshow(np.transpose(power_wo) / A_1px, cmap=\"jet\", vmax=vmax, vmin=vmin)\n", "im3 = grid[2].imshow(np.transpose(power_ref) / A_1px, cmap=\"jet\", vmax=vmax, vmin=vmin)\n", "grid[0].set_xlabel(\"x [px]\")\n", "grid[0].set_ylabel(\"y [px]\")\n", "grid[0].set_title(\"total\")\n", "grid[1].set_title(\"w/o Reflection\")\n", "grid[2].set_title(\"Reflection only\")\n", "cbar1 = plt.colorbar(im1, grid.cbar_axes[0])\n", "cbar1.set_label(\"Irradiance [W/m$^2$]\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's compare values which is retrieved by slicing the above images either at cetain x or y line.\n", "The slicing points is corresponding to the pixel having the maximum value." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "max_point = np.unravel_index(np.argmax(power_total), power_total.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "ypx = max_point[1] + 1\n", "# ypx = 256\n", "ax.plot(power_total[:, ypx - 1] / A_1px, label=\"total\")\n", "ax.plot(power_wo[:, ypx - 1] / A_1px, label=\"w/o reflection\")\n", "ax.plot(power_ref[:, ypx - 1] / A_1px, label=\"Reflection only\")\n", "ax.legend()\n", "ax.set_ylabel(\"Irradiance [W/m$^2$]\")\n", "ax.set_xlabel(\"x [px]\")\n", "ax.set_title(f\"y = {ypx} px\")\n", "# ax.set_ylim(0, 40)\n", "ax.set_xlim(0, power_total.shape[0] - 1)\n", "ax.set_ylim(0, 90);\n", "# fig.set_size_inches(6,5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "xpx = max_point[0] + 1\n", "ax.plot(power_total[xpx - 1, :] / A_1px, label=\"total\")\n", "ax.plot(power_wo[xpx - 1, :] / A_1px, label=\"w/o reflection\")\n", "ax.plot(power_ref[xpx - 1, :] / A_1px, label=\"Reflection only\")\n", "ax.legend()\n", "ax.set_ylabel(\"Irradiance [W/m$^2$]\")\n", "ax.set_xlabel(\"y [px]\")\n", "ax.set_title(f\"x = {xpx} px\")\n", "# ax.set_ylim(0, 40)\n", "ax.set_xlim(0, power_total.shape[1] - 1)\n", "ax.set_ylim(0, 90);\n", "# fig.set_size_inches(6,5)" ] } ], "metadata": { "celltoolbar": "Tags", "kernelspec": { "display_name": "cherab-phix-dev", "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.9.15 | packaged by conda-forge | (main, Nov 22 2022, 15:55:03) \n[GCC 10.4.0]" }, "vscode": { "interpreter": { "hash": "2725905a4c02db19e04df9b8fdbbe5ec65a73ea52bebaf9474aa1cc98819834c" } } }, "nbformat": 4, "nbformat_minor": 4 }