{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plasma Position\n", "The mission of this script is to process data from Mirnov coils, determine plasma position and thus help with plasma stabilization. Mirnov coils are type of magnetic diagnostics and are used to the plasma position determination on GOLEM. Four Mirnov coils are placed inside the tokamak 93 mm from the center of the chamber. The effective area of each coil is $A_{eff}=3.8\\cdot10^{-3}$ m. Coils $mc_9$ and $mc_1$ are used to determination the horizontal plasma position and coils $mc_5$ and $mc_{13}$ to determination vertical plasma position.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Procedure (This notebook to download)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import glob\n", "\n", "#remove files from the previous discharge\n", "def remove_old(name):\n", " if os.path.exists(name):\n", " os.remove(name)\n", " \n", "names = ['analysis.html','icon-fig.png', 'plasma_position.png']\n", "for name in names:\n", " remove_old(name)\n", " \n", "if os.path.exists('Results/'):\n", " file=glob.glob('Results/*')\n", " for f in file:\n", " os.remove(f)\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from scipy import integrate, signal, interpolate\n", "import pandas as pd\n", "\n", "\n", "import holoviews as hv\n", "hv.extension('bokeh')\n", "import hvplot.pandas\n", "import requests\n", "\n", "from IPython.display import Markdown\n", "\n", "#execute time\n", "from timeit import default_timer as timer\n", "start_execute = timer()\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "BDdata_URL = \"http://golem.fjfi.cvut.cz/shots/{shot_no}/Diagnostics/BasicDiagnostics/Basic/{identifier}.csv\"\n", "data_URL = \"http://golem.fjfi.cvut.cz/shots/{shot_no}/Diagnostics/LimiterMirnovCoils/Default/DAS_raw_data_dir/NIdata_6133.lvm\" #NI Standart (DAS) new address\n", "\n", "\n", "shot_no = 44582 # to be replaced by the actual discharge number\n", "\n", "vacuum_shot = # to be replaced by the discharge command line paramater \"vacuum_shot\"\n", "\n", "\n", "ds = np.DataSource(destpath='') " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def open_remote(shot_no, identifier, url_template=data_URL):\n", " return ds.open(url_template.format(shot_no=shot_no, identifier=identifier))\n", "\n", "def read_signal(shot_no, identifier, url = data_URL, data_type='csv'): \n", " file = open_remote(shot_no, identifier, url)\n", " if data_type == 'lvm':\n", " channels = ['Time', 'mc1', 'mc5', 'mc9', 'mc13', '5', 'RogQuadr', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']\n", " return pd.read_table(file, sep = '\\t', names=channels)\n", " else:\n", " return pd.read_csv(file, names=['Time', identifier],\n", " index_col = 'Time', squeeze=True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data integration and $B_t$ elimination\n", "\n", "The coils measure voltage induced by changes in poloidal magnetic field. In order to obtain measured quantity (poloidal magnetic field), it is necessary to integrate the measured voltage and multiply by constant: $B(t)=\\frac{1}{A_{eff}}\\int_{0}^{t} U_{sig}(\\tau)d\\tau$\n", "\n", "\n", "Ideally axis of the coils is perpendicular to the toroidal magnetic field, but in fact they are slightly deflected and measure toroidal magnetic field too. To determine the position of the plasma, we must eliminate this additional signal. For this we use vacuum discharge with the same parameters." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def elimination (shot_no, identifier, vacuum_shot = False):\n", " #load data \n", " mc = (read_signal(shot_no, identifier, data_URL, 'lvm'))\n", " mc = mc.set_index('Time')\n", " mc = mc.replace([np.inf, -np.inf, np.nan], value = 0)\n", " mc = mc[identifier]\n", " \n", " konst = 1/(3.8e-03)\n", " \n", " \n", " if vacuum_shot == False: \n", " signal_start = mc.index[0]\n", " length = len(mc)\n", " Bt = read_signal(shot_no, 'BtCoil_integrated', BDdata_URL).loc[signal_start:signal_start+length*1e-06]\n", " if len(Bt)>len(mc):\n", " Bt = Bt.iloc[:length] \n", " if len(Bt)85 or i <0:\n", " a = a.replace(i, value = 0)\n", " else:\n", "\n", " plasma_time.append(a.index[t])\n", "\n", " t+=1\n", "start = plasma_time[0]-1e-03 \n", "end = plasma_time[-1]-1e-03 \n", "print('start =', round(start, 3), 'ms')\n", "print('end =', round(end, 3), 'ms')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "r_cut = r.loc[start:end]\n", "a_cut = a.loc[start:end]\n", "z_cut = z.loc[start:end]\n", "\n", "df_processed = pd.concat([r_cut.rename('r'), z_cut.rename('z'), a_cut.rename('a')], axis= 'columns')\n", "df_processed\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "savedata = 'plasma_position.csv'\n", "df_processed.to_csv(savedata)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Markdown(\"[Plasma position data - $r, z, a$ ](./{})\".format(savedata))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Graphs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hline = hv.HLine(0)\n", "hline.opts(color='k',line_dash='dashed', alpha = 0.4,line_width=1.0)\n", "\n", "layout = hv.Layout([df_processed[v].hvplot.line(\n", " xlabel='', ylabel=l,ylim=(-85,85), xlim=(start,end),legend=False, title='', grid=True, group_label=v)\n", " for (v, l) in [('r', ' r [mm]'), ('z', 'z [mm]'), ('a', 'a [mm]')] ])*hline\n", "\n", "plot=layout.cols(1).opts(hv.opts.Curve(width=600, height=200), hv.opts.Curve('a', xlabel='time [ms]'))\n", "\n", "plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_processed.describe()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "z_end=round(z_cut.iat[-25],2)\n", "z_start=round(z_cut.iat[25],2)\n", "r_end=round(r_cut.iat[-25],2)\n", "r_start=round(r_cut.iat[25],2)\n", "\n", "name=('z_start', 'z_end', 'r_start', 'r_end','plasma_start', 'plasma_end')\n", "values=(z_start, z_end, r_start, r_end, start, end)\n", "data={'Values':[z_start, z_end, r_start, r_end, start, end]}\n", "results=pd.DataFrame(data, index=name)\n", " \n", "dictionary='Results/'\n", "j=0\n", "for i in values :\n", " with open(dictionary+name[j], 'w') as f:\n", " f.write(str(i))\n", " j+=1\n", " \n", "results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Icon fig" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "responsestab = requests.get(\"http://golem.fjfi.cvut.cz/shots/%i/Production/Parameters/PowSup4InnerStab\"%shot_no)\n", "stab = responsestab.text\n", "\n", "if not '-1' in stab or 'Not Found' in stab and exStab==False:\n", " fig, axs = plt.subplots(4, 1, sharex=True, dpi=200)\n", " dataNI = (read_signal(shot_no, 'Rog', data_URL, 'lvm')) #data from NI\n", " dataNI = dataNI.set_index('Time')\n", " dataNI = dataNI.set_index(dataNI.index*1e3)\n", " Irog = dataNI['RogQuadr']\n", "# Irog=abs(Irog)\n", " Irog*=1/5e-3\n", " r.plot(grid=True, ax=axs[0])\n", " z.plot(grid=True, ax=axs[1])\n", " a.plot(grid=True, ax=axs[2])\n", " Irog.plot(grid=True, ax=axs[3])\n", " axs[3].set(xlim=(start,end), ylabel = 'I [A]')\n", " axs[2].set(ylim=(0,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$a$ [mm]')\n", " axs[1].set(ylim=(-85,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$\\Delta$z [mm]')\n", " axs[0].set(ylim=(-85,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$\\Delta$r [mm]', \n", " title = 'Horizontal, vertical plasma position and radius #{}'.format(shot_no))\n", " \n", "else:\n", " fig, axs = plt.subplots(3, 1, sharex=True, dpi=200)\n", " r.plot(grid=True, ax=axs[0])\n", " z.plot(grid=True, ax=axs[1])\n", " a.plot(grid=True, ax=axs[2])\n", " axs[2].set(ylim=(0,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$a$ [mm]')\n", " axs[1].set(ylim=(-85,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$\\Delta$z [mm]')\n", " axs[0].set(ylim=(-85,85), xlim=(start,end), xlabel= 'Time [ms]', ylabel = '$\\Delta$r [mm]', \n", " title = 'Horizontal, vertical plasma position and radius #{}'.format(shot_no))\n", " \n", "plt.savefig('icon-fig') \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plasma position during discharge" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tms = np.arange(np.round(start),np.round(end)-1,1)\n", "\n", "circle1 = plt.Circle((0, 0), 100, color='black', fill = False, lw = 5)\n", "circle2 = plt.Circle((0, 0), 85, color='black', fill = False, lw = 3)\n", "\n", "fig, ax = plt.subplots(figsize = (10,10)) \n", "ax.axvline(x=0, color = 'black', alpha = 0.5)\n", "ax.axhline(y=0, color = 'black', alpha = 0.5)\n", "\n", "ax.set_xlim(-100,100)\n", "ax.set_ylim(-100,100)\n", "ax.add_patch(circle1)\n", "ax.add_patch(circle2)\n", "plt.annotate('vessel',xy=(27-100, 170-100), xytext=(2-100, 190-100),\n", " arrowprops=dict(facecolor='black', shrink=0.05), fontsize = 12)\n", "plt.annotate('limiter',xy=(175-100, 140-100), xytext=(170-100, 190-100),\n", " arrowprops=dict(facecolor='black', shrink=0.05), fontsize = 12)\n", "\n", "color_idx = np.linspace(0, 1, tms.size)\n", "a = 0\n", "for i in tms:\n", " mask_pos = ((df_processed.index>i) & (df_processed.index