{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python3: Plotting of GOLEM $U_\\mathrm{loop}$ signal\n", "\n", "## Python3 source code\n", "- as Jupyter notebook: [Uloop.ipynb](./Uloop.ipynb)\n", "- as Python3 script (exported from this notebook): [Uloop.py](./Uloop.py)\n", "\n", "## Result (in Jupyter notebook format)\n", "Loading of basic libraries.\n", "The `matplotlib` library is used for plotting, the `pandas` library for data retrieval and manipulation. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Basic libraries\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The parametrized URL address to obtain CSV files from the analysis results of the basic diagnostics" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data_URL = 'http://golem.fjfi.cvut.cz/shots/{shot_no}/Diagnostics/BasicDiagnostics/Results/{name}.csv'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Discharge number to use. The special discharge number 0 refers to the most recent discharge" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "shot_no = 39617" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The processed loop voltage signal $U_\\mathrm{loop}$ is automatically downloaded and read using the Pandas library into a `pandas.Series` object from the specified URL." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "U_loop = pd.read_csv(data_URL.format(shot_no=shot_no, name='U_loop'), # create a specific URL\n", " names=['time', 'U_loop'], # names of the columns\n", " index_col=0, # first column will serve as index (independent variable) \n", " squeeze=True, # return as Series since there is only 1 dependent variable column\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `.plot()` wrapper method for plotting with the `matplotlib` library automatically selects the x and y values and the plot type (line for 1D). It returns an `Axes` object, which is then used to label the axes and set a title." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ax = U_loop.plot()\n", "ax.set(title=\"GOLEM #{}\".format(shot_no), xlabel='time [ms]', ylabel=r'$U_\\mathrm{loop}$ [V]')\n", "plt.savefig('plot.jpg')" ] } ], "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.4.3" } }, "nbformat": 4, "nbformat_minor": 4 }