scotty.fun_general module
scotty.fun_general module#
Functions for Scotty (excluding functions for finding derivatives of H).
- scotty.fun_general.K_magnitude(K_R, K_zeta, K_Z, q_R)#
Returns the magnitude of the wavevector \(\mathbf{K}\):
\[|K| = \sqrt{\mathbf{K}\cdot\mathbf{K}} = \sqrt{K_R^2 + (K_\zeta / q_R)^2 + K_Z^2}\]- Parameters
K_R (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) –
K_zeta (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) –
K_Z (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) –
q_R (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) –
- Return type
Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]
- scotty.fun_general.angular_frequency_to_wavenumber(angular_frequency)#
Convert angular frequency to wavenumber
- scotty.fun_general.apply_continuous_BC(q_R, q_Z, Psi_vacuum_3D, K_v_R, K_v_zeta, K_v_Z, delta_R, delta_Z, field, hamiltonian)#
- scotty.fun_general.apply_discontinuous_BC(q_R, q_Z, Psi_vacuum_3D, K_v_R, K_v_zeta, K_v_Z, launch_angular_frequency, mode_flag, delta_R, delta_Z, field, hamiltonian, temperature=None)#
- scotty.fun_general.contract_special(arg_a, arg_b)#
Dot product of arrays of vectors or matrices.
Covers the case that matmul and dot don’t do very elegantly, and avoids having to use a for loop to iterate over the array slices.
- Parameters
arg_a (numpy.ndarray[Any, numpy.dtype[numpy.float64]]) –
One of:
matrix with shape TxMxN and a vector with TxN or TxM
two vectors of shape TxN
For each T, independently compute the dot product of the matrices/vectors
arg_b (numpy.ndarray[Any, numpy.dtype[numpy.float64]]) –
One of:
matrix with shape TxMxN and a vector with TxN or TxM
two vectors of shape TxN
For each T, independently compute the dot product of the matrices/vectors
- Return type
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
- scotty.fun_general.find_Booker_alpha(electron_density, B_Total, sin_theta_m_sq, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_Booker_beta(electron_density, B_Total, sin_theta_m_sq, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_Booker_gamma(electron_density, B_Total, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_D(K_magnitude, launch_angular_frequency, epsilon_para, epsilon_perp, epsilon_g, theta_m)#
- scotty.fun_general.find_H_Cardano(K_magnitude, launch_angular_frequency, epsilon_para, epsilon_perp, epsilon_g, theta_m)#
- scotty.fun_general.find_H_numba(K_magnitude, electron_density, B_Total, sin_theta_m_sq, launch_angular_frequency, mode_flag, temperature)#
- scotty.fun_general.find_K_lab(K_lab_Cartesian, q_lab_Cartesian)#
- scotty.fun_general.find_K_lab_Cartesian(K_lab, q_lab)#
- scotty.fun_general.find_K_plasma(q_R, K_v_R, K_v_zeta, K_v_Z, launch_angular_frequency, mode_flag, B_R, B_T, B_Z, electron_density_p, dpolflux_dR, dpolflux_dZ, temperature=None)#
- scotty.fun_general.find_Psi_3D_lab(Psi_3D_lab_Cartesian, q_R, q_zeta, K_R, K_zeta)#
Converts Psi_3D from Cartesian to cylindrical coordinates, both in the lab frame (not the beam frame)
- scotty.fun_general.find_Psi_3D_lab_Cartesian(Psi_3D_lab, q_R, q_zeta, K_R, K_zeta)#
Converts Psi_3D from cylindrical to Cartesian coordinates, both in the lab frame (not the beam frame) The shape of Psi_3D_lab must be either [3,3] or [numberOfDataPoints,3,3]
- scotty.fun_general.find_Psi_3D_plasma_continuous(Psi_vacuum_3D, dH_dKR, dH_dKzeta, dH_dKZ, dH_dR, dH_dZ, d_poloidal_flux_d_R, d_poloidal_flux_d_Z)#
- scotty.fun_general.find_Psi_3D_plasma_discontinuous(Psi_vacuum_3D, K_v_R, K_v_zeta, K_v_Z, K_p_R, K_p_zeta, K_p_Z, dH_dKR, dH_dKzeta, dH_dKZ, dH_dR, dH_dZ, dpolflux_dR, dpolflux_dZ, d2polflux_dR2, d2polflux_dZ2, d2polflux_dRdZ)#
- scotty.fun_general.find_Rayleigh_length(waist, wavenumber)#
- scotty.fun_general.find_ST_terms(tau_array, K_magnitude_array, k_perp_1_bs, g_magnitude_Cardano, g_magnitude_output, theta_m_output, M_w_inv_xx_output)#
- scotty.fun_general.find_area_points(xs, ys, fraction_wanted)#
ys = f(xs)
Finds the maximum in ys, and finds an area around that Used to find localisation
Assume xs sorted in ascending order
- scotty.fun_general.find_d2B_dR2_CFD(q_R, q_Z, delta_R, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d^2 B}{d R^2}\), where B is the magnitude of the B field
- scotty.fun_general.find_d2B_dR2_FFD(q_R, q_Z, delta_R, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d^2 B}{d R^2}\), where B is the magnitude of the B field
- scotty.fun_general.find_d2B_dR_dZ_FFD(q_R, q_Z, delta_R, delta_Z, find_B_R, find_B_T, find_B_Z)#
- scotty.fun_general.find_d2B_dZ2_CFD(q_R, q_Z, delta_Z, find_B_R, find_B_T, find_B_Z)#
- scotty.fun_general.find_d2B_dZ2_FFD(q_R, q_Z, delta_Z, find_B_R, find_B_T, find_B_Z)#
- scotty.fun_general.find_dB_dR_CFD(q_R, q_Z, delta_R, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d B}{d R}\), where B is the magnitude of the B field
- scotty.fun_general.find_dB_dR_FFD(q_R, q_Z, delta_R, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d B}{d Z}\), where B is the magnitude of the B field
- scotty.fun_general.find_dB_dZ_CFD(q_R, q_Z, delta_Z, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d B}{d Z}\), where B is the magnitude of the B field
- scotty.fun_general.find_dB_dZ_FFD(q_R, q_Z, delta_Z, find_B_R, find_B_T, find_B_Z)#
Finds \(\frac{d B}{d Z}\), where B is the magnitude of the B field
- scotty.fun_general.find_dbhat_dR(q_R, q_Z, delta_R, find_B_R, find_B_T, find_B_Z)#
- scotty.fun_general.find_dbhat_dZ(q_R, q_Z, delta_Z, find_B_R, find_B_T, find_B_Z)#
- scotty.fun_general.find_distance_from_waist(width, wavenumber, curvature)#
- scotty.fun_general.find_electron_mass(temperature=None)#
Implements first-order relativistic corrections to electron mass. Tmperature is an optional argument. If no argument is passed, returns standard electron mass as a scalar. When passed an array of temperatures, returns an array of relativistically-corrected electron masses.
Temperature needs to be in units of KeV.
- scotty.fun_general.find_epsilon_g(electron_density, B_Total, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_epsilon_para(electron_density, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_epsilon_perp(electron_density, B_Total, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_inverse_2D(matrix_2D)#
- scotty.fun_general.find_nearest(array, value)#
Returns the index of the first element in
array
closest in absolute value tovalue
- Parameters
array (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) –
value (Any) –
- Return type
- scotty.fun_general.find_normalised_gyro_freq(B_Total, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_normalised_plasma_freq(electron_density, launch_angular_frequency, temperature=None)#
- scotty.fun_general.find_q_lab(q_lab_Cartesian)#
- scotty.fun_general.find_q_lab_Cartesian(q_lab)#
- scotty.fun_general.find_quick_output(ray_parameters_2D, K_zeta_initial, find_B_R, find_B_T, find_B_Z)#
Finds mismatch at cut-off location Cut-off location where K is minimised
- scotty.fun_general.find_vec_lab_Cartesian(vec_lab, q_zeta)#
- scotty.fun_general.find_waist(width, wavenumber, curvature)#
- scotty.fun_general.find_widths_and_curvatures(Psi_xx, Psi_xy, Psi_yy, K_magnitude, theta_m, theta)#
Calculates beam widths and curvatures from components of Psi_w
Equations (15) and (16) of VH Hall-Chen et al., PPCF (2022) https://doi.org/10.1088/1361-6587/ac57a1
- Parameters
Psi_xx (TYPE) – DESCRIPTION.
Psi_xy (TYPE) – DESCRIPTION.
Psi_yy (TYPE) – DESCRIPTION.
K_magnitude (TYPE) – DESCRIPTION.
theta_m (TYPE) – Mismatch angle, in radians. Equation (109) of the above paper
theta (TYPE) – Equation (107) of the above paper.
- Returns
widths (TYPE) – DESCRIPTION.
Psi_w_imag_eigvecs (TYPE) – DESCRIPTION.
curvatures (TYPE) – DESCRIPTION.
Psi_w_real_eigvecs (TYPE) – DESCRIPTION.
- scotty.fun_general.find_x0(xs, ys, y0)#
xs,ys are the x and y coordinates of a line on a plane Finds the value of x corresponding to a certain y0 This implementation is silly but I am impatient and want to move on to other things quickly
- scotty.fun_general.freq_GHz_to_angular_frequency(freq_GHz)#
Convert frequency in GHz to angular frequency
- scotty.fun_general.freq_GHz_to_wavenumber(freq_GHz)#
Converts frequency in GHz to wavenumber
- scotty.fun_general.genray_angles_from_mirror_angles(rot_ang_deg, tilt_ang_deg, offset_for_window_norm_to_R=3.0)#
Compute the GENRAY-equivalent angles from mirror angles
rot_ang_deg = 0
,tilt_ang_deg = 0
implies beam propagates in negative window normal direction.Can get from
rot_ang_deg, tilt_ang_deg
by using toroidal and poloidal “genray angles” (tor_ang, pol_ang
) in IDL savefile log. The angles were calculated according to the logic:tor_ang = 3.0 - rot_ang_deg pol_ang = tilt_ang_deg
- Parameters
rot_ang_deg (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) – Steering mirror rotation angle in degrees
tilt_ang_deg (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) – Steering mirror tilt angle in degrees
offset_for_window_norm_to_R (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) – Toroidal angle in degrees of window normal to major radial position, such that for
rot_ang_deg = 0
,tilt_ang_deg = 0
beam would have toroidal angle given byoffset_for_window_norm_to_R
.
- Return type
Tuple[Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]], Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]
- scotty.fun_general.make_array_3x3(array)#
Convert a 2x2 array into a 3x3 by appending zeros on the outside:
\[\begin{split}\begin{pmatrix} a & b \\ c & d \\ \end{pmatrix} \Rightarrow \begin{pmatrix} a & b & 0 \\ c & d & 0 \\ 0 & 0 & 0 \\ \end{pmatrix}\end{split}\]
- scotty.fun_general.make_unit_vector_from_cross_product(vector_a, vector_b)#
Assume np.shape(vector_a) = np.shape(vector_b) = (n,3) or np.shape(vector_a) = (n,3) , np.shape(vector_b) = (3)
- scotty.fun_general.mirrornorm_make(r, t)#
makes norm vector for mirror directly using angles in radians
- scotty.fun_general.mirrornorm_make_with_rot_tilt_operators(r, t)#
makes norm vector for mirror using rot and tilt operators given angles in radians
- scotty.fun_general.modify_beam(width, curvature, freq_GHz, z0_shift, w0_shift)#
positive z0_shift moves the waist in the direction of -infinity
- scotty.fun_general.propagate_beam(Psi_w_initial_cartesian, propagation_distance, freq_GHz)#
Uses the vacuum solution of the beam tracing equations to propagate the beam Works for arbitrary Gaussian beam in vacuum
- scotty.fun_general.propagate_circular_beam(width, curvature, propagation_distance, freq_GHz)#
w0 : Width of beam waist
- scotty.fun_general.read_floats_into_list_until(terminator, lines)#
Reads the lines of a file until the string (terminator) is read.
Currently used to read topfile.
Written by NE Bricknell
- Parameters
- Return type
numpy.ndarray[Any, numpy.dtype[numpy.float64]]
- scotty.fun_general.reflector_make(r, t)#
makes relector matrix for mirror using angles in radians
- scotty.fun_general.reflector_make_from_mirrornorm(mirrornorm)#
makes relector matrix for mirror using norm vector for mirror
- scotty.fun_general.rot_trns_make(r)#
rotates R ([1,0,0]) into T ([0,1,0]) using angle in radians
- scotty.fun_general.tilt_trns_RZ_make(t)#
tilts R ([1,0,0]) in to Z ([0,0,1]) using angle in radians
- scotty.fun_general.tilt_trns_TZ_make(t)#
tilts T ([1,0,0]) in to Z ([0,0,1]) using angle in radians
- scotty.fun_general.use_deg_args(func, *args, **kwargs)#
transform args from degrees to radians before calling