#!/usr/bin/env python
# -*- coding: utf-8 -*-
#main script from the vagnetic profile animation generator.
#Autor :Tomas Odstrcil
import time
cas = time.time()
import matplotlib
matplotlib.rcParams['backend'] = 'Agg'
matplotlib.rc('font', size='10')
matplotlib.rc('text', usetex=True) # FIXME !! nicer but slower !!!
import matplotlib.pyplot as plt
from numpy import *
import os
import sys
from pygolem_lite.modules import saveconst
from scipy.signal import fftconvolve,gaussian
from scipy.interpolate import interpolate
import MagFieldProfileGen
from pygolem_lite import Shot
print 'including time: ', time.time()-cas
#constants
a = 0.085 #[m]
R_0 = 0.4 #[m]
def LoadData():
Data = Shot()
tvec, R_position = Data['plasma_position_r']
tvec, Z_position = Data['plasma_position_z']
Ip = array(Data['plasma_current'], copy = False).T
return tvec,R_position,Z_position,Ip
def Resample(tvec,vec,t_min,t_max,n):
std = (t_max-t_min)/(tvec[1]-tvec[0])/n/2
gauss_win = gaussian(std*3,std)
gauss_win/= sum(gauss_win)
vec_smmoth = fftconvolve(vec,gauss_win, mode = 'same')
tvec_new = linspace(t_min,t_max,n)
f = interpolate.interp1d(tvec,vec_smmoth,bounds_error = False, fill_value = 0, copy = False)
vec_new = f(tvec_new)
return tvec_new,vec_new
def graphs():
tvec,R_position,Z_position,Ip = LoadData()
tvec,Ip = Resample(Ip[:,0],Ip[:,1],tvec[0],tvec[-1],len(tvec))
position = vstack((R_position,Z_position)).T
#plot animation -- very slow!!!
print "plotting animation"
MagFieldProfileGen.PlotProfile(tvec,Ip,position, 'animation')
def main():
if not os.path.exists('video'):
os.mkdir('video')
if sys.argv[1] == "plots":
graphs()
saveconst('status', 0)
if __name__ == "__main__":
main()