Revision 0ab53102c02cd5c97fc58c71489748c2546cd368 (click the page title to view the current version)
#-------------------------------------------------------------------------------------------
# Import prostredia pre pracu s kniznicami numpy, scipy, matplotlib....
% pylab inline
import urllib2
#---------------------------------------------------------------------------------
# Funkcia pre vytvorenie matice dat - vstup: string s linkom pre konkretne data z databazy tokamaku GOLEM
def data_array(data):
datas = urllib2.urlopen(data)
lines = datas.readlines()
for k,l in enumerate(lines):
lines[k] = l.strip().split()
for i,j in enumerate(lines[k]):
try:
lines[k][i] = float(j)
except 'ValueError':
print('not a number')
return array(lines)
#----------------------------------------------------------------------------------
# Data pre prud v plazme a a urcenie casu pre zaciatok vyboja
shot = # shot number#
I_plasma = data_array('http://golem.fjfi.cvut.cz/utils/data/%i/plasma_current'%shot)
shot_start = data_array('http://golem.fjfi.cvut.cz/utils/data/%i/plasma_start'%shot)
#----------------------------------------------------------------------------------
# Definovana fitovacia funkcia pre start up fazu
def f(t,t_0,L,n0,t0):
ft = zeros_like(t)
for i, j in enumerate(t):
if j <=t_0:
ft[i] = n0*exp((1/L)*(j-t0))
elif j > t_0:
ft[i] = (n0/L)*exp(((t_0-t0)/L))*(j) + (1-(t_0/L))*(n0)*exp(((t_0-t0)/L))
return ft
#---------------------------------------------------------------------------------
# Urcenie rozpatia dat pre fitovanie
zac = 500
kon = 300
def time_interval(start,I_p):
beg = argmin(abs(I_p[:,0] - start)) - zac
end = argmin(abs(I_p[:,0] - start)) + kon
return array([beg,end])
beg = time_interval(shot_start,I_plasma)[0]
end = time_interval(shot_start,I_plasma)[1]
#-------------------------------------------------------------------------------
# Vypocet parametrov definujucich start up fazu vyboja
p0 = array([0.0123, 5.24058646e-05, 8.74081919e+01,0.0124])
param, c = curve_fit(f,I_plasma[beg:end,0],I_plasma[beg:end,1]-mean(I_plasma[beg:end-300,1]),p0)