This is a brief tutorial for CoilPy. Here is the full list of required packages, but most of them will be only needed in specific functions. The user is encouraged to check the docstring (like using the question mark in ipython kernals) or even the source code for more details.
mayavi
numpy
matplotlib.pyplot
warnings
sys
pyevtk.hl
pandas
In this tutorial, we are going to demonstrate three functions that are relevent to general FOCUS runs. There are more functions can be used and please check the source code.
We going to use the example w7x_std_30
in the FOCUS repository. Please compile and execute FOCUS first.
# add CoilPy to python sys path
import sys
sys.path.append('/Users/czhu/Documents/Code/CoilPy/')
# common python packages
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook
# 3D rendering using mayavi; not mandatory
from mayavi import mlab
mlab.init_notebook('x3d', 600, 600, local=True)
cd ~/Documents/Code/FOCUS/examples/w7x_std_30/
from focushdf5 import FOCUSHDF5
# read the hdf5file
output = FOCUSHDF5('focus_w7x_std_30.h5')
# plot the convergence
output.convergence(term='all')
plt.legend(loc=4)
# Poincare plot
plt.figure(figsize=[6,8])
output.poincare_plot()
plt.ylim([-1.3, 1.3])
# Residual Bnormal plot
output.Bnorm(source='coil')
from surface import FourSurf
# read the boundary file
plasma = FourSurf.read_focus_input('plasma.boundary')
# plot crossections
plt.figure()
plasma.plot(zeta=0, label='w7x_boundary')
plt.legend()
plt.tight_layout()
# plot 3D figures using matplotlib
xx, yy, zz = plasma.plot3d()
# plot 3D figures using mayavi
mlab.init_notebook('png') # only required for storing the image. For interactive ploting, please use 'x3d'
fig = mlab.figure(bgcolor=(1,1,1), fgcolor=(0,0,0), size=(600,600))
plasma.plot3d(engine='mayavi')
fig
# Poincare plot with the target boundary
plt.figure(figsize=[6,8])
plasma.plot(zeta=0, label='w7x_boundary', color='k', linestyle='--')
plt.legend()
output.poincare_plot()
# read coils in MAKEGRID format
from coils import Coil
w7x_30 = Coil.read_makegrid('w7x_std_30.coils')
# plot coils using mayavi, with the boundary
fig = mlab.figure(bgcolor=(1,1,1), fgcolor=(0,0,0), size=(600,600))
w7x_30.plot(engine='mayavi', color=(0,0,1))
plasma.plot3d(engine='mayavi')
fig