-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path_plot_kam_surface.py
71 lines (67 loc) · 2.59 KB
/
_plot_kam_surface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def plot_kam_surface(self, ns=[], ntheta=1000, zeta=0.0, ax=None, **kwargs):
"""Plot SPEC KAM surfaces
Args:
ns (list, optional): List of surface index to be plotted (0 for axis, -1 for the computational boundary if applied).
Defaults to [] (plot all).
zeta (float, optional): The toroidal angle where the cross-sections are plotted. Defaults to 0.0.
ax (Matplotlib axis, optional): Matplotlib axis to be plotted on. Defaults to None.
kwargs (dict, optional): Keyword arguments. Matplotlib.pyplot.plot keyword arguments
Returns:
list : list of FourSurf classes
"""
import numpy as np
import matplotlib.pyplot as plt
Igeometry = self.input.physics.Igeometry
from coilpy import FourSurf
surfs = []
# check if plot all
if len(ns) == 0:
# 0 for the axis
ns = np.arange(self.input.physics.Nvol + self.input.physics.Lfreebound + 1)
else:
ns = np.atleast_1d(ns)
# get axix data
if ax is None:
fig, ax = plt.subplots()
plt.sca(ax)
# set default plotting parameters
if "label" not in kwargs:
kwargs.update({"label": "SPEC_KAM"}) # default label
if "c" not in kwargs:
kwargs.update({"c": "red"})
# plot all the surfaces
if Igeometry == 3:
for i in ns:
_surf = FourSurf.read_spec_output(self, i)
if i == 0:
# plot axis as a curve
_r, _z = _surf.rz(0.0, zeta)
plt.scatter(_r, _z, **kwargs)
else:
_surf.plot(zeta=zeta, **kwargs)
surfs.append(_surf)
plt.axis("equal")
return surfs
elif Igeometry == 2:
for i in ns:
_surf = FourSurf.read_spec_output(self, i)
if i == 0:
pass # don't do anything for the axis
else:
_theta = np.arange(
0, 2 * np.pi + 2 * np.pi / ntheta, 2 * np.pi / ntheta
)
_r, _z = _surf.rz(_theta, np.ones_like(_theta) * zeta)
plt.scatter(_r * np.cos(_theta), _r * np.sin(_theta), **kwargs)
surfs.append(_surf)
plt.axis("equal")
return surfs
elif Igeometry == 1:
for i in ns:
_surf = FourSurf.read_spec_output(self, i)
# plot axis as a curve
_theta = np.arange(0, 2 * np.pi + 2 * np.pi / ntheta, 2 * np.pi / ntheta)
_r, _z = _surf.rz(_theta, np.ones_like(_theta) * zeta)
plt.scatter(_theta, _r, **kwargs)
surfs.append(_surf)
return surfs