#!/usr/bin/env python
# coding: utf-8

# # Python3: Plotting of GOLEM $U_\mathrm{loop}$ signal
# 
# ## Python3 source code
# - as Jupyter notebook: [Uloop.ipynb](./Uloop.ipynb)
# - as Python3 script (exported from this notebook): [Uloop.py](./Uloop.py)
# 
# ## Result (in Jupyter notebook format)
# Loading of basic libraries.
# The `matplotlib` library is used for plotting, the `pandas` library for data retrieval and manipulation. 

# In[ ]:


# Basic libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


# The parametrized URL address to obtain CSV files from the analysis results of the basic diagnostics

# In[ ]:


data_URL = 'http://golem.fjfi.cvut.cz/shots/{shot_no}/Diagnostics/BasicDiagnostics/Results/{name}.csv'


# Discharge number to use. The special discharge number 0 refers to the most recent discharge

# In[ ]:


shot_no = 44425


# 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.

# In[ ]:


U_loop = pd.read_csv(data_URL.format(shot_no=shot_no, name='U_loop'),  # create a specific URL
                     names=['time', 'U_loop'], # names of the columns
                     index_col=0,  # first column will serve as index (independent variable) 
                     squeeze=True, # return as Series since there is only 1 dependent variable column
                    )


# 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.

# In[ ]:


ax = U_loop.plot()
ax.set(title="GOLEM #{}".format(shot_no), xlabel='time [ms]', ylabel=r'$U_\mathrm{loop}$ [V]')
plt.savefig('plot.jpg')

