Source code :: main_backup
[Return]
[Download]#!/usr/bin/python2
"""Analysis and figure generation for Flukes"""
################################################################
#### CONFIGURATION ####
################################################################
prefix_plasma = "../../../analysis/Basics/0411ShotHomepage.ONN/Plasma"
plasma_start_file = prefix_plasma + "Start"
plasma_end_file = prefix_plasma + "End"
source_DAS = {
"name" : "NIbasic",
"path" : "../../../DAS/1011NIbasic.ON/Nidatap.lvm"
# "path" : "Nidatap.lvm"
}
flukes = [
{ #number 1
"measuring" : "Toroidal magnetic field coils current",
"maximum" : 6e3 #[A]
},
{ #number 2
"measuring" : "Current drive primary winding current",
"maximum" : 6e3 #[A]
},
{ #number 3
"measuring" : "Breakdown winding current",
"maximum" : 6e3 #[A]
},
{ #number 4
"measuring" : "Stabilization vert. mag. field coils current",
"maximum" : 6e3 #[A]
},
]
################################################################
#### IMPORTING ####
################################################################
from numpy import loadtxt, savetxt, log10
from matplotlib.pyplot import figure
from multiprocessing import Process
from mako.template import Template
################################################################
#### FIGURE GENERATION ####
################################################################
data = loadtxt(source_DAS["path"]) #load the data as a big matrix
time_vector = data[:,0] #first column is time
try:
plasma_start = float(open(plasma_start_file).readline())
plasma_end = float(open(plasma_end_file).readline())
plasma = True
except IOError:
plasma = False
time_vector *= 1e3 #convert to ms
source_DAS["sampling_frequency"] = 1 / (time_vector[1] - time_vector[0]) #in kHz !
fig = figure(1) #get a Figure object
icon = figure(2, figsize=(2.14, 1.5), dpi=100)
axes = fig.add_subplot(111) #make only one Axes object within the Figure
for index in xrange(len(flukes)): #iterate over the flukes list
measuring, maximum = flukes[index].values() #unpack the values for this fluke
column = index + 1 #will use column number greater by one, as there is also the time_vector
scaling_factor = 5 * 10 ** -(log10(maximum / 6) + 1) #for range 6000 A it's 0.5 mV/1A
flukes[index]["scaling"] = scaling_factor
current = data[:,column] #convenient array slice view
current /= scaling_factor #scale the current data
p = Process(target=savetxt, args=("fluke_" + str(column) + ".csv", data[:,[0,column]]), kwargs=dict(delimiter=",")) #save the data in CSV format
p.start() #save data in paralel
flukes[index]["over_limit"] = (current > maximum).any() or (current < -maximum).any() #True if anywhere in the array the measured value is beyond the range
iaxes = icon.add_subplot(len(flukes),1,column)
for ax in [axes, iaxes]:
ax.plot(time_vector, current)
if current.max() > maximum:
ax.set_ylim(top=maximum)
if current.min() < -maximum:
ax.set_ylim(bottom=-maximum)
if plasma:
for border in [plasma_start, plasma_end]:
ax.axvline(border, color="black", linestyle='dashed')
iaxes.set_xticks(())
iaxes.set_yticks(())
axes.set_xlabel("Time [ms]") #TODO: maybe scale to ms?
axes.set_ylabel("Current [A]")
fig.savefig("fluke_" + str(column) + ".png") #save the figure
axes.clear() #clear the axis for next plot
icon.savefig('icon.png')
################################################################
#### HTML GENERATION ####
################################################################
def make_html(template_fname="index.html.template", **kwargs):
t = Template(filename=template_fname)
with open(template_fname.replace('.template', ''), 'w') as f:
f.write(t.render(**kwargs))
make_html(flukes=flukes, DAS=source_DAS)[Return]