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.

Import modules

In [1]:
# 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)
Notebook initialized with x3d backend.
In [2]:
cd ~/Documents/Code/FOCUS/examples/w7x_std_30/
/Users/czhu/Documents/Code/FOCUS/examples/w7x_std_30

FOCUS hdf5 output

In [23]:
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)
FOCUS version: v0.13.02
Out[23]:
<matplotlib.legend.Legend at 0x133e71a58>
In [42]:
# Poincare plot
plt.figure(figsize=[6,8])
output.poincare_plot()
plt.ylim([-1.3, 1.3])
Out[42]:
(-1.3, 1.3)
In [44]:
# Residual Bnormal plot
output.Bnorm(source='coil')
Out[44]:
[<matplotlib.image.AxesImage at 0x13e64ce48>]

FOCUS plasma boundary

In [17]:
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()
In [19]:
# plot 3D figures using matplotlib
xx, yy, zz = plasma.plot3d()
In [22]:
# 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
Notebook initialized with png backend.
PNG image
In [45]:
# 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()

Coils

In [46]:
# read coils in MAKEGRID format
from coils import Coil
w7x_30 = Coil.read_makegrid('w7x_std_30.coils')
In [47]:
# 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
PNG image
In [ ]: