{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
" \n",
"\n",
" \n",
"def Fits(IndvSetup,PlasmaParameters,Extrems,Time,VAchar_voltage,VAchar_current,VAchar_voltage_smoothed,VAchar_current_smoothed, Potential_smoothed,Uloop, Btoroidal, Iplasma, dz, IndxDef):\n",
" ShotNo=IndvSetup[0]\n",
" ShotNoStr=str(ShotNo)\n",
" PlasmaStart=PlasmaParameters[0]\n",
" PlasmaEnd=PlasmaParameters[1]\n",
" \n",
" ylim_min=np.min(VAchar_current_smoothed)\n",
" ylim_max=np.max(VAchar_current_smoothed)\n",
" xlim_min=np.min(VAchar_voltage_smoothed)\n",
" xlim_max=np.max(VAchar_voltage_smoothed)\n",
" \n",
" print(\"Fits .. ...\", end=\":\")\n",
" print(len(Extrems)-1)\n",
" AllVAchars=[]\n",
" def AzoozFn(Vbias, a1, a2, a3, a4):\n",
" return np.exp(a1 * np.tanh((Vbias+a2)/a3)) - a4\n",
"\n",
" def ClassicalFn(Vbias, Isat, Vfl, Te,):\n",
" return -Isat*(1-np.exp((Vbias-Vfl)/Te))\n",
"\n",
" def Classical4Fn(Vbias, Isat, Vfl, Te, C):\n",
" return -Isat*(1-C*(Vbias-Vfl))*(1-np.exp((Vbias-Vfl)/Te))\n",
"\n",
" \n",
" Results=[]\n",
" #Voltage = np.linspace(int(xlim_min),int(xlim_max),1000);dVoltage = Voltage[1]-Voltage[0]\n",
" #AzoozInitialGuess = [3.8,34,42,2.9]\n",
" AzoozInitialGuess = IndvSetup[3]\n",
" #AzoozInitialGuess = [1.5,8,24,1.15] # Absolutne nejslabsi misto\n",
" AFP0=0;AFP1=0;AFP2=0;AFP3=0\n",
" #ClassicalInitialGuess = [4.6,-30,21] # Absolutne nejslabsi misto\n",
" ClassicalInitialGuess = IndvSetup[4]\n",
" ClassicalFitParms=[0,0,0,0]\n",
" #ClassicalInitialGuess = [0.3,-20,20] # Absolutne nejslabsi misto\n",
" CFP0=0;CFP1=0;CFP2=0;CFP3=0;Pocet=0\n",
" if IndxDef[1]==0:\n",
" IndxDef[1]=len(Extrems)-1 # test purposes\n",
" \n",
" for i in range(IndxDef[0],IndxDef[1]): \n",
" data=[VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],\\\n",
" VAchar_current_smoothed[Extrems[i]:Extrems[i+1]]]\n",
" #data=[VAchar_voltage[Extrems[i]:Extrems[i+1]],\\\n",
" # VAchar_current[Extrems[i]:Extrems[i+1]]]\n",
" #Voltage = np.linspace(int(xlim_min),int(xlim_max),len(data[0]));dVoltage = Voltage[1]-Voltage[0]\n",
" Voltage = np.linspace(int(np.min(data[0])),int(np.max(data[0])),len(data[0]));dVoltage = Voltage[1]-Voltage[0]\n",
" #print(Voltage)\n",
" #Voltage = data[0];dVoltage = Voltage[1]-Voltage[0]\n",
" #print(Voltage)\n",
" def plotsetup():\n",
" plt.legend()\n",
" ax1.plot(data[0],data[1],',',label=\"rawdata\")\n",
" ax1.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],VAchar_current_smoothed[Extrems[i]:Extrems[i+1]],label=\"data averaged\")\n",
" plt.grid(True)\n",
" ax1.set_xlim(xlim_min,xlim_max);\n",
" ax1.set_ylim(ylim_min,ylim_max*1.25); # Kvuli legende ..\n",
" ax1.set_title('VAchar #'+ShotNoStr+' \\\n",
" t=<'+str(PlasmaStart+Extrems[i])+','+\\\n",
" str(PlasmaStart+Extrems[i+1])+'> us')\n",
" ax1.set_xlabel('$U$ [V]')\n",
" ax1.set_ylabel('$I$ [mA]')\n",
" ax1.axhline(0);\n",
" ax2 = fig.add_axes([0.25, 0.45, 0.3, 0.18]);\n",
" ax2.set_xlim(PlasmaStart,PlasmaEnd);\n",
" ax2.set_ylim(0,6000);\n",
" ax2.set_yticks([j for j in xrange(0,6000,2000)])\n",
" ax2.set_yticklabels([j for j in xrange(0,6,2)])\n",
" ax2.set_xticks([j for j in xrange(PlasmaStart,PlasmaEnd,5000)])\n",
" ax2.set_xticklabels([j for j in xrange(PlasmaStart/1000,PlasmaEnd/1000,2)])\n",
" ax2.plot(Iplasma['data']);\n",
" ax2.axvline(PlasmaStart+(Extrems[i]+Extrems[i+1])/2);\n",
" ax2.set_ylabel('$I_p$ [kA]')\n",
" ax3 = fig.add_axes([0.25, 0.63, 0.3, 0.18]);\n",
" ax3.set_yticks([(j/10.0) for j in xrange(0,6,2)])\n",
" ax3.set_xticklabels([]);\n",
" ax3.set_ylim(0,0.55);\n",
" ax3.set_xlim(PlasmaStart,PlasmaEnd);\n",
" ax3.plot(Btoroidal['data']);\n",
" ax3.axvline(PlasmaStart+(Extrems[i]+Extrems[i+1])/2);\n",
" ax3.set_ylabel('$B_t$ [T]')\n",
" ax2.set_xlabel('$t$ [ms]')\n",
" #plt.show(); #just for tuning\n",
" fig, ax1 = plt.subplots();\n",
" plotsetup()\n",
" ax1.legend()\n",
" plt.savefig(ShotNoStr+'/IndivVAchars/VA'\\\n",
" +str(i).zfill(2) +':'+str(PlasmaStart+Extrems[i])+'_'+str(PlasmaStart+Extrems[i+1])+'.jpg',\\\n",
" bbox_inches='tight')\n",
" TimeLineDir=ShotNoStr+'/TimeLine/'+str(PlasmaStart+Extrems[i])+'_'+str(PlasmaStart+Extrems[i+1])\n",
" mkdir(TimeLineDir)\n",
" plt.savefig(TimeLineDir+'/VAcharSmoothed.jpg',bbox_inches='tight')\n",
" plt.close();\n",
" # Azooz fit\n",
" #if is_interactive():\n",
" print(i, end=\",\")\n",
" #else:\n",
" # print(i)\n",
" #print data[0][0]\n",
" AzoozFitParms, po_cov = spo.curve_fit(AzoozFn, data[0], data[1], AzoozInitialGuess)\n",
" #print(AzoozFitParms, po_cov)\n",
" AzoozFit=AzoozFn(Voltage,AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3])\n",
" #AzoozFit=AzoozFn(data[0],AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3])\n",
" dAzoozFit_dVoltage = np.gradient(AzoozFit, dVoltage)\n",
" InflPointLoc=argrelextrema(dAzoozFit_dVoltage, np.greater)[0]\n",
" #VflPointLoc=fsolve(AzoozFit, 0.0)\n",
" #VflPointLoc=fsolve(AzoozFn(Voltage,AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3]), 0.0)\n",
" #FitLimit=VflPointLoc\n",
" #print(len(InflPointLoc))\n",
" if len(InflPointLoc) != 1 \\\n",
" or (ShotNo==23191 and i==7)\\\n",
" or (ShotNo==23198 and i>22):\\\n",
" # not reasonable data\n",
" print('(Azooz fit problem)',end=\"\")\n",
" Results.append([\\\n",
" i,\\\n",
" (PlasmaStart+Extrems[i])/1000.0,\\\n",
" (PlasmaStart+(Extrems[i]+Extrems[i+1])/2)/1000.0,\\\n",
" (PlasmaStart+Extrems[i+1])/1000.0,\\\n",
" nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan\n",
" ])\n",
" np.savetxt(TimeLineDir+'/index.html',['\\\n",
"
\\\n",
" \\\n",
" \\\n",
" <=\\\n",
" '+str(i)+':Particular time t='+str(Results[j][2])+' us\\\n",
" =>\\\n",
"
\\\n",
" Raw and smoothed data
\\\n",
" \\\n",
"
!NO FITS!'],fmt=\"%s\")\n",
" \n",
" else: # reasonable data\n",
" #nearest_idx = np.where(abs(data[0]-float(Voltage[InflPointLoc]))==abs(data[0]-float(Voltage[InflPointLoc])).min())[0][0] # Azooz limit\n",
" #nearest_idx = np.where(abs(data[0]-FitLimit)==abs(data[0]-FitLimit).min())[0][0] # HS limit\n",
" #nearest_idx = np.where(abs(AzoozFit-0.0)==abs(AzoozFit-0.0).min())[0][0] # Azooz V_fl limit\n",
" #print(nearest_idx)\n",
" #print(Voltage[nearest_idx])\n",
" errorflag=0\n",
" Shift=int(float(len(data[0]))/(np.max(data[0])-np.min(data[0]))*VoltageShift)\n",
" DataIndex=0\n",
" if data[0][0]<0: # Are we sweeping up or down??\n",
" #if 1==1:\n",
" #Voltage = np.linspace(int(np.max(data[0])),int(np.min(data[0])),len(data[0]));\n",
" nearest_idx = np.where(abs(AzoozFit-0.0)==abs(AzoozFit-0.0).min())[0][0] # Azooz V_fl limit\n",
" VoltageReduced=Voltage[0:nearest_idx+Shift]\n",
" DataIndex=int((nearest_idx+Shift)*1.0*len(data[0])/len(Voltage))\n",
" #print(nearest_idx,nearest_idx+Shift,DataIndex)\n",
" #print(VoltageReduced)\n",
" #VoltageReduced=VoltageDef[0:nearest_idx+Shift]\n",
" #print(VoltageReduced)\n",
" try:\n",
" #ClassicalFitParms, po_cov = spo.curve_fit(Classical4Fn,data[0][0:nearest_idx+Shift], data[1][0:nearest_idx+Shift], ClassicalInitialGuess)\n",
" ClassicalFitParms, po_cov = spo.curve_fit(Classical4Fn,data[0][0:DataIndex], data[1][0:DataIndex], ClassicalInitialGuess)\n",
" except RuntimeError: \n",
" errorflag=1\n",
" else:\n",
" #Voltage = np.linspace(int(np.min(data[0])),int(np.max(data[0])),len(data[0]));\n",
" #VoltageReduced=data[0][0:nearest_idx]\n",
" nearest_idx = np.where(abs(AzoozFit-0.0)==abs(AzoozFit-0.0).min())[0][0] # Azooz V_fl limit\n",
" #VoltageReduced=Voltage[0:len(data[0])-nearest_idx-Shift]\n",
" VoltageReduced=Voltage[0:nearest_idx+Shift]\n",
" DataIndex=int((len(data[0])-(nearest_idx+Shift))*1.0*len(data[0])/len(Voltage))\n",
" #print(VoltageReduced)\n",
" #VoltageReduced=VoltageDef[len(data[0])-nearest_idx-Shift:]\n",
" #print(VoltageReduced)\n",
" try:\n",
" #ClassicalFitParms, po_cov = spo.curve_fit(Classical4Fn,data[0][len(data[0])-nearest_idx-Shift:], data[1][len(data[0])-nearest_idx-Shift:], ClassicalInitialGuess)\n",
" ClassicalFitParms, po_cov = spo.curve_fit(Classical4Fn,data[0][DataIndex:], data[1][DataIndex:], ClassicalInitialGuess)\n",
" except RuntimeError: \n",
" errorflag=1\n",
" if errorflag==1:\n",
" print('(Classic fit problem)',end=\"\")\n",
" Results.append([\\\n",
" i,\\\n",
" (PlasmaStart+Extrems[i])/1000.0,\\\n",
" (PlasmaStart+(Extrems[i]+Extrems[i+1])/2)/1000.0,\\\n",
" (PlasmaStart+Extrems[i+1])/1000.0,\\\n",
" nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan\n",
" ])\n",
" np.savetxt(TimeLineDir+'/index.html',['\\\n",
" \\\n",
" \\\n",
" \\\n",
" <=\\\n",
" '+str(i)+':Particular time t='+str(Results[j][2])+' us\\\n",
" =>\\\n",
"
\\\n",
" Raw and smoothed data
\\\n",
" \\\n",
"
!NO FITS!'],fmt=\"%s\")\n",
" else: \n",
" ClassicalFit=Classical4Fn(VoltageReduced,ClassicalFitParms[0],ClassicalFitParms[1],ClassicalFitParms[2],ClassicalFitParms[3])\n",
" fig, ax1 = plt.subplots();\n",
" plotsetup()\n",
" ax1.plot(VoltageReduced, ClassicalFit, label=\"Classic fit\")\n",
" ax1.plot(Voltage, AzoozFit,label=\"Azooz fit\")\n",
" ax1.legend()\n",
" ax1.axvline(float(Voltage[InflPointLoc]))\n",
" ax1.axvline(float(Voltage[nearest_idx]))\n",
" ax1.axvline(float(Voltage[nearest_idx+Shift]))\n",
" plt.savefig(ShotNoStr+'/IndivVAcharsFits/VA'+str(i).zfill(2) +':'+str(PlasmaStart+Extrems[i])+'_'+str(PlasmaStart+Extrems[i+1])+'.jpg', bbox_inches='tight')\n",
" plt.savefig(ShotNoStr+'/TimeLine/'+str(PlasmaStart+Extrems[i])+'_'+str(PlasmaStart+Extrems[i+1])+'/VAcharFit.jpg', bbox_inches='tight')\n",
" np.savetxt(TimeLineDir+'/VoltageAzooz.dat',np.transpose([Voltage,AzoozFit]),fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/VoltageReducedClassic4.dat',np.transpose([VoltageReduced,ClassicalFit]),fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/SmoothedVachar.dat',np.transpose([VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],VAchar_current_smoothed[Extrems[i]:Extrems[i+1]]]),fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/RawVachar.dat',np.transpose([VAchar_voltage[Extrems[i]:Extrems[i+1]],VAchar_current[Extrems[i]:Extrems[i+1]]]),fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/DataToBeClass4Fitted.dat',np.transpose([data[0][0:DataIndex], data[1][0:DataIndex]]),fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/nearest_idx.dat',[nearest_idx],fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/DataIndex.dat',[DataIndex],fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/Voltage@nearest_idx.dat',[Voltage[nearest_idx]],fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/Shift.dat',[Shift],fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/Voltage@nearest_idxPlusShift.dat',[Voltage[nearest_idx+Shift]],fmt=\"%s\")\n",
" plt.close()\n",
" # plot Raw and smoothed data\n",
" plt.plot(VAchar_voltage[Extrems[i]:Extrems[i+1]],VAchar_current[Extrems[i]:Extrems[i+1]],'+', label=\"raw data\")\n",
" plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],VAchar_current_smoothed[Extrems[i]:Extrems[i+1]], label=\"smoothed\")\n",
" plt.xlabel('$U$ [V]');plt.ylabel('$I$ [mA]');plt.legend()\n",
" plt.savefig(TimeLineDir+'/RawAndSmoothed.jpg', bbox_inches='tight')\n",
" plt.close()\n",
" # plot Raw and smoothed data with fits\n",
" plt.plot(VAchar_voltage[Extrems[i]:Extrems[i+1]],VAchar_current[Extrems[i]:Extrems[i+1]],',', label=\"raw data\")\n",
" plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],VAchar_current_smoothed[Extrems[i]:Extrems[i+1]], label=\"smoothed\")\n",
" plt.plot(VoltageReduced, ClassicalFit, label=\"Classic fit\")\n",
" plt.plot(Voltage, AzoozFit,label=\"Azooz fit\")\n",
" plt.axvline(float(Voltage[nearest_idx]))\n",
" plt.axvline(float(Voltage[nearest_idx+Shift]))\n",
" plt.axhline(0)\n",
" #plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],AzoozFn(data[0],AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3]), label=\"Azooz fit\")\n",
" #plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],Classical4Fn(data[0],ClassicalFitParms[0],ClassicalFitParms[1],ClassicalFitParms[2],ClassicalFitParms[3]), label=\"Classic4p fit\")\n",
" plt.xlabel('$U$ [V]');plt.ylabel('$I$ [mA]');plt.legend()\n",
" plt.savefig(TimeLineDir+'/RawAndSmoothedWithFits.jpg', bbox_inches='tight')\n",
" plt.close()\n",
" # plot Raw and smoothed data with fits zoom\n",
" plt.plot(VAchar_voltage[Extrems[i]:Extrems[i+1]],VAchar_current[Extrems[i]:Extrems[i+1]],',', label=\"raw data\")\n",
" plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],VAchar_current_smoothed[Extrems[i]:Extrems[i+1]], label=\"smoothed\")\n",
" plt.plot(VoltageReduced, ClassicalFit, label=\"Classic 4 fit\")\n",
" plt.plot(Voltage, AzoozFit,label=\"Azooz fit\")\n",
" plt.axvline(float(Voltage[nearest_idx]))\n",
" plt.axvline(float(Voltage[nearest_idx+Shift]))\n",
" plt.axhline(0)\n",
" plt.ylim(-10,10);\n",
" plt.xlabel('$U$ [V]');plt.ylabel('$I$ [mA]');plt.legend()\n",
" plt.savefig(TimeLineDir+'/RawAndSmoothedWithFitsZoom.jpg', bbox_inches='tight')\n",
" plt.close()\n",
" #plot Azooz stuff\n",
" plt.plot(VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]],AzoozFn(data[0],AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3]), label=\"Azooz fit\")\n",
" plt.plot(Voltage,dAzoozFit_dVoltage*100,label=\"Azooz 1st derivative\")\n",
" plt.xlabel('$U$ [V]');plt.ylabel('$I$ [mA]');plt.legend()\n",
" plt.savefig(TimeLineDir+'/AzoozStuff.jpg', bbox_inches='tight')\n",
" plt.close()\n",
" DischTime=(PlasmaStart+(Extrems[i]+Extrems[i+1])/2)/1000.0\n",
" V_BPP=sum(Potential_smoothed[(Extrems[i]):(Extrems[i+1])])/\\\n",
" len(Potential_smoothed[(Extrems[i]):(Extrems[i+1])])\n",
" Results.append([\\\n",
" i,\\\n",
" (PlasmaStart+Extrems[i])/1000.0,\\\n",
" DischTime,\\\n",
" (PlasmaStart+Extrems[i+1])/1000.0,\\\n",
" float(Btoroidal['data'][DischTime*1000:DischTime*1000+1]),\\\n",
" AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3],\\\n",
" #int(InflPointLoc),\\\n",
" Voltage[nearest_idx],\\\n",
" nearest_idx,\\\n",
" float(Voltage[InflPointLoc]),\\\n",
" ClassicalFitParms[0],ClassicalFitParms[1],ClassicalFitParms[2],ClassicalFitParms[3],\\\n",
" (np.exp(AzoozFitParms[0])+AzoozFitParms[3])/(np.exp(-AzoozFitParms[0])+AzoozFitParms[3]),\\\n",
" V_BPP,\\\n",
" (V_BPP-ClassicalFitParms[1])/ClassicalFitParms[2],\\\n",
" sum(dz[(PlasmaStart+Extrems[i]):(PlasmaStart+Extrems[i+1])])/\\\n",
" len(dz[(PlasmaStart+Extrems[i]):(PlasmaStart+Extrems[i+1])])\\\n",
" ])\n",
" j=i-IndxDef[0] # Tuning purposes ..\n",
" k=0\n",
" np.savetxt(TimeLineDir+'/Results',Results[j],fmt=\"%s\")\n",
" np.savetxt(TimeLineDir+'/index.html',['\\\n",
" \\\n",
" \\\n",
" \\\\\n",
" \\\n",
" \\\n",
" <=\\\n",
" '+str(i)+':Particular time t='+str(Results[j][2])+' us\\\n",
" =>\\\n",
"
\\\n",
" Raw and smoothed data with fits
\\\n",
" \\\n",
" \\\n",
" \\\n",
"
\\\n",
" Smoothed data with fits
\\\n",
"
\\\n",
" Results
\\\n",
" i:'+'{:2d}'.format(Results[j][0]) +\\\n",
" ', Time:From:'+'{:4.2f}'.format(Results[j][1]) +\\\n",
" ',via:'+'{:4.2f}'.format(Results[j][2]) +\\\n",
" ',to:'+'{:4.2f}'.format(Results[j][3]) +\\\n",
" ',$B_t$:'+'{:4.2f}'.format(Results[j][4]) +\\\n",
" 'Azooz fit: $a_1$='+'{:+5.3e}'.format(Results[j][5]) +\\\n",
" ',$a_2$='+'{:4.2f}'.format(Results[j][6]) +\\\n",
" ',$a_3$='+'{:+5.3e}'.format(Results[j][7]) +\\\n",
" ',$a_4$='+'{:4.2f}'.format(Results[j][8]) +\\\n",
" 'Inflex point:'+'{:+4.0f}'.format(Results[j][9]) +\\\n",
" ',Infl'+'{:+4.0f}'.format(Results[j][10]) +\\\n",
" ',Infl'+'{:+3.2f}'.format(Results[j][11]) +\\\n",
" 'Class fit: $I_{sat}$='+'{:4.2f}'.format(Results[j][12]) +\\\n",
" ',$\\\\varphi_{pl}$='+'{:4.2f}'.format(Results[j][13]) +\\\n",
" ',$T_e$='+'{:4.2f}'.format(Results[j][14]) +\\\n",
" ',$C$='+'{:4.2f}'.format(Results[j][15]) +\\\n",
" ',$Ratio_{sat}$='+'{:4.2f}'.format(Results[j][16]) +\\\n",
" ',$\\\\varphi_{fl}$='+'{:4.2f}'.format(Results[j][17]) +\\\n",
" ',$\\\\alpha$='+'{:4.2f}'.format(Results[j][18]) +\\\n",
" ',Plasma position='+'{:4.2f}'.format(Results[j][19]) +\\\n",
" 'Azooz stuff
\\\n",
"
\\\n",
" Data
\\\n",
" Raw VA char data
\\\n",
" Smoothed VA char data
\\\n",
" Azooz fit VA data
\\\n",
" Classic 4 par fit VA data
\\\n",
" Final results
\\\n",
" '],fmt=\"%s\")\n",
" AFP0=AFP0+AzoozFitParms[0];AFP1=AFP1+AzoozFitParms[1];AFP2=AFP2+AzoozFitParms[2];AFP3=AFP3+AzoozFitParms[3]\n",
" CFP0=CFP0+ClassicalFitParms[0];CFP1=CFP1+ClassicalFitParms[1];CFP2=CFP2+ClassicalFitParms[2];CFP3=CFP3+ClassicalFitParms[3];Pocet=Pocet+1\n",
" #print(end=\",\")\n",
" #np.savetxt(TimeLineDir+'/chars.dat',\\\n",
" # [[VAchar_voltage[Extrems[i]:Extrems[i+1]][j],\\\n",
" # VAchar_current[Extrems[i]:Extrems[i+1]][j],\\\n",
" # VAchar_voltage_smoothed[Extrems[i]:Extrems[i+1]][j],\\\n",
" # VAchar_current_smoothed[Extrems[i]:Extrems[i+1]][j],\\\n",
" # AzoozFn(data[0][j],AzoozFitParms[0],AzoozFitParms[1],AzoozFitParms[2],AzoozFitParms[3]), \\\n",
" # dAzoozFit_dVoltage[int(1000*(j*1.0)/len(data[0]))],\\\n",
" # Classical4Fn(data[0][j],ClassicalFitParms[0],ClassicalFitParms[1],ClassicalFitParms[2],ClassicalFitParms[3])] \\\n",
" # for j in xrange(len(data[0]))],delimiter=\" \",fmt=\"%.3f\")\n",
"\n",
" np.savetxt(ShotNoStr+'/Data/Results',Results,fmt=\"%+8.2f\") \n",
" #print(IndvSetup[3][0])\n",
" np.savetxt(ShotNoStr+'/Data/AzoozFitCoefficients',['Fit parameters generation *estimate*-><final>: No:{:d}.
'.format(Pocet)\\\n",
" +'Azooz fit: a1:{:4.2f} -> {:4.2f};'.format(IndvSetup[3][0],AFP0/Pocet)\\\n",
" +'a2:{:4.2f} -> {:4.2f};'.format(IndvSetup[3][1],AFP1/Pocet)\\\n",
" +'a3:{:4.2f} -> {:4.2f};'.format(IndvSetup[3][2],AFP2/Pocet)\\\n",
" +'a4:{:4.2f} -> {:4.2f};
'.format(IndvSetup[3][3],AFP3/Pocet)\\\n",
" +'Classic fit: Isat:{:4.2f} -> {:4.2f};'.format(IndvSetup[4][0],CFP0/Pocet)\\\n",
" +'varphi_pl:{:4.2f} -> {:4.2f};'.format(IndvSetup[4][1],CFP1/Pocet)\\\n",
" +'Te:{:4.2f} -> {:4.2f};'.format(IndvSetup[4][2],CFP2/Pocet)\\\n",
" +'C:{:4.3f} -> {:4.3f};'.format(IndvSetup[4][3],CFP3/Pocet)\\\n",
" ],fmt=\"%s\")\n",
" return Results\n",
" \n",
"def htmlgeneration(ShotNo,UBt,VacuumShot,PlasmaStart, PlasmaEnd, Time, Extrems, IndxDef, Results):\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",
" - Current resistor $R=$'+str(HWProudovyResistor)+' $\\Omega$
\\\n",
" - Voltage divider: 1:'+str(HWNapetovyDelic)+'
\\\n",
" - The shot: '+ShotNoStr+'
\\\n",
" - The DAS used: Papouch_St
\\\n",
" - $U_{B_t}$='+str(UBt)+'
\\\n",
" - Vacuum shot /plasma position issues/:'+str(VacuumShot)+'
\\\n",
" - Voltage shift='+str(VoltageShift)+'
\\\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",
" The BPP raw data
\\\n",
"
')\n",
" fileid.write('\\\n",
" Maxima and minima localization in bpp_voltage
\\\n",
"
\\\n",
"
Extrems\\\n",
"
minima\\\n",
"
maxima \\\n",
" ')\n",
" fileid.write('Final movie
')\n",
" fileid.write('
Individual figures\\\n",
" .dat format: VAchar_voltage,VAchar_current,VAchar_voltage_smoothed,VAchar_current_smoothed,Azooz fit,dAzoozFit/dVoltage,ClassicFit
')\n",
" StartIndx=0\n",
" if IndxDef[1]==0:\n",
" IndxDef[1]=len(Extrems)-1 # test purposes\n",
" for i in range(IndxDef[0]-IndxDef[0],IndxDef[1]-IndxDef[0]): \n",
" if os.path.isfile(str(ShotNo)+'/IndivVAcharsFits/VA'+str(i).zfill(2) +':'+str(PlasmaStart+Extrems[i])+'_'+str(PlasmaStart+Extrems[i+1])+'.jpg'): # Azooz fit problem\n",
" fileid.write('
\\\n",
"
\\\n",
" \\\n",
" \\\n",
" i:'+'{:2d}'.format(Results[i][0]) +\\\n",
" ', Time:From:'+'{:4.2f}'.format(Results[i][1]) +\\\n",
" ',via:'+'{:4.2f}'.format(Results[i][2]) +\\\n",
" ',to:'+'{:4.2f}'.format(Results[i][3]) +\\\n",
" ',$B_t$'+'{:4.2f}'.format(Results[i][4]) +\\\n",
" 'Azooz fit: $a_1$='+'{:+5.3e}'.format(Results[i][5]) +\\\n",
" ',$a_2$='+'{:4.2f}'.format(Results[i][6]) +\\\n",
" ',$a_3$='+'{:+5.3e}'.format(Results[i][7]) +\\\n",
" ',$a_4$='+'{:4.2f}'.format(Results[i][8]) +\\\n",
" 'Class fit: $I_{sat}$='+'{:4.2f}'.format(Results[i][12]) +\\\n",
" ',$\\\\varphi_{pl}$='+'{:4.2f}'.format(Results[i][13]) +\\\n",
" ',$T_e$='+'{:4.2f}'.format(Results[i][14]) +\\\n",
" ',$Ratio_{sat}$='+'{:4.2f}'.format(Results[i][15]) +\\\n",
" ',$\\\\varphi_{fl}$='+'{:4.2f}'.format(Results[i][16]) +\\\n",
" ',$\\\\alpha$='+'{:4.2f}'.format(Results[i][17]) +\\\n",
" '
')\n",
" else:\n",
" fileid.write('
\\\n",
"
\\\n",
" \\\n",
" \\\n",
" i:'+'{:2d}'.format(Results[i][0]) +\\\n",
" ', Time:From:'+'{:4.2f}'.format(Results[i][1]) +\\\n",
" ',via:'+'{:4.2f}'.format(Results[i][2]) +\\\n",
" ',to:'+'{:4.2f}'.format(Results[i][3]) +\\\n",
" '
!!Azooz fit problem! -> No Fits !
' +\\\n",
" '
data')\n",
" fileid.write('
\\\n",
"
')\n",
" fileid.write('\\\n",
" $i$ | Time | $B_t$ | \\\n",
" Azooz fit parameters $I(a,V_{bias})=\\exp[a_1 \\\\tanh\\{(V_{bias}+a_2)/a_3\\}]+a_4$ | \\\n",
" InflexPoint | \\\n",
" Classical fit parameters $I(V_{bias},I_{sat},V_{fl},T_e,C)=-I_{sat}*(1-C*(V_{bias}-V_{fl}))*(1-\\exp((V_{bias}-V_{fl})/T_e)$ | \\\n",
" $Ratio_{sat}$ | $\\\\varphi_{fl}$ | $\\\\alpha$ | $Pl_{pos}$ [mm] |
\\\n",
" | Start | Middle | End | \\\n",
" | \\\n",
" $a_1$ | $a_2$ | $a_3$ | $a_4$ | \\\n",
" Data row | Data row | Voltage | \\\n",
" $I_{sat}$ | $\\\\varphi_{pl}$ | $T_e$ | C | | | | |
')\n",
" for i in range(IndxDef[0]-IndxDef[0],IndxDef[1]-IndxDef[0]):\n",
" fileid.write('\\\n",
" '+'{:2.0f}'.format(Results[i][0]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][1]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][2]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][3]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][4]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][5]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][6]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][7]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][8]) +' | \\\n",
" '+'{:3.0f}'.format(Results[i][9]) +' | \\\n",
" '+'{:3.0f}'.format(Results[i][10]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][11]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][12]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][13]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][14]) +' | \\\n",
" '+'{:4.3f}'.format(Results[i][15]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][16]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][17]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][18]) +' | \\\n",
" '+'{:4.2f}'.format(Results[i][19]) +' | \\\n",
"
')\n",
" fileid.write('
data
')\n",
" fileid.write(np.loadtxt(ShotNoStr+'/Data/AzoozFitCoefficients',dtype='str'))\n",
" fileid.write('Experimental Photo
') \n",
" fileid.write('\\n\\n')\n",
" fileid.write('Resources
')\n",
" fileid.write('') \n",
" fileid.write('References
')\n",
" fileid.write('')\n",
" fileid.write('')\n",
" fileid.close()\n",
" \n",
"def GlobalGraphGen(ShotNo,VacuumShot,PlasmaStart, PlasmaEnd, Time, Extrems, Uloop, Btoroidal, Iplasma,\\\n",
" VAchar_current, Potential, Potential_smoothed, PlasmaPosition, dz, Results):\n",
" print(\"Global graph generation .. \")\n",
" ShotNoStr=str(ShotNo)\n",
" Borders=0,len(Extrems) # Initial and final problems out (in future option)\n",
" ResultsArr=np.array(Results)\n",
" f = plt.figure(figsize=(20.0, 10.0))\n",
" f,ax = plt.subplots(17,sharex=True);plt.subplots_adjust(hspace=0.001)\n",
" f.set_size_inches(10,20)\n",
" ax[0].set_title('#' + ShotNoStr)\n",
" ax[0].plot(Time/1000,Uloop['data'][PlasmaStart:PlasmaEnd]);ax[0].set_ylabel('$U_l$ [V]')\n",
" ax[1].plot(Time/1000,Btoroidal['data'][PlasmaStart:PlasmaEnd]);ax[1].set_ylabel('$B_t$ [T]')\n",
" ax[1].plot(ResultsArr[:,2],ResultsArr[:,4],'+')\n",
" ax[2].plot(Time/1000,Iplasma['data'][PlasmaStart:PlasmaEnd]/1000);ax[2].set_ylabel('$I_p$ [kA]')\n",
" \n",
" ax[3].plot(Time/1000,VAchar_current[0:,1]/HWProudovyResistor*CurrentScale,label='VA char: I');ax[3].set_ylabel('$I$ [mA]');ax[3].legend(loc=0)\n",
" ax[3].plot(Time/1000,VAchar_current[0:,1]*0)\n",
" \n",
" ax[4].plot(Time/1000,dz[PlasmaStart:PlasmaEnd]);ax[4].set_ylabel('$$ [mm]')\n",
" ax[4].plot(Time/1000,dz[PlasmaStart:PlasmaEnd]*0)\n",
" ax[4].plot(ResultsArr[:,2],ResultsArr[:,19],'+')\n",
" \n",
" ax[5].plot(ResultsArr[:,2],ResultsArr[:,5],'+');ax[5].set_ylabel('$a_1$')\n",
" ax[6].plot(ResultsArr[:,2],ResultsArr[:,6],'+');ax[6].set_ylabel('$a_2$')\n",
" ax[7].plot(ResultsArr[:,2],ResultsArr[:,7],'+');ax[7].set_ylabel('$a_3$')\n",
" ax[8].plot(ResultsArr[:,2],ResultsArr[:,8],'+');ax[8].set_ylabel('$a_4$')\n",
" ax[9].plot(ResultsArr[:,2],ResultsArr[:,9],'+');ax[9].set_ylabel('InflPoint [V]')\n",
" ax[10].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],12],'+');ax[10].set_ylabel('$I_{sat}$')\n",
" ax[11].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],13],'+');ax[11].set_ylabel('$\\\\varphi_{pl}$ [V]')\n",
" ax[12].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],14],'+');ax[12].set_ylabel('$T_e$ [eV]')\n",
" ax[13].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],15],'+');ax[13].set_ylabel('$C$ []')\n",
" ax[14].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],16],'+');ax[14].set_ylabel('$Ratio_{sat}$ []')\n",
" ax[15].plot(ResultsArr[Borders[0]:Borders[1],2],ResultsArr[Borders[0]:Borders[1],18],'+');ax[15].set_ylabel('$\\\\alpha$ []')\n",
" ax[16].plot(Time/1000,Potential_smoothed);ax[16].set_ylabel('$\\\\varphi_{fl}$ [V]')\n",
" ax[16].plot(Time/1000,Potential_smoothed*0)\n",
" ax[16].plot(ResultsArr[:,2],ResultsArr[:,17],'+')\n",
" \n",
" ax[16].set_xlim(PlasmaStart/1000*8/10,PlasmaEnd/1000*11/10);ax[16].set_xlabel('$t$ [ms]')\n",
"\n",
" plt.savefig(ShotNoStr+'/GlobalResults.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" \n",
"def Initials(ShotNo):\n",
" ShotNoStr=str(ShotNo)\n",
" mkdir(ShotNoStr+'/IndivVAchars');mkdir(ShotNoStr+'/IndivVAcharsFits');\n",
" mkdir(ShotNoStr+'/Basics');mkdir(ShotNoStr+'/Data');mkdir(ShotNoStr+'/TimeLine');\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",
"def PlasmaPositionFn(ShotNo):\n",
" ShotNoStr=str(ShotNo)\n",
" mc5_p=np.loadtxt(ShotNoStr+'/Basics/mc5_p.txt')\n",
" mc5_v=np.loadtxt(ShotNoStr+'/Basics/mc5_v.txt')\n",
" mc13_p=np.loadtxt(ShotNoStr+'/Basics/mc13_p.txt')\n",
" mc13_v=np.loadtxt(ShotNoStr+'/Basics/mc13_v.txt')\n",
" #upper mirnov coil\n",
" mc5_p = integrate(mc5_p[0:,1], coeff=1/(3705 * 1e-6))\n",
" mc5_v = integrate(mc5_v[0:,1], coeff=1/(3705 * 1e-6))\n",
" mc5 = mc5_p - mc5_v # pure signal from plasma\n",
" #bottom mirnov coil\n",
" mc13_p = integrate(mc13_p[0:,1], coeff=1/(3705 * 1e-6))\n",
" mc13_v = integrate(mc13_v[0:,1], coeff=1/(3705 * 1e-6))\n",
" mc13 = mc13_p - mc13_v # pure signal from plasma\n",
" dz= 93 * (mc5 - mc13)/(mc5 + mc13) # calculation of displacement\n",
" for i in range(len(dz)): \n",
" if dz[i]>50:dz[i]=50\n",
" if dz[i]<-50:dz[i]=-50 \n",
" return dz\n",
" \n",
" \n",
"def IndividualShot(IndvSetup,IndxDef):\n",
" ShotNo=IndvSetup[0];print( 'Doing', ShotNo)\n",
" VacuumShot=IndvSetup[1]\n",
" ShotNoStr=str(ShotNo)\n",
" Initials(ShotNo)\n",
" PlasmaParameters=PlasmaParametersDef(ShotNo)\n",
" PlasmaStart=PlasmaParameters[0]\n",
" PlasmaEnd=PlasmaParameters[1]\n",
" \n",
" Time = np.linspace(PlasmaStart,PlasmaEnd,(PlasmaEnd-PlasmaStart))\n",
" VAchar_voltage=np.loadtxt(ShotNoStr+'/Basics/VAchar_voltage.txt')[PlasmaStart:PlasmaEnd]\n",
" VAchar_current=np.loadtxt(ShotNoStr+'/Basics/VAchar_current.txt')[PlasmaStart:PlasmaEnd]\n",
" VAchar_voltage_smoothed=running_mean(VAchar_voltage[:,1]*HWNapetovyDelic,SmoothCoefficient)\n",
" VAchar_current_smoothed=running_mean(VAchar_current[:,1]/HWProudovyResistor*CurrentScale,SmoothCoefficient)\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",
" Potential=np.loadtxt(ShotNoStr+'/Basics/Potential.txt')[PlasmaStart:PlasmaEnd]\n",
" Potential_smoothed=running_mean(Potential[:,1]*HWNapetovyDelic,SmoothCoefficient)\n",
"\n",
" PlasmaPosition=PlasmaPositionFn(ShotNo)\n",
"\n",
" \n",
" DischargeBasics(ShotNo,VacuumShot,PlasmaStart, PlasmaEnd, Time, Uloop, Btoroidal, Iplasma,\\\n",
" VAchar_voltage, VAchar_current,Potential, Potential_smoothed, PlasmaPosition)\n",
" Extrems=FindingSweepIntervals(ShotNo,PlasmaStart, PlasmaEnd, Time, VAchar_voltage)\n",
" Results=Fits(IndvSetup,PlasmaParameters,Extrems,Time,VAchar_voltage[:,1]*HWNapetovyDelic,VAchar_current[:,1]/HWProudovyResistor*CurrentScale,VAchar_voltage_smoothed,VAchar_current_smoothed,\\\n",
" Potential_smoothed, Uloop, Btoroidal, Iplasma, PlasmaPosition, IndxDef)\n",
" htmlgeneration(ShotNo,IndvSetup[2],VacuumShot,PlasmaStart, PlasmaEnd, Time, Extrems, IndxDef, Results)\n",
" GlobalGraphGen(ShotNo,VacuumShot,PlasmaStart, PlasmaEnd, Time, Extrems, Uloop, Btoroidal, Iplasma,\\\n",
" VAchar_current,Potential, Potential_smoothed, PlasmaPosition, PlasmaPosition, Results)\n",
"\n",
"\n",
"def GlobalFigs():\n",
" mkdir('GlobalFigs')\n",
" Time = np.linspace(0,40000,40000)\n",
"\n",
" for graph in GraphSetup:\n",
" FigDef()\n",
" for shot in Setup:\n",
" data=np.load(str(shot[0])+'/Basics/'+graph[0]+'.npz')\n",
" plt.plot(Time/1000,data['data'],label='#'+str(shot[0])+' ($U_{B_t}$='+str(shot[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",
"def Dependences():\n",
" # Dependences with respect to time (Results[0:,2])\n",
" for result in ResultsDef:\n",
" FigDef()\n",
" for shot in Setup:\n",
" Results=np.loadtxt(str(shot[0])+'/Data/Results')\n",
" plt.plot(Results[0:,2],Results[0:,result[0]],shot[6],label=str(shot[0])+' ($U_{B_t}$='+str(shot[2])+')')\n",
" plt.title('Crosscheck for: '+result[2])\n",
" plt.ylabel(result[2])\n",
" plt.xlabel('$t$ [ms]')\n",
" plt.legend(loc=0)\n",
" plt.savefig('GlobalFigs/TimeCrossCheck_'+str(result[1])+'.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" os.system('rm GlobalFigs/TimeCrossCheck_'+str(result[1])+'.dat')\n",
" with open('GlobalFigs/TimeCrossCheck_'+str(result[1])+'.dat', \"a\") as myfile:\n",
" for i in xrange(len(Results[0:,3])):\n",
" k=1;datarow=str(Results[i][3])\n",
" #print(lst)\n",
" for shot in Setup:\n",
" datarow=datarow+result[4].format(Results[0:,result[0]][i])\n",
" k=k+1\n",
" myfile.write(datarow+'\\n')\n",
" # and Ufl x Plpot speciality:\n",
" FigDef()\n",
" for shot in Setup:\n",
" Results=np.loadtxt(str(shot[0])+'/Data/Results')\n",
" plt.plot(Results[0:,2],Results[0:,13],shot[6],label=str(shot[0])+' $\\\\varphi_{fl}$')\n",
" plt.plot(Results[0:,2],Results[0:,17],shot[6],label=str(shot[0])+' $\\\\varphi_{pl}$')\n",
" plt.title('Crosscheck for: $\\\\varphi_{fl}$ x $\\\\varphi_{pl}$')\n",
" plt.ylabel('$V_{fl}$ [V]')\n",
" plt.xlabel('$t$ [ms]')\n",
" plt.legend(loc=0)\n",
" plt.savefig('GlobalFigs/TimeCrossCheck_FlowPot_PlPot.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" \n",
" \n",
"\n",
" # Dependences with respect to Bt (Results[0:,4])\n",
" for result in ResultsDef:\n",
" FigDef()\n",
" for shot in Setup:\n",
" Results=np.loadtxt(str(shot[0])+'/Data/Results')\n",
" plt.plot(Results[0:,4],Results[0:,result[0]],shot[6],label=str(shot[0])+' ($U_{B_t}$='+str(shot[2])+')')\n",
" plt.title('Crosscheck for: '+result[2])\n",
" plt.ylabel(result[2])\n",
" plt.xlabel('$B_t$ [T]')\n",
" plt.legend(loc=0)\n",
" plt.savefig('GlobalFigs/BtCrossCheck_'+str(result[1])+'.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" os.system('rm GlobalFigs/BtCrossCheck_'+str(result[1])+'.dat')\n",
" with open('GlobalFigs/BtCrossCheck_'+str(result[1])+'.dat', \"a\") as myfile:\n",
" for i in xrange(len(Results[0:,4])):\n",
" k=1;datarow=str(Results[i][4])\n",
" for shot in Setup:\n",
" datarow=datarow+result[4].format(Results[0:,result[0]][i])\n",
" k=k+1\n",
" myfile.write(datarow+'\\n')\n",
" # and Ufl x Plpot speciality:\n",
" FigDef()\n",
" for shot in Setup:\n",
" Results=np.loadtxt(str(shot[0])+'/Data/Results')\n",
" plt.plot(Results[0:,4],Results[0:,13],shot[6],label=str(shot[0])+' $\\\\varphi_{fl}$')\n",
" plt.plot(Results[0:,4],Results[0:,17],shot[6],label=str(shot[0])+' $\\\\varphi_{pl}$')\n",
" plt.title('Crosscheck for: $\\\\varphi_{fl}$ x $\\\\varphi_{pl}$')\n",
" plt.ylabel('$V_{fl}$ [V]')\n",
" plt.xlabel('$B_t$ [T]')\n",
" plt.legend(loc=0)\n",
" plt.savefig('GlobalFigs/BtCrossCheck_FlowPot_PlPot.jpg', bbox_inches='tight')\n",
" if is_interactive():plt.show();\n",
" plt.close(); \n",
" \n",
"\n",
"def HtmlGeneration():\n",
" print(\"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
')\n",
" fileid.write('Essential parameters:
\\\n",
" - Date:'+Datum+'
\\\n",
" - BPP used for Plasma Float potential $\\\\varphi_{fl}$, BPP_LP used in sweped mode
\\\n",
" - Probe position:'+Probe_position+'
\\\n",
" - The VA characteristic resistor:'+str(HWProudovyResistor)+'$\\Omega$
\\\n",
" - Sweeping frequency:'+str(HFSweepFrequency)+'
\\\n",
" |
')\n",
" fileid.write('Experimental setup
')\n",
" fileid.write('
Ball pen probe @ North-East port
')\n",
" fileid.write('
\\\n",
" \\\n",
"
\\\n",
" setup \\\n",
" Discharges involved
\\\n",
" \\\n",
" Discharge # | \\\n",
" Vacuum # | \\\n",
" $U_{B_t}$ [V] | \\\n",
" Analysis | \\\n",
" Comment |
')\n",
" for shot in Setup: \n",
" fileid.write('\\\n",
" #'+str(shot[0])+' | \\\n",
" #'+str(shot[1])+' | \\\n",
" '+str(shot[2])+' | \\\n",
" link | \\\n",
" '+str(shot[5])+' | \\\n",
"
')\n",
" for shot in Setup: \n",
" fileid.write('
') \n",
" fileid.write('Reproducibility
')\n",
" for graph in GraphSetup:\n",
" fileid.write('')\n",
" fileid.write('Fits definition
\\\n",
" Azooz fit definition:$I(a,V_{bias})=\\exp[a_1 \\\\tanh\\{(V_{bias}+a_2)/a_3\\}]+a_4$
\\\n",
" Classical 4 par fit definition:$I(V_{bias},I_{sat},V_{fl},T_e,C)=-I_{sat}*(1-C*(V_{bias}-V_{fl}))*(1-\\exp((V_{bias}-V_{fl})/T_e)$
\\\n",
" Classical 3 par fit definition:$I(V_{bias},I_{sat},V_{fl},T_e)=-I_{sat}*(1-\\exp((V_{bias}-V_{fl})/T_e)$') \n",
" fileid.write('Time cross compares
')\n",
" for result in ResultsDef:\n",
" fileid.write('')\n",
" fileid.write(' $\\\\varphi_{fl}$ x $\\\\varphi_{pl}$
\\\n",
"
\\\n",
" ')\n",
" fileid.write('$B_t$ cross compares
')\n",
" for result in ResultsDef:\n",
" fileid.write('')\n",
" fileid.write(' $\\\\varphi_{fl}$ x $\\\\varphi_{pl}$
\\\n",
"
\\\n",
" ')\n",
"\n",
" fileid.write('References
')\n",
" fileid.write('')\n",
" fileid.write('')\n",
" fileid.close()\n",
" \n",
"def MovieGeneration(ShotNo):\n",
" os.system('convert -delay 50 '+str(ShotNo)+'/IndivVAchars/* '+str(ShotNo)+'/finalmovie.gif')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Doing 23297\n",
"Fits .. ...:39\n",
"0,"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:326: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,html generation ...\n",
"Global graph generation .. \n",
"Doing 23295\n",
"Fits .. ...:39\n",
"0,1,2,3,4,5,6,7,8,9,10,11,12,13,(Classic fit problem)14,15,16,17,(Azooz fit problem)18,19,20,(Classic fit problem)21,22,23,24,(Classic fit problem)25,26,27,28,29,30,31,(Classic fit problem)32,33,34,35,36,37,38,html generation ...\n",
"Global graph generation .. \n",
"Doing 23296\n",
"Fits .. ...:41\n",
"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,(Classic fit problem)23,24,25,26,27,28,29,(Azooz fit problem)30,(Classic fit problem)31,32,33,34,35,36,37,38,39,40,"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:133: RuntimeWarning: overflow encountered in exp\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"html generation ...\n",
"Global graph generation .. \n",
"html generation ...\n"
]
}
],
"source": [
"Setup=[\\\n",
" [23297,23196,1100,[4,39.2,46,3.7],[6.3,-34.5,21.3,0.02],'','o'],\\\n",
" [23295,23194,1200,[4.3,42.3,44.6,5.2],[8.4,-34,21,0.02],'','x'],\\\n",
" [23296,23192,1300,[4,36.7,43.7,3.4],[5.5,-32,21.4,0.02],'','*'],\\\n",
" ]\n",
"\n",
"GraphSetup=[['Iplasma','$I_{pl}$ [kA]','$I_p$'],['Uloop',\"$U_{l}$ [V]\",'$U_l$'],['Btoroidal','$B_t$ [T]','$B_t$']]\n",
"\n",
"ResultsDef=[\\\n",
" [2,'Time','t [ms]','',' {:2.0f}'],\\\n",
" [4,'$B_t$','$B_t$ [T]','$T$',' {:4.2f}'],\\\n",
" [5,'$a_1$','$a_1$ []','',' {:4.2f}'],\\\n",
" [6,'$a_2$','$a_2$ []','',' {:4.2f}'],\\\n",
" [7,'$a_3$','$a_3$ []','',' {:4.2f}'],\\\n",
" [8,'$a_4$','$a_4$ []','',' {:4.2f}'],\\\n",
" [12,'$I_{sat}$','$I_{sat}$ [mA]','',' {:4.2f}'],\\\n",
" [13,'$V_{pl}$','$\\\\varphi_{pl}$ [V]','',' {:4.2f}'],\\\n",
" [14,'$T_e$','$T_e$ [eV]','',' {:4.2f}'],\\\n",
" [15,'$C$','$C$ []','',' {:4.3f}'],\\\n",
" [16,'$Ratio_{Sat}$','$Ratio_{sat}$ []','',' {:4.2f}'],\\\n",
" [17,'$U_{fl}$','$\\\\varphi_{fl}$ [V]','',' {:4.2f}'],\\\n",
" [18,'alpha','$\\\\alpha$','',' {:4.2f}'],\\\n",
" ]\n",
"\n",
"\n",
"for j in Setup:\n",
" #GetData(j[0],j[1])\n",
" IndividualShot(j,[0,0]) # mode: which analysis to be made, second parameter: 0 for everything \n",
" #MovieGeneration(j[0])\n",
"GlobalFigs() \n",
"Dependences()\n",
"HtmlGeneration()\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}