def running_mean(l, N):
# Also works for the(strictly invalid) cases when N is even.
if (N//2)*2 == N:
N = N - 1
front = np.zeros(N//2)
back = np.zeros(N//2)
for i in range(1, (N//2)*2, 2):
front[i//2] = np.convolve(l[:i], np.ones((i,))/i, mode = 'valid')
for i in range(1, (N//2)*2, 2):
back[i//2] = np.convolve(l[-i:], np.ones((i,))/i, mode = 'valid')
return np.concatenate([front, np.convolve(l, np.ones((N,))/N, mode = 'valid'), back[::-1]])
def running_means(data, odkud, kam, krok):
Means = [None] * int((kam-odkud)/krok)
for i in range(0,kam-odkud,krok):
Suma=0
for j in range(0,krok):
Suma=Suma+data[i+j]
Means[int(i/krok)] = [odkud+i+krok/2,Suma/(krok)]
return(Means)
def mkdir(dir):
try:os.makedirs(dir)
except OSError:pass
def GetData(ShotNo):
ShotNoStr=str(ShotNo)
if os.path.isdir(ShotNoStr+'/Basics'): return
print('Getting ..'+ShotNoStr+'/Basics')
mkdir(ShotNoStr)
mkdir(ShotNoStr+'/Basics')
os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Btoroidal.npz -O '+ShotNoStr+'/Basics/Btoroidal.npz');
os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Iplasma.npz -O '+ShotNoStr+'/Basics/Iplasma.npz');
os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/Uloop.npz -O '+ShotNoStr+'/Basics/Uloop.npz');
os.system('wget http://golem.fjfi.cvut.cz/shots/' + ShotNoStr + '/basicdiagn/graphpres.png -O '+ShotNoStr+'/Basics/graphres.png');
#Plasma parameters
PlasmaStart=int(float(np.loadtxt(urlopen(BaseURL+ShotNoStr+'/plasma_start')))*1e6) # in us
PlasmaEnd=int(float(np.loadtxt(urlopen(BaseURL+ShotNoStr+'/plasma_end')))*1e6) # in us
np.savetxt(ShotNoStr+'/Basics/PlasmaStart',[PlasmaStart], delimiter=" ", fmt="%s")
np.savetxt(ShotNoStr+'/Basics/PlasmaEnd',[PlasmaEnd], delimiter=" ", fmt="%s")
np.savetxt(ShotNoStr+'/Basics/TektronixDataAnalysisStart',[TektronixDataAnalysisStart], delimiter=" ", fmt="%s")
np.savetxt(ShotNoStr+'/Basics/TektronixDataAnalysisEnd',[TektronixDataAnalysisEnd], delimiter=" ", fmt="%s")
for signal in SignalIdents:
os.system('wget '+BaseURL + ShotNoStr + '/' + signal[0] + ' -O '+ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt');
def DischargeBasics(ShotNo):
PlasmaParameters=PlasmaParametersDef(ShotNo)
PlasmaStart=PlasmaParameters[0]
PlasmaEnd=PlasmaParameters[1]
ShotNoStr=str(ShotNo)
Time = np.linspace(PlasmaStart,PlasmaEnd,(PlasmaEnd-PlasmaStart))
TimeTektronix = np.linspace(TektronixDataAnalysisStart,TektronixDataAnalysisEnd,(TektronixDataAnalysisEnd-TektronixDataAnalysisStart))
#rint(Time);print(TimeTektronix)
Btoroidal=np.load(ShotNoStr+'/Basics/Btoroidal.npz');
Iplasma=np.load(ShotNoStr+'/Basics/Iplasma.npz');
Uloop=np.load(ShotNoStr+'/Basics/Uloop.npz');
f = plt.figure(figsize=(20.0, 5.0))
f,ax = plt.subplots(5,sharex=True);plt.subplots_adjust(hspace=0.001)
f.set_size_inches(FigSize)
ax[0].set_title('#' + str(ShotNo))
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)
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)
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)
graphindx=3
for signal in SignalIdents:
PlasmaSignal=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt')[TektronixDataAnalysisStart:TektronixDataAnalysisEnd]
ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignal[0:,1],label=signal[1],color='blue');ax[graphindx].legend(loc=0)
PlasmaSignalSmoothed=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_smoothed.txt')
ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignalSmoothed*0,label='0',color='green')
ax[graphindx].plot((TimeTektronix*TimeCalibScale+TimeCalibShift)/1000,PlasmaSignalSmoothed,label='smoothed',color='red')
PlasmaSignalMeans=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_mean.txt')
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)
graphindx=graphindx+1
ax[graphindx-1].set_xlabel('$t$ [ms]');#ax[6].set_ylim(-200,200)
ax[graphindx-1].set_xlim(PlasmaStart/1000,PlasmaEnd/1000)
plt.savefig(str(ShotNo)+'/Basics/BasicDiagWithSignals.jpg', bbox_inches='tight')
if is_interactive():plt.show();
plt.close();
def htmlgeneration(ShotNo,UBt,PlasmaStart, PlasmaEnd, Time):
print("html generation ...")
ShotNoStr=str(ShotNo)
os.system('rm '+str(ShotNo)+'/index.html');
fileid = open(str(ShotNo)+'/index.html','a+')
fileid.write('<html><head><title>VA char @ GOLEM</title>\
<style>\
div.grafy30 {display:inline-block;width: 30%;}\
div.grafy20 {display:inline-block;width: 20%;}\
.grafy20 img {width: 100%;}\
.grafy30 img {width: 100%;}\
</style>\
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\
<style></style>\
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [[\'$\',\'$\'], [\'\\(\',\'\\)\']]}});</script>\
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>\
</head><body><center>')
fileid.write('<h2><a href="../index.html">Home</a></h2>')
fileid.write('<h1>BPP experiments @ the tokamak GOLEM</h1>')
fileid.write('<h3>Essential parameters:</h3><table><tr><td><ul>\
<li>Voltage divider: 1:'+str(HWNapetovyDelic)+'</li>\
<li>The shot: <a href="http://golem.fjfi.cvut.cz/shots/'+ShotNoStr+'">'+ShotNoStr+'</a></li>\
<li>The DAS used: <a href="http://golem.fjfi.cvut.cz/shots/'+ShotNoStr+'/DAS/1011Papouch_St.ON/">Papouch_St</a></li>\
</ul></td></tr></table>')
fileid.write('<div class="grafy30"><h2>Experimental setup</h2>')
fileid.write('<h3>Ball pen probe @ North-East port</h3>')
fileid.write('<center>\
<a href="http://golem.fjfi.cvut.cz/wikiraw/Experiments/EdgePlasmaPhysics/ParticleFlux/BallPenProbe/Experiments/BottomPosition/setup/vI/ExpSetup-BPP.png">\
<img src="../setup/ExpSetup-BPP.png" width="100%"></a><br>\
<a href="/wikiraw/Experiments/EdgePlasmaPhysics/ParticleFlux/BallPenProbe/Experiments/BottomPosition/setup/">setup</a></div>')
fileid.write('<div class="grafy30"><h2>The discharge #'+ShotNoStr+'</h2>')
fileid.write('<h3>Basic diagnostics</h3>\
<a href="http://golem.fjfi.cvut.cz/shots/'+ShotNoStr+'/"><img src="Basics/graphres.png" width="100%"></a><br/>\
Plasma start:<a href="ShotNo/PlasmaStart">'+str(PlasmaStart)+'</a> us\
Plasma end:<a href="ShotNo/PlasmaEnd">'+str(PlasmaEnd)+'</a> us</div>\
<h3>The BPP data vs diagnostics</h3>\
<a href="Basics/BasicDiagWithBPP.jpg"><img src="Basics/BasicDiagWithBPP.jpg" width="30%"></a><br/>\
<a href="ShotNo/">Reference shot data</a><br/></div>')
fileid.write('</body></html>')
fileid.close()
def Initials(ShotNo):
ShotNoStr=str(ShotNo)
def PlasmaParametersDef(ShotNo):
return [\
int(np.loadtxt(str(ShotNo)+'/Basics/PlasmaStart')),\
int(np.loadtxt(str(ShotNo)+'/Basics/PlasmaEnd'))\
]
def IndividualShot(IndvSetup):
ShotNo=IndvSetup[0];print( 'Doing', ShotNo)
ShotNoStr=str(ShotNo)
Initials(ShotNo)
PlasmaParameters=PlasmaParametersDef(ShotNo)
PlasmaStart=PlasmaParameters[0]
PlasmaEnd=PlasmaParameters[1]
for signal in SignalIdents:
PlasmaSignal=np.loadtxt(ShotNoStr+'/Basics/'+signal[0]+'4WholeTime.txt')[TektronixDataAnalysisStart:TektronixDataAnalysisEnd]
np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma.txt',PlasmaSignal, delimiter=" ", fmt="%s")
PlasmaSignalSmoothed=running_mean(PlasmaSignal[:,1],SmoothCoefficient)
np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_smoothed.txt',PlasmaSignalSmoothed, delimiter=" ", fmt="%s")
PlasmaSignalMean=running_means(PlasmaSignal[:,1],TektronixDataAnalysisStart,TektronixDataAnalysisEnd, TektronixDataAnalysisStep)
np.savetxt(ShotNoStr+'/Basics/'+signal[0]+'@plasma_mean.txt',PlasmaSignalMean, delimiter=" ", fmt="%s")
DischargeBasics(ShotNo)
#htmlgeneration(ShotNo,1300,PlasmaStart, PlasmaEnd, Time)
def GlobalFigs():
mkdir('GlobalFigs')
Time = np.linspace(0,40000,40000)
for graph in GraphSetup:
FigDef()
for shot in LoopSetup:
data=np.load(str(shot[0])+'/Basics/'+graph[0]+'.npz')
plt.plot(Time/1000,data['data'],label='#'+str(shot[0])+' ('+ KeyParameter[1]+'='+str(shot[1])+ KeyParameter[2]+')');
plt.legend(loc=0)
plt.title('Reproducibility for: '+graph[2])
plt.xlabel('$t$ [ms]')
plt.ylabel(graph[1])
plt.savefig('GlobalFigs/Reproducibility_'+graph[0]+'.jpg', bbox_inches='tight')
if is_interactive():plt.show();
plt.close();