Source code :: main
[Return]
[Download]#!/usr/bin/python2
# -*- coding: utf-8 -*-
""" CREATED: 7/2012
AUTHOR: MICHAL ODSTRČIL
"""
import matplotlib
matplotlib.rcParams['backend'] = 'Agg'
matplotlib.rc('font', size='10')
matplotlib.rc('text', usetex=True) # FIXME !! nicer but slower !!!
import pygolem_lite
from pygolem_lite import Shot
from numpy import *
from pygolem_lite.config import *
from pygolem_lite.modules import *
from matplotlib.pyplot import *
import time
from shutil import copy, move
import os
from scipy.interpolate import interp1d
import re
#element_names = ['H','O','He','C','N','M1','MIV']
#element_signs = ['*','o','D','+','x','.','s']
element_names = ['C','O','N']
element_signs = ['*','o','D']
#element_names = ['H','O','C','N','M1']
#element_signs = ['*','o','+','x','.']
def analysis():
shot_num = Shot().shot_num
N = 550 # 3000# # !!!!!! number of shots in history !!!!!
shots = arange(N) + shot_num - N+1
t = time.time()
task = list()
for shot in shots:
try:
task_name = open(shotdir+"/" + str(shot) + "/SessionName").read()
task_name = re.sub("\n", "", task_name)
except:
pass # use previous name
task += [task_name]
start_shots = list()
for i in arange(1,len(shots)):
if task[i] != task[i-1] or i == 1:
start_shots.append([shots[i], task[i] ])
print start_shots
save("start_shots", start_shots)
print "time shots estim", time.time() - t
get_history('pressure_initial', 'pressure_all', shots)
get_history('electron_temperature_max', "temp_max_all", shots)
get_history('temperature_mean', 'temp_all', shots)
#try:
for i in element_names:
get_history('spectrometr\mean_relative_density_'+i, 'impur_dens_'+i, shots)
#except Exception,e:
#print e.__str__()
get_history('spectrometr\mean_temperature', 'impur_temp_all', shots)
#get_history('electron_confinement_t98', 'tau_all',shots)
#get_history('electron_density_mean', "dens_all", shots)
get_history('noise_level', "noise_all", shots)
#photo = get_history('photodiode_mean', "photo_all", shots)
get_history('plasma_current_mean', "current_all", shots)
#uloop = get_history('loop_voltage_mean', "uloop_all", shots)
#get_history('Komora/Aktual_DoutnavyVyboj', "glow_dis_all", shots)
#get_history('Komora/Aktual_VypekaniKomory', "baking_all", shots)
#get_history('Komora/Aktual_VypekaniKrizu', "baking_cross_all", shots)
get_history('Komora/Aktual_PfeifferMerkaVakuaPotrubi', "pipes_pressure_all", shots)
#shots_R, data_R = get_history('chamber_resistance', "chamber_resistance_all", shots[shots>9500])
#shots_R0, data_R0 = get_history('chamber_resistance_old', "chamber_resistance_old_all", shots[shots>9500])
#shots_P, data_P = get_history('plasma', "plasma_all", shots)
#get_history('chamber_temperature', "ch_temp_all", shots)
#ind = in1d(shots_R, shots_P[data_P == 1])
#savetxt('chamber_resistance_all_plasma', array([shots[ind], data_R[ind]]).T, fmt="%g")
#savetxt('chamber_resistance_all_noplasma', array([shots[~ind], data_R[~ind]]).T, fmt="%g")
#ind = in1d(shots_R0, shots_P[data_P == 1])
#savetxt('chamber_resistance_old_all_plasma', array([shots[ind], data_R0[ind]]).T, fmt="%g")
#savetxt('chamber_resistance_old_all_noplasma', array([shots[~ind], data_R0[~ind]]).T, fmt="%g")
get_history('spectrometr\mean_radiation_power', "rad_power_all", shots)
get_history('input_power_plasma_mean', "input_power_all", shots)
def get_history(diagn, name, shot_range):
t = time.time()
N = len(shot_range)
Data = Shot()
shot = Data.shot_num
#print "path", shotdir + '/' + str(shot) + '/' + diagn, os.path.exists(diagn)
#print Data.diagns
if os.path.exists(shotdir + '/' + str(shot) + '/' + diagn):
path = shotdir + '/' + str(shot) + '/' + diagn
else:
path = Data.get_data(diagn, return_path = True)
#print "diagn", diagn, "path", path, ".."
if not path: # some failure
print "get history failed", diagn, name, path
return
print "======= ", path , "======" , re.match('.+\.npz$',path)
#if re.match('.+\.npz$',path):
#[_,d] = load_adv(path)
#else:
#d = loadtxt(path)
#if ndim(d) == 0:
data = zeros(N) + NaN
#elif ndim(d) == 1:
#data = zeros( (N, size(d,0)) ) + NaN
#elif ndim(d) == 2:
#data = zeros( (N, size(d,0), size(d,1)) ) + NaN
#print " = d ", shape(d) , d
for i in range(N):
#print str(shot), str(shot_range[i]), path
path_tmp = re.sub(str(shot), str(shot_range[i]), path)
if os.path.exists(path_tmp) and os.path.getsize(path_tmp) > 0:
#print "exist path =========", path_tmp
#if not re.match('.+\.npz$',path):
try:
f = open( path_tmp , 'r').read()
if not re.match( ".*[a-z].*", f): # no letters in the string
data[i] = float( f )
except Exception, e:
print "ERROR :", e.__str__(), 'shot', shot_range[i]
#else:
#try:
#[_,d] = load_adv(path_tmp)
#data[i, ...] = d
#except:
#raise
if ndim(data) == 1:
ind = ~isnan(data)
elif ndim(data) == 2:
ind = any(~isnan(data),axis=-1)
try:
shots = shot_range[ind]
data = data[ind, ...]
except Exception, e:
print data
print ind
print where(ind)
print e.__str__()
raise
data_final = array([shots, data]).T
#print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
#print data_final
savetxt(name, data_final , fmt="%g")
print "time", time.time() - t
return shots, data
def plot_data(file_type):
start_shots = load("start_shots.npy")
vlines = [ start_shots[i][0] for i in range(len(start_shots)) ]
annotate = [ {'text':start_shots[i][1] , 'pos':[start_shots[i][0], None], 'angle':270, 'fontsize':"small" } for i in range(len(start_shots)) ]
print "vlines", vlines
print "annotate", annotate
plot_size = 12# max(12, (int(start_shots[-1][0]) - int(start_shots[0][0]))/50); # width of the plots
print "plot_size", plot_size, int(start_shots[-1][0]) , int(start_shots[0][0])
try:
data1 = [[get_data('temp_all', 'Mean temperature', 'T [eV]' , ylim = [0,75] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True),
get_data('temp_max_all', 'Max temperature', 'T [eV]' , ylim = [0,75] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True),
get_data('impur_temp_all', 'Specrometr temperature', 'T [eV]', tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, ylim = [0,75] ) ]]
paralel_multiplot(data1, 'Temperature evolution', 'temp', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data2 = [[get_data('pressure_all', 'Init pressure', 'P [mPa]' , ylim = [0.5,6] , tvec_rescale= 1, plot_limits= False, line_format='g.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True),
get_data('pipes_pressure_all', 'Pipes pressure', 'P [mPa]' , ylim = [0.5,6] , data_rescale = 1e-3 , tvec_rescale= 1, plot_limits= False, line_format='b.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)]]
paralel_multiplot(data2, 'Pressure evolution', 'pressure', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data9 = [[get_data('glow_dis_all', 'Glow discharge', 'ON/OFF' , ylim = [0,1.1] , tvec_rescale= 1, plot_limits= False, line_format='r-', xlabel="Shot number", vlines = vlines, annotate = annotate),
get_data('baking_all', 'Chamber baking', 'ON/OFF' , ylim = [0,1.1] , tvec_rescale= 1, plot_limits= False, line_format='g-', xlabel="Shot number", vlines = vlines, annotate = annotate),
get_data('baking_cross_all', 'Cross baking', 'ON/OFF' , ylim = [0,1.1] , tvec_rescale= 1, plot_limits= False, line_format='b-', xlabel="Shot number", vlines = vlines, annotate = annotate)]]
paralel_multiplot(data9, 'Chamber conditioning', 'vacuum', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data3 = get_data('tau_all', 'Confinement', 'tau [s]' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
paralel_multiplot(data3, 'Confinement evolution', 'tau', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data4 = get_data('dens_all', 'Density', 'n$_{e}$' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
paralel_multiplot(data4, 'Density evolution', 'dens', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
#try:
#data5 = get_data('photo_all', 'Mean emiss', 'U [V]' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
#paralel_multiplot(data5, 'Photodiode evolution', 'emiss', (plot_size,4), 100, 'vertical', file_type)
#except:
#pass
#try:
#data7 = get_data('uloop_all', 'Loop voltage', 'U [V]' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
#paralel_multiplot(data7, 'Loop voltage evolution', 'uloop', (plot_size,4), 100, 'vertical', file_type)
#except:
#pass
try:
data8 = get_data('noise_all', 'Noise', 'U [V]' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
paralel_multiplot(data8, 'Noise evolution', 'noise', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data11 = [[get_data('chamber_resistance_all_plasma', 'New-plasma', 'R [Ohm]' , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, yscale='log'), get_data('chamber_resistance_all_noplasma', 'New-noplasma', 'R [Ohm]' , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, yscale='log') ],
[get_data('chamber_resistance_old_all_plasma', 'Old-plasma', 'R [Ohm]' , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, yscale='log'), get_data('chamber_resistance_old_all_noplasma', 'Old-noplasma', 'R [Ohm]' , tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, yscale='log') ]]
paralel_multiplot(data11, 'Chamber resistance', 'resistance', (plot_size,6), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data8 = get_data('ch_temp_all', 'Chamber temperature', 'T [C]' , ylim = [0,None] , tvec_rescale= 1, plot_limits= False, line_format='xr', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
paralel_multiplot(data8, 'Chamber temperature', 'ch_temp', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data8 = get_data('current_all', '', 'I [kA]' , ylim = [0,None] , tvec_rescale= 1, data_rescale=1e-3, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True)
paralel_multiplot(data8, 'Plasma Current' , 'current', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data9 = [[ get_data('impur_dens_'+element_names[i], 'n '+element_names[i], 'n [a.u.]' , tvec_rescale= 1, plot_limits= False, xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, yscale = 'log', ylim=[1e-2, None], line_format=element_signs[i], markersize=4 ) for i in range(len(element_names)) ]]
paralel_multiplot(data9, 'Relative impurity density', 'impurity', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
try:
data9 = [[ get_data('rad_power_all', 'Output power spectrometer', 'P [kW]' , data_rescale=1e-3, tvec_rescale= 1, plot_limits= False, xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, ylim=[0, None], line_format='b.' ),
get_data('input_power_all', 'Input ohmic power', 'P [kW]' , data_rescale=1e-3, tvec_rescale= 1, plot_limits= False, xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, ylim=[0, None], line_format='r+' ) ]]
paralel_multiplot(data9, 'Mean power balance', 'rad_power', (plot_size,4), 100, 'vertical', file_type)
except Exception, e:
print e.__str__()
#try:
#data10 = get_data('impur_temp_all', 'Specrometr temperature', 'T [eV]', tvec_rescale= 1, plot_limits= False, line_format='.', xlabel="Shot number", vlines = vlines, annotate = annotate, ygrid = True, ylim=[0,None] )
#paralel_multiplot(data10, 'Specrometr temperature', 'impur_temp', (plot_size,4), 100, 'vertical', file_type)
#except:
#print e.__str__()
#os.system('convert -resize 150x120\! total_plot.png icon.png')
#print "===== plotting done ===== "
#data = data_1 + data_2 +data_3 + data_4
paralel_multiplot((data1 if 'data1' in locals() else []) + (data2 if 'data2' in locals() else []), "" , 'icon', (4,3), 40)
def main():
if sys.argv[1] == "analysis":
analysis()
if sys.argv[1] == "plots":
plot_data('png')
print "==="*20, "generate svgz !!!"
#plot_data('svgz')
saveconst('status', 0)
if __name__ == "__main__":
main()[Return]