{ "cells": [ { "cell_type": "markdown", "id": "ac7ff5f0", "metadata": {}, "source": [ "# Analysis of DRP signals, analysing transport\n", "\n", "The following script shows the basic data aquision from **D**ouble **R**ake **P**robe\n", "\n", "To get more detailed information about **D**ouble **R**ake **P**robe visit its [wikipage](http://golem.fjfi.cvut.cz/wiki/Diagnostics/ParticleFlux/DoubleRakeProbe/index).\n", "\n", "DRP consists of two rakes of Langmuir probes that can be operated in two basic modes. \n", "The first one is floating potential mode ($V_\\mathrm{float}$), where each pin is insulated \n", "and we can measure an approximation of plasma potential. \n", "\n", "The other mode is ion saturation current ($I_\\mathrm{sat}$), where -100 V voltage is \n", "applied to each pin. This voltage repels electrons so one can measure the plasma density.\n", "\n", "To measure transport using DRP one has to measure 4 floating potential ($V_\\mathrm{fl}$) \n", "signals and 2 ion saturation current ($I_\\mathrm{sat}$) signals, however, quality $I_\\mathrm{sat}$ \n", "measurements may turn out to be challenging to perform, so in the following \n", "script, only $V_\\mathrm{float}$ measurements are considered." ] }, { "cell_type": "markdown", "id": "e1806b5b", "metadata": {}, "source": [ "### Needed Python modules" ] }, { "cell_type": "code", "execution_count": null, "id": "bf34bef6", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import xarray as xr\n", "\n", "# to keep the attributes\n", "xr.set_options(keep_attrs=True)\n", "\n", "# the data is downloaded in the directory/folder\n", "# from where this script was started \n", "ds = np.DataSource()\n", "\n", "#interactive inline plots\n", "%matplotlib notebook " ] }, { "cell_type": "markdown", "id": "9f681704", "metadata": {}, "source": [ "## Download (and save the data)\n", "One might need to modify `ulr_base` variable in `download_data` function and `channel_list`.\n", "\n", "\n", "The correct `url_base` depends on the DAS used and the `channel_list` \n", "represents the names of particular signals. \n", "It is recommended to save the data to your computer if runnig the scipts locally, \n", "as it saves time and makes your analysis independent on internet connection.\n", "\n", "Eventually the data is converted into xarray.DataArray structure for convenience." ] }, { "cell_type": "code", "execution_count": null, "id": "fca57b87", "metadata": {}, "outputs": [], "source": [ "# list of channel names in the database\n", "channel_list = ['DRP-R1', 'DRP-R2','DRP-R3','DRP-R4','DRP-R5','DRP-R6',\n", " 'DRP-L1', 'DRP-L2' ,'DRP-L3' ,'DRP-L4' ,'DRP-L5','DRP-L6']\n", "\n", "# shot is set to 0\n", "# i.e. the last shot\n", "# attention! when running the script locally\n", "# leaving the 0 will not upda\n", "\n", "shot_no = 0 \n", "\n", "# test shot_no\n", "# shot_no = 36443\n", "# test channel_list\n", "# channel_list = ['DRP-R1', 'DRP-R2','DRP-R3','DRP-R4','DRP-R5','DRP-R6',\n", "# 'DRP-L1', 'DRP-L2' ,'DRP-L3' ,'DRP-L4' ,'DRP-L5']\n", "# test url_base\n", "# \"http://golem.fjfi.cvut.cz/shots/{}/Diagnostics/DoubleRakeProbe/\".format(shot_no)\n", "\n", "def download_data(shot_no, channel_list):\n", " \"\"\"Downloads the data and returns a tuple\n", " of time numpy.ndarray and data numpy.ndarray\"\"\"\n", " url_base = \"http://golem.fjfi.cvut.cz/shots/{}/Diagnostics/DoubleRakeProbe/\".format(shot_no)\n", " data_all = np.ones(shape=(40960,len(channel_list)))\n", " i = 0\n", "\n", " for channel in channel_list:\n", " # open the file\n", " file = ds.open(url_base+\"{}.csv\".format(channel))\n", " # transform to numpy format\n", " np_file = np.loadtxt(file, delimiter=',')\n", " # add to the complete array\n", " data_all[:,i] = np_file[:,1]\n", " # saves the time from the diag. output\n", " if i == 0:\n", " time = np_file[:,0] * 10e2 # to have time in ms\n", " i += 1\n", " \n", " # the 10e2 coefficient is given by a voltage divider\n", " return time, data_all * 10e2\n", "\n", "time, data = download_data(shot_no,channel_list)\n", "# creation of xarray.DataArray\n", "# it is with offset\n", "data_all_off = xr.DataArray(data,\n", " coords={'time':time,\n", " 'signal':channel_list},\n", " dims=['time','signal']\n", "# attrs = {'shot_no':}\n", " )" ] }, { "cell_type": "markdown", "id": "6fe47eed", "metadata": {}, "source": [ "### Download the time of the plasma start and the end" ] }, { "cell_type": "code", "execution_count": null, "id": "0dca31d0", "metadata": {}, "outputs": [], "source": [ "# a little helper function\n", "def strip_off_data(base_url,data_name):\n", " url = base_url + data_name\n", " file = ds.open(url)\n", " data = np.loadtxt(file)\n", " return data\n", "\n", "def get_plasma_start_end(shot_no):\n", " # the following should not change, except the shot_no\n", " base_url = \"http://golem.fjfi.cvut.cz/shots/{}/Diagnostics/BasicDiagnostics/Results/\".format(shot_no)\n", " \n", " # check whether there was plasma\n", " # and if yes, get the plasma start and end\n", " is_plasma = strip_off_data(base_url,\"is_plasma\")\n", " \n", " if is_plasma == 1.0:\n", " t_start = strip_off_data(base_url,\"t_plasma_start\")\n", " t_end = strip_off_data(base_url,\"t_plasma_end\")\n", " else:\n", " raise RuntimeError(\"There was no plasma.\")\n", " return t_start, t_end\n", "\n", "# add the plasma start and end as a attribute of \n", "# all_data xarray.DataArray\n", "t_start, t_end = get_plasma_start_end(shot_no)\n", "\n", "data_all_off.attrs = {\"plasma_start\":t_start, \"plasma_end\":t_end}" ] }, { "cell_type": "markdown", "id": "dbcfc3e5", "metadata": {}, "source": [ "### Substraction of offset " ] }, { "cell_type": "code", "execution_count": null, "id": "d274c1a9", "metadata": {}, "outputs": [], "source": [ "# time window of period before the plasma start\n", "# where we calculate the offset, that we substract\n", "time_off = slice(data_all_off.attrs['plasma_start']-2.5,data_all_off.attrs['plasma_start']-1)\n", "\n", "# all the downloaded data without offset\n", "data_all = data_all_off - data_all_off.sel(time=time_off).mean(dim='time')" ] }, { "cell_type": "markdown", "id": "34e66573", "metadata": {}, "source": [ "### Visual check of the signals " ] }, { "cell_type": "code", "execution_count": null, "id": "c08efd46", "metadata": { "scrolled": false }, "outputs": [], "source": [ "time_window = slice(data_all.attrs['plasma_start']-0.5,data_all.attrs['plasma_end']+1)\n", "# the following list just to sort the pin coordinates such that\n", "# it is shown as it is physically in the vessel\n", "signal_order = ['DRP-R1', 'DRP-L1','DRP-R2','DRP-L2','DRP-R3','DRP-L3',\n", " 'DRP-R4', 'DRP-L4' ,'DRP-R5' ,'DRP-L5' ,'DRP-R6', 'DRP-L6']\n", "\n", "# here the part, where the plasma is is selected\n", "sel_plasma = data_all.sel(time=time_window,signal=signal_order)\n", "\n", "# plot and plot setup\n", "all_plot = sel_plasma.plot.line(x=\"time\", col='signal', col_wrap=2,\n", " figsize=(9,9),\n", "# subplot_kws={'gridspec_kw:{'wspace':0.1}}\n", " )\n", "\n", "fontsize = 13\n", "# axes labels\n", "all_plot.set_xlabels('time [ms]',fontsize=fontsize)\n", "all_plot.set_ylabels('$V_\\mathrm{float}$ [V]',fontsize=fontsize)\n", "\n", "# make the figure nicer\n", "plt.tight_layout()\n", "\n", "# save the figure\n", "\n", "plt.savefig('icon_fig.png')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.12" } }, "nbformat": 4, "nbformat_minor": 5 }