{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Ray-tracing simulation of fast camera\n", "===" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from matplotlib import pyplot as plt\n", "from mpl_toolkits.axes_grid1 import ImageGrid\n", "from raysect.optical import World\n", "from raysect.optical.observer import PowerPipeline2D, RGBAdaptiveSampler2D, RGBPipeline2D\n", "\n", "from cherab.phix.machine import import_phix_mesh\n", "from cherab.phix.observer import import_phix_camera\n", "from cherab.phix.plasma import import_plasma" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Create scene graph\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# scene world\n", "world = World()\n", "\n", "# import plasma\n", "plasma, eq = import_plasma(world)\n", "\n", "# import phix mesh\n", "mesh = import_phix_mesh(world, reflection=True)\n", "\n", "# import phix camera\n", "camera = import_phix_camera(world)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set up pipelines\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# RGB image and Power pipelines\n", "# NOTE: if you excute the code in .py script, the progress image can be displayed\n", "# when `display_progress = True`.\n", "rgb = RGBPipeline2D(display_unsaturated_fraction=1.0, name=\"sRGB\", display_progress=False)\n", "power = PowerPipeline2D(display_progress=False, name=\"power\")\n", "\n", "# set camera's pipeline property\n", "camera.pipelines = [rgb, power]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set other camera parameters\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# set sampler\n", "sampler = RGBAdaptiveSampler2D(rgb, ratio=10, fraction=0.2, min_samples=10, cutoff=0.05)\n", "\n", "camera.frame_sampler = sampler\n", "camera.min_wavelength = 400\n", "camera.max_wavelength = 780\n", "camera.spectral_rays = 1\n", "camera.spectral_bins = 20 # spectrum resolution between 400 - 780 nm in wavelength\n", "camera.per_pixel_samples = 10\n", "camera.lens_samples = 10" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Execute Ray-tracing\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.ion()\n", "camera.observe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save images and power data\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# save images\n", "rgb.save(\"rgb.png\")\n", "power.save(\"power.png\")\n", "\n", "# save power array data\n", "np.save(\"power.npy\", power.frame.mean)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Ray-traced images are shown below:\n", "\n", ".. figure:: ../../_static/images/plots/rgb.png\n", " \n", " RGB image\n", "\n", "\n", ".. figure:: ../../_static/images/plots/power.png\n", "\n", " Power monochrome image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show calculated power distribution\n", "---" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(dpi=150)\n", "grids = ImageGrid(fig, 111, (1, 1), axes_pad=0, cbar_mode=\"each\")\n", "mappable = grids[0].imshow(power.frame.mean.T, cmap=\"jet\")\n", "grids[0].set_xlabel(\"width [px]\")\n", "grids[0].set_ylabel(\"height [px]\")\n", "cbar = plt.colorbar(mappable, cax=grids.cbar_axes[0])\n", "cbar.set_label(\"Power [W]\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext", "tags": [] }, "source": [ ".. image:: ../../_static/images/plots/power_figure.png\n", " :align: center" ] }, { "attachments": {}, "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", "\n", " `demos/synthetic_calculation.py `_\n", " is the script file having the same workflow as the above codes." ] } ], "metadata": { "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.16" }, "nbsphinx": { "execute": "never" }, "vscode": { "interpreter": { "hash": "2725905a4c02db19e04df9b8fdbbe5ec65a73ea52bebaf9474aa1cc98819834c" } }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }