{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fast Cameras\n", "\n", "
\n", "\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "#delete files from the previous discharge\n", "if os.path.exists('FastCameras.html'):\n", " os.remove('FastCameras.html')\n", " \n", "if os.path.exists('SpeedCamera.png'):\n", " os.remove('SpeedCamera.png')\n", " \n", "if os.path.exists('FastCameras.png'):\n", " os.remove('FastCameras.png')\n", "\n", "if os.path.exists('plasma_position_FastCamera.csv'):\n", " os.remove('plasma_position_FastCamera.csv')\n", " \n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import requests\n", "\n", "from PIL import Image\n", "from io import BytesIO\n", "from IPython.display import Image as DispImage\n", "from IPython.display import Markdown\n", "\n", "shot_no = 35903\n", "\n", "FastCameras = True\n", "\n", "\n", "try:\n", " url = \"http://golem.fjfi.cvut.cz/shots/%i/Diagnostics/FastExCameras/plasma_film.png\"%(shot_no)\n", " image = requests.get(url)\n", " img = Image.open(BytesIO(image.content)).convert('L') #'L','1'\n", "\n", " data = np.asanyarray(img)\n", "\n", " r = []\n", " for i in range(data.shape[1]): #corresponds to the time evolution\n", " a=0\n", " b=0\n", " for j in range(data.shape[0]): \n", " a += data[j,i]*j\n", " b += data[j,i]\n", " r.append((a/b)*(170/336))\n", " duration = (len(r)/(1200*96))*1e3\n", "\n", " camera_time = np.linspace(0, duration, len(r))\n", " r_camera = pd.Series(r, index = camera_time)-85\n", " \n", " fig = plt.figure()\n", " ax = r_camera.plot(label = 'Fast Camera')\n", " plt.legend()\n", " ax.set(ylim=(-85, 85), title='Horizontal plasma position #%i'%shot_no,ylabel='$\\Delta$r visible radiation', xlabel = 'Time [ms]')\n", " ax.axhline(y=0, color='k', ls='--', lw=1, alpha=0.4)\n", " fig.savefig('SpeedCamera')\n", "except OSError:\n", " FastCameras = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(2,1)\n", "img = Image.open(BytesIO(image.content)).convert('RGB')\n", "data2=np.empty([data.shape[0], data.shape[1]])\n", "for i in range(data.shape[1]):\n", " for j in range(data.shape[0]):\n", " data2[j,i] = float(data[j*-1,i])\n", " \n", "print(data2.shape)\n", "ax[0].imshow(data2)\n", "ax[0].axhline(336/2, color='r')\n", "ax[0].set_title('Horizontal plasma position #%i'%shot_no)\n", "ax[0].get_xaxis().set_visible(False)\n", "ax[1] = r_camera.plot(label = 'Fast Camera')\n", "plt.legend()\n", "ax[1].set(ylim=(-85, 85),ylabel='$\\Delta$r visible radiation', xlabel = 'Time [ms]')\n", "ax[1].axhline(y=0, color='k', ls='--', lw=1, alpha=0.4)\n", "fig.savefig('SpeedCamera')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(r_camera.array)\n", "savedata_camera = 'plasma_position_FastCamera.csv'\n", "df.to_csv(savedata_camera)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Markdown(\"[Plasma position data from FastCamera - $r$ ](./{})\".format(savedata_camera))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }