{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#Basic setup \n",
"from __future__ import print_function\n",
"import matplotlib\n",
"matplotlib.use('Agg')\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from urllib.request import urlopen\n",
"import os\n",
"from IPython import get_ipython\n",
"import string\n",
"import sys\n",
"from pylab import *\n",
"from scipy.signal import argrelextrema\n",
"import scipy.optimize as spo\n",
"from scipy.optimize import fsolve\n",
"from numpy import nan\n",
"from numpy import math\n",
"\n",
"def is_interactive_(): # are we in jupyter ??\n",
" import __main__ as main\n",
" return not hasattr(main, '__file__')\n",
"\n",
"def is_interactive(): # are we in jupyter ??\n",
" import __main__ as main\n",
" return 0 \n",
"\n",
"\n",
"if is_interactive():\n",
" %matplotlib inline\n",
"\n",
"BaseURL = \"http://golem.fjfi.cvut.cz/utils/data/\" #global\n",
"\n",
"R_BPP=200 # Ohm\n",
"R_BPP_LP=23 # Ohm\n",
"\n",
"\n",
"Date='130717'\n",
"MainMission='BPP & BPP_LP $U_{bias}$ scan'\n",
"Comment='BPP used to measure $I^{BPP}$ current, BPP_LP used to measure $I^{BPP\\_LP}$ current'\n",
"OtherKeyParams='BPP probe distance from plasma centre $r_{BPP\\_LP}=70$ mm,'+'$R_{BPP}='+str(R_BPP)+' \\Omega$'+'$R_{BPP\\_LP}='+str(R_BPP_LP)+' \\Omega$'\n",
"SmoothCoefficient=100\n",
"CurrentScale=1000 # so .. mA\n",
"\n",
"#DASsetup: (Ne, osciloskop nejeden na 1 us, musime to obejit)\n",
"RecordLength=10000\n",
"TektronixDataAnalysisStart=1000\n",
"TektronixDataAnalysisEnd=7000\n",
"TektronixDataAnalysisStep=500\n",
"TimeCalibShift=4000\n",
"TimeCalibScale=4\n",
"\n",
"FigSize=10,8\n",
"def FigDef():plt.figure(figsize=(10, 8), dpi= 80, facecolor='w', edgecolor='k')\n",
"\n",
"\n",
"SignalIdents=[\\\n",
" ['U@R_bpp','$U@R_{BPP}$'],\\\n",
" ['U@R_bpp_lp','$U@R_{BPP\\_LP}$'],\\\n",
" ]\n",
"KeyParameter=['Biasing voltage','$U_{bias}$','V']\n",
"\n",
"Setup=[\\\n",
" [24411,0,'o'],\\\n",
" [24412,13,'o'],\\\n",
" ]\n",
"\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def running_mean(l, N):\n",
" # Also works for the(strictly invalid) cases when N is even.\n",
" if (N//2)*2 == N:\n",
" N = N - 1\n",
" front = np.zeros(N//2)\n",
" back = np.zeros(N//2)\n",
" for i in range(1, (N//2)*2, 2):\n",
" front[i//2] = np.convolve(l[:i], np.ones((i,))/i, mode = 'valid')\n",
" for i in range(1, (N//2)*2, 2):\n",
" back[i//2] = np.convolve(l[-i:], np.ones((i,))/i, mode = 'valid')\n",
" return np.concatenate([front, np.convolve(l, np.ones((N,))/N, mode = 'valid'), back[::-1]])\n",
"\n",
"\n",
"def running_means(data, odkud, kam, krok):\n",
" \n",
" Means = [None] * int((kam-odkud)/krok)\n",
" for i in range(0,kam-odkud,krok):\n",
" Suma=0\n",
" for j in range(0,krok):\n",
" Suma=Suma+data[i+j]\n",
" Means[int(i/krok)] = [odkud+i+krok/2,Suma/(krok)]\n",
" return(Means)\n",
" \n",
"\n",
"def mkdir(dir): \n",
" try:os.makedirs(dir) \n",
" except OSError:pass\n",
" \n",
"\n",
"\n",
"def GetData(ShotNo):\n",
" ShotNoStr=str(ShotNo)\n",
" if os.path.isdir(ShotNoStr+'/Basics'): return\n",
" print('Getting ..'+ShotNoStr+'/Basics')\n",
" mkdir(ShotNoStr)\n",
" mkdir(ShotNoStr+'/Basics')\n",
" \n",
" os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Btoroidal.npz -O '+ShotNoStr+'/Basics/Btoroidal.npz');\n",
" os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Iplasma.npz -O '+ShotNoStr+'/Basics/Iplasma.npz');\n",
" os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Uloop.npz -O '+ShotNoStr+'/Basics/Uloop.npz');\n",
" os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/graphpres.png -O '+ShotNoStr+'/Basics/graphres.png');\n",
" #Plasma parameters \n",
" PlasmaStart=int(float(np.loadtxt(urlopen(BaseURL+ShotNoStr+'/plasma_start')))*1e6) # in us\n",
" PlasmaEnd=int(float(np.loadtxt(urlopen(BaseURL+ShotNoStr+'/plasma_end')))*1e6) # in us\n",
" np.savetxt(ShotNoStr+'/Basics/PlasmaStart',[PlasmaStart], delimiter=\" \", fmt=\"%s\")\n",
" np.savetxt(ShotNoStr+'/Basics/PlasmaEnd',[PlasmaEnd], delimiter=\" \", fmt=\"%s\")\n",
" np.savetxt(ShotNoStr+'/Basics/TektronixDataAnalysisStart',[TektronixDataAnalysisStart], delimiter=\" \", fmt=\"%s\")\n",
" np.savetxt(ShotNoStr+'/Basics/TektronixDataAnalysisEnd',[TektronixDataAnalysisEnd], delimiter=\" \", fmt=\"%s\")\n",
"\n",
"\n",
" for signal in SignalIdents:\n",
" os.system('wget '+BaseURL + ShotNoStr + '/' + signal[0] + ' -O '+ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt');\n",
" \n",
"\n",
" \n",
" \n",
"def DischargeBasics(ShotNo):\n",
" \n",
" PlasmaParameters=PlasmaParametersDef(ShotNo)\n",
" PlasmaStart=PlasmaParameters[0]\n",
" PlasmaEnd=PlasmaParameters[1]\n",
" ShotNoStr=str(ShotNo)\n",
"\n",
" \n",
" Time = np.linspace(PlasmaStart,PlasmaEnd,(PlasmaEnd-PlasmaStart))\n",
" TimeTektronix = np.linspace(TektronixDataAnalysisStart,TektronixDataAnalysisEnd,(TektronixDataAnalysisEnd-TektronixDataAnalysisStart))\n",
"\n",
" #rint(Time);print(TimeTektronix)\n",
" \n",
" Btoroidal=np.load(ShotNoStr+'/Basics/Btoroidal.npz');\n",
" Iplasma=np.load(ShotNoStr+'/Basics/Iplasma.npz');\n",
" Uloop=np.load(ShotNoStr+'/Basics/Uloop.npz');\n",
" \n",
" f = plt.figure(figsize=(20.0, 5.0))\n",
" f,ax = plt.subplots(5,sharex=True);plt.subplots_adjust(hspace=0.001)\n",
" f.set_size_inches(FigSize)\n",
" ax[0].set_title('#' + str(ShotNo))\n",
" ax[0].plot(Time/1000,Uloop['data'][PlasmaStart:PlasmaEnd],label='Loop voltage');ax[0].set_ylabel('$U_l$ [V]');ax[0].set_ylim(0,);ax[0].legend(loc=0)\n",
" ax[1].plot(Time/1000,Btoroidal['data'][PlasmaStart:PlasmaEnd],label='Toroidal magnetic field');ax[1].set_ylabel('$B_t$ [T]');ax[1].set_ylim(0,);ax[1].legend(loc=0)\n",
" ax[2].plot(Time/1000,Iplasma['data'][PlasmaStart:PlasmaEnd]/1000,label='Plasma current');ax[2].set_ylabel('$I_p$ [kA]');ax[2].set_ylim(0,);ax[2].legend(loc=0)\n",
" graphindx=3\n",
" for signal in SignalIdents:\n",
" PlasmaSignal=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt')[TektronixDataAnalysisStart:TektronixDataAnalysisEnd]\n",
" ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignal[0:,1],label=signal[1],color='blue');ax[graphindx].legend(loc=0)\n",
" PlasmaSignalSmoothed=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_smoothed.txt')\n",
" ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignalSmoothed*0,label='0',color='green')\n",
" ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignalSmoothed,label='smoothed',color='red')\n",
" PlasmaSignalMeans=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_mean.txt')\n",
" ax[graphindx].plot((PlasmaSignalMeans[:,0]*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignalMeans[:,1],label='discrete',color='y',marker='*',linestyle='');ax[graphindx].set_ylabel(signal[1]);ax[graphindx].legend(loc=1)\n",
" graphindx=graphindx+1\n",
" ax[graphindx-1].set_xlabel('$t$ [ms]');#ax[6].set_ylim(-200,200)\n",
" ax[graphindx-1].set_xlim(PlasmaStart/1000,PlasmaEnd/1000)\n",
" plt.savefig(str(ShotNo)+'/Basics/BasicDiagWithSignals.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close();\n",
" \n",
" \n",
"\n",
" \n",
"def htmlgeneration(ShotNo,UBt,PlasmaStart, PlasmaEnd, Time):\n",
" print(\"html generation ...\")\n",
" ShotNoStr=str(ShotNo)\n",
"\n",
" os.system('rm '+str(ShotNo)+'/index.html');\n",
" fileid = open(str(ShotNo)+'/index.html','a+')\n",
" fileid.write('
VA char @ GOLEM\\\n",
" \\\n",
" \\\n",
" \\\n",
" \\\n",
" \\\n",
" ')\n",
" fileid.write('')\n",
" fileid.write('BPP experiments @ the tokamak GOLEM
')\n",
" fileid.write('Essential parameters:
\\\n",
" - Voltage divider: 1:'+str(HWNapetovyDelic)+'
\\\n",
" - The shot: '+ShotNoStr+'
\\\n",
" - The DAS used: Papouch_St
\\\n",
" |
')\n",
" fileid.write('Experimental setup
')\n",
" fileid.write('
Ball pen probe @ North-East port
')\n",
" fileid.write('
\\\n",
" \\\n",
"
\\\n",
" setup ')\n",
" fileid.write('\\\n",
" The BPP data vs diagnostics
\\\n",
"
\\\n",
" Reference shot data
')\n",
" \n",
" fileid.write('')\n",
" fileid.close()\n",
" \n",
"\n",
" \n",
"def Initials(ShotNo):\n",
" ShotNoStr=str(ShotNo)\n",
" \n",
" \n",
"def PlasmaParametersDef(ShotNo):\n",
" return [\\\n",
" int(np.loadtxt(str(ShotNo)+'/Basics/PlasmaStart')),\\\n",
" int(np.loadtxt(str(ShotNo)+'/Basics/PlasmaEnd'))\\\n",
" ]\n",
" \n",
"\n",
" \n",
" \n",
"def IndividualShot(IndvSetup):\n",
" ShotNo=IndvSetup[0];print( 'Doing', ShotNo)\n",
" ShotNoStr=str(ShotNo)\n",
" Initials(ShotNo)\n",
" PlasmaParameters=PlasmaParametersDef(ShotNo)\n",
" PlasmaStart=PlasmaParameters[0]\n",
" PlasmaEnd=PlasmaParameters[1]\n",
" \n",
" \n",
" for signal in SignalIdents:\n",
" PlasmaSignal=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt')[TektronixDataAnalysisStart:TektronixDataAnalysisEnd]\n",
" np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma.txt',PlasmaSignal, delimiter=\" \", fmt=\"%s\")\n",
" PlasmaSignalSmoothed=running_mean(PlasmaSignal[:,1],SmoothCoefficient)\n",
" np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_smoothed.txt',PlasmaSignalSmoothed, delimiter=\" \", fmt=\"%s\")\n",
" PlasmaSignalMean=running_means(PlasmaSignal[:,1],TektronixDataAnalysisStart,TektronixDataAnalysisEnd, TektronixDataAnalysisStep)\n",
" np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_mean.txt',PlasmaSignalMean, delimiter=\" \", fmt=\"%s\")\n",
" \n",
"\n",
" \n",
" DischargeBasics(ShotNo)\n",
" #htmlgeneration(ShotNo,1300,PlasmaStart, PlasmaEnd, Time)\n",
" \n",
"\n",
"\n",
"def GlobalFigs():\n",
" mkdir('GlobalFigs')\n",
" Time = np.linspace(0,40000,40000)\n",
" \n",
"\n",
" for graph in GraphSetup:\n",
" FigDef()\n",
" for shot in LoopSetup:\n",
" data=np.load(str(shot[0])+'/Basics/'+graph[0]+'.npz')\n",
" plt.plot(Time/1000,data['data'],label='#'+str(shot[0])+' ('+ KeyParameter[1]+'='+str(shot[1])+ KeyParameter[2]+')');\n",
" plt.legend(loc=0)\n",
" plt.title('Reproducibility for: '+graph[2])\n",
" plt.xlabel('$t$ [ms]')\n",
" plt.ylabel(graph[1])\n",
" plt.savefig('GlobalFigs/Reproducibility_'+graph[0]+'.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" \n",
" \n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# HTML generation\n",
"def HtmlGeneration():\n",
" print(\"Global html generation ...\")\n",
"\n",
" os.system('rm index.html');\n",
" fileid = open('index.html','a+')\n",
" fileid.write('VA char @ GOLEM\\\n",
" \\\n",
" \\\n",
" \\\n",
" \\\n",
" \\\n",
" ')\n",
" fileid.write('BPP experiments @ the tokamak GOLEM 2016,2017
')\n",
" fileid.write('Essential parameters:
\\\n",
" - Main mission:'+MainMission+'
\\\n",
" - Date:'+Date+'
\\\n",
" - '+Comment+'
\\\n",
" - '+OtherKeyParams+'
\\\n",
" |
')\n",
" fileid.write('Experimental setup
')\n",
" fileid.write('
Ball pen probe @ North-East port
')\n",
" fileid.write('
\\\n",
" \\\n",
"
\\\n",
" Experimental setup \\\n",
" Discharges involved
\\\n",
" \\\n",
" Discharge # | \\\n",
" '+KeyParameter[1]+'['+ KeyParameter[2]+'] | \\\n",
" Data |
')\n",
" for shot in LoopSetup: \n",
" fileid.write('\\\n",
" #'+str(shot[0])+' | \\\n",
" '+str(shot[1])+' | \\\n",
" link | \\\n",
"
')\n",
" for shot in LoopSetup: \n",
" fileid.write('
#'+str(shot[0])+','+ KeyParameter[1] +'='+str(shot[1])+ KeyParameter[2]+'
\\\n",
"
\\\n",
" ') \n",
" fileid.write('Reproducibility
')\n",
" for graph in GraphSetup:\n",
" fileid.write('')\n",
" fileid.write('Experimental photo
')\n",
" fileid.write('')\n",
" fileid.write('Experiment specific data
\\\n",
" \\\n",
" Discharge # | \\\n",
" '+KeyParameter[1]+'['+ KeyParameter[2]+'] | \\\n",
" Data directory | \\\n",
" Raw BPP_LP data | \\\n",
" Smoothed BPP_LP data | \\\n",
" Raw BPP data | \\\n",
" Smoothed BPP data | \\\n",
"
')\n",
" for shot in LoopSetup: \n",
" fileid.write('\\\n",
" #'+str(shot[0])+' | \\\n",
" '+str(shot[1])+' | \\\n",
" link | \\\n",
" link | \\\n",
" link | \\\n",
" link | \\\n",
" link | \\\n",
"
')\n",
" fileid.write('')\n",
" fileid.close()\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[24411, 0, 'o']\n",
"Getting ..24411/Basics\n",
"Doing 24411\n",
"[24412, 13, 'o']\n",
"Getting ..24412/Basics\n",
"Doing 24412\n",
"Global html generation ...\n",
"Hotovo\n"
]
}
],
"source": [
"\n",
"\n",
"GraphSetup=[['Iplasma','$I_{pl}$ [kA]','$I_p$'],['Uloop',\"$U_{l}$ [V]\",'$U_l$'],['Btoroidal','$B_t$ [T]','$B_t$']]\n",
"\n",
"\n",
"#LoopSetup=Setup[0:1]\n",
"LoopSetup=Setup[0:2]\n",
"\n",
"for shot in LoopSetup:\n",
" print(shot);\n",
" GetData(shot[0])\n",
" IndividualShot(shot) \n",
"\n",
"#GlobalFigs() \n",
"HtmlGeneration()\n",
"print('Hotovo')\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Global html generation ...\n"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}