coilpy.misc#
- coilpy.misc.booz2focus(booz_file, ns=-1, focus_file='plasma.boundary', tol=1e-06, Nfp=1)[source]#
convert BOOZ_XFORM output into FOCUS format plasma surface (in Boozer coordinates)
- Parameters:
booz_file (str) – Netcdf file of BOOZ_XFORM output
ns (int, optional) – The specific flux surface you want to convert. Defaults to -1.
focus_file (str, optional) – FOCUS plasma boundary filename. Defaults to ‘plasma.boundary’.
tol ([type], optional) – Tolerance to truncate. Defaults to 1E-6.
Nfp (int, optional) – [description]. Defaults to 1.
- coilpy.misc.get_figure(axes=None, **kwargs)[source]#
Check where to plot :param axes: matplotlib.pyplot axis, axis to plot (default: None) :param kwargs: keyword arguments
- Returns:
f, ax f : matplotlib.pyplot figure ax : matplotlib.pyplot axis
- coilpy.misc.map_matrix(xx, first=True, second=True)[source]#
Map matrix to be complete (closed) :param xx – 2D numpy array: :param first – boolean: True, if increase the first dimension :param default: True, if increase the first dimension :param second – boolean: True, if increase the second dimension :param default: True, if increase the second dimension
- Returns:
new – the new matrix with dimension increased
- coilpy.misc.poincare_plot(data, color=None, **kwargs)[source]#
Making poincare plot
- Parameters:
data (array_like) – poincare data, shape is [nlines, niterations, 2].
color (matplotlib color, optional) – Color code. Defaults to None.
- coilpy.misc.print_progress(iteration, total, prefix='Progress', suffix='Complete', decimals=1, bar_length=60)[source]#
Call in a loop to create terminal progress bar @params:
iteration - Required : current iteration (Int) total - Required : total iterations (Int) prefix - Optional : prefix string (Str) suffix - Optional : suffix string (Str) decimals - Optional : positive number of decimals in percent complete (Int) bar_length - Optional : character length of bar (Int)
- coilpy.misc.read_focus_boundary(filename)[source]#
Read FOCUS/FAMUS plasma boundary file
- Parameters:
filename (str) – File name and path.
- Returns:
- Dict contains the parsed data.
nfp : number of toroidal periods nfou : number of Fourier harmonics for describing the boundary nbn : number of Fourier harmonics for Bn surface : Toroidal surface dict, containing ‘xm’, ‘xn’, ‘rbc’, ‘rbs’, ‘zbc’, ‘zbs’ bnormal : Input Bn dict, containing ‘xm’, ‘xn’, ‘bnc’, ‘bns’
- Return type:
boundary (dict)
- coilpy.misc.real2trig_2d(f, xm, xn, theta, zeta)[source]#
Fourier decomposition in 2D
- Parameters:
f (numpy.ndarray) – The 2D function to be decomposed. Size: [npol, ntor].
xm (numpy.ndarray) – Poloildal mode number. Size: [mn,]
xn (numpy.ndarray) – Toroildal mode number. Size: [mn,]
theta (numpy.ndarray) – Poloidal angles. Size:[npol,].
zeta (numpy.ndarray) – Toroidal angles. Size:[ntor,]
- Returns:
Cos harmonics, sin harmonics. Size: [mn,]
- Return type:
numpy.ndarray, numpy.ndarray
- coilpy.misc.rotation_angle(R, xyz=False)[source]#
Get the rotation angle from a rotation matrix
- Parameters:
R (3x3 matrix) – The rotation matrix.
xyz (bool, optional) – the rotation scenario, RxRyRz vs RzRyRx. Defaults to False.
- Returns:
The rotation angle around x,y,z-axis (if xyz=True) or z,y,x-axis.
- Return type:
[alpha, beta, gamma]
- coilpy.misc.rotation_matrix(alpha=0.0, beta=0.0, gamma=0.0, xyz=False)[source]#
A genera rotation matrix using yaw, pitch, and roll angles
- Parameters:
alpha (float, optional) – The yaw angle (rotating around the z-axis). Defaults to 0.0.
beta (float, optional) – The pitch angle (rotating around the y-axis). Defaults to 0.0.
gamma (float, optional) – The roll angle (rotating around the x-axis). Defaults to 0.0.
xyz (bool, optional) – The rotation order, True: x->y->z; False: z->y->x. Defaults to False
- Returns:
The rotation matrix.
- Return type:
R (3x3 matrix)
- coilpy.misc.scan_focus(template, key, value, run=False)[source]#
Scan input variable of FOCUS
- Parameters:
template (str) – a template input file (*.input).
key (str) – the variable name that will be scanned.
value (list) – the loop that the scan is going to take.
run (bool, optional) – whether you want to run the scan immediately. Defaults to False.
- coilpy.misc.set_axes_equal(ax)[source]#
Make axes of 3D plot have equal scale so that spheres appear as spheres, cubes as cubes, etc.. This is one possible solution to Matplotlib’s ax.set_aspect(‘equal’) and ax.axis(‘equal’) not working for 3D.
- Input
ax: a matplotlib axis, e.g., as output from plt.gca().
- coilpy.misc.toroidal_period(vec, nfp=1)[source]#
vec: [x,y,z] data Nfp: =1, toroidal number of periodicity
- coilpy.misc.tracing(bfield, r0, z0, phi0=0.0, niter=100, nfp=1, nstep=1, **kwargs)[source]#
Trace magnetic field line in toroidal geometry
- Parameters:
bfield (callable) – A callable function. The calling signature is B = bfield(xyz), where xyz is the position in cartesian coordinates and B is the magnetic field at this point (in cartesian coordinates).
r0 (list) – Initial radial coordinates.
z0 (list) – Initial vertical coordinates.
phi0 (float, optional) – The toroidal angle where the poincare plot data saved. Defaults to 0.0.
niter (int, optional) – Number of toroidal periods in tracing. Defaults to 100.
nfp (int, optional) – Number of field periodicity. Defaults to 1.
nstep (int, optional) – Number of intermediate step for one period. Defaults to 1.
- Returns:
The stored poincare date, shape is (len(r0), niter+1, 2).
- Return type:
array_like
- coilpy.misc.trig2real(theta, zeta=None, xm=[], xn=[], fmnc=None, fmns=None)[source]#
Trigonometric coefficients to real space points
- Parameters:
theta (numpy.ndarray) – Theta values to be evaluated.
zeta (numpy.ndarray, optional) – Zeta values to be evaluated if discretizing in 2D. Defaults to None.
xm (list, optional) – Poloidal Fourier modes. Defaults to [].
xn (list, optional) – Toroidal Fourier modes. Defaults to [].
fmnc ([type], optional) – Cosine Fourier coefficients Defaults to None.
fmns ([type], optional) – Sin Fourier coefficients. Defaults to None.
- Returns:
The discretized values in real space.
- Return type:
numpy.ndarray
- coilpy.misc.trigfft(y, tr=-1)[source]#
calculate trigonometric coefficients using FFT Assuming the periodicity is 2*pi params:
y – 1D array for Fourier transformation tr – Truncation number (default: -1)
- Returns:
a dict containing ‘n’ – index ‘rcos’ – cos coefficients of the real part ‘rsin’ – sin coefficients of the real part ‘icos’ – cos coefficients of the imag part ‘isin’ – sin coefficients of the imag part
- coilpy.misc.trigfft2(y)[source]#
calculate trigonometric coefficients using FFT Assuming the periodicity is 2*pi params:
y – 2D array for Fourier transformation
- Returns:
a dict containing ‘n’ – 1D array, n index ‘m’ – 1D array, m index ‘rcos’ – 2D array, cos coefficients of the real part ‘rsin’ – 2D array, sin coefficients of the real part ‘icos’ – 2D array, cos coefficients of the imag part ‘isin’ – 2D array, sin coefficients of the imag part
- coilpy.misc.vmec2focus(vmec_file, focus_file='plasma.boundary', bnorm_file=None, ns=-1, curpol=1.0, flipsign=False)[source]#
Prepare FOCUS input boundary
- Parameters:
vmec_file (str) – VMEC input or output filename.
focus_file (str, optional) – FOCUS boundary filename to be written. Defaults to ‘plasma.boundary’.
bnorm_file (str, optional) – BNORM output filename. Defaults to None.
ns (int, optional) – VMEC surface index. Defaults to -1.
curpol (float, optional) – Normalization factor related to poloidal current. Defaults to 1.0.
flipsign (bool, optional) – Bool value to flip the sign of Bn coefficients. Defaults to False.
- coilpy.misc.write_focus_boundary(filename, surf, nfp=1, bn=None, **kwargs)[source]#
Write the Fourier harmonics down in FOCUS format
- Parameters:
filename (str) – File name to be saved.
surf (dict) – Plasma surface information, containing ‘xm’, ‘xn’, ‘rbc’, ‘rbs’, ‘zbc’, zbs’.
nfp (int, optional) – Number of field periodicity. Defaults to 1.
bn (dict, optional) – Nonzero Bn information, containing ‘xm’, ‘xn’, ‘bnc’, ‘bns’. Defaults to None.