idstools.compute.common¶
This is a common module which has mathematical or physics functions
Module Contents¶
-
idstools.compute.common.calcw(wt, rt, lambda_ray, freq=
np.double(170000000000.0))[source]¶ The function calculates the width of a laser beam based on its initial width, curvature radius, length along the ray, and frequency.
- Parameters:¶
- wt¶
width at the start point of the ray in meters
- rt¶
Curvature radius at start point in meters. If rt is negative, the beam will pass through the focus, and if it is positive, the beam will purely diverge. The focus is located at lambda_ray =-rt
- lambda_ray¶
length along the ray in meters
- freq=
np.double(170000000000.0)¶ wave frequency in Hz (not rad/s)
- Returns:¶
the value of the beam width w at a given length along the ray, calculated based on the input parameters of width and curvature radius at the start point, the length along the ray, and the frequency of the wave.
Note
calculates beam width for given w,Rcur and length along ray (lambda_ray)
wt, rt width and curvature radius at start point in m
rt < 0 : beam will pass focus, >0 : purely diverging
the focus is at lambda_ray = -rt
lambda_ray length along ray in m
freq: wave frequency im Hz (not rad/s)
- idstools.compute.common.cyl2xyz(rcyl)[source]¶
The function cyl2xyz converts cylindrical coordinates to Cartesian coordinates.
- Parameters:¶
- rcyl¶
rcyl is a numpy array containing cylindrical coordinates (r, theta, z) of points in 3D space. The function cyl2xyz converts these cylindrical coordinates to Cartesian coordinates (x, y, z) and returns a numpy array of the same shape as rcyl.
- Returns:¶
The function cyl2xyz returns a numpy array with the same shape as the input rcyl array, but with the cylindrical coordinates converted to Cartesian coordinates.
- idstools.compute.common.ell_on_wall(xpout, w1, w2, gamma, e_k, wall2d)[source]¶
This function calculates the center and generating vectors of an ellipse on a 2D polygon given certain input parameters.
Note
calculates ellipses on wall segment input - xpout array of data type xp_dt (as defined in routine line_polygon_intersection) - w1,w2 widths of beam at cross section (calculated with calcw) - gamma rotation of the ellipse - e_k unit vector direction of ray - wall2d R,z values of Polygone output - rl center of the Ellipse (R*Phi [m], l(ength along polygone) [m] - g1l,g2l generating vectors of the ellips (not orthogonal) - Ellipse rl + g1l*cos(t) + g2l*sin(t) - xpout,w1,w2,gamma are assumed to have the same shape - e_k has the same shape but is a 3d vector - rl,g1l,g2l same shape, 2d vectors
- idstools.compute.common.find_maxima(y)[source]¶
Find the indices of local maxima in a 1D array.
A point is considered a local maximum if it is higher than its neighbors at distances t = len(y)//50 and immediate neighbors.
- idstools.compute.common.find_minima(y)[source]¶
Find the indices of local minima in a 1D array.
A point is considered a local minimum if it is lower than its neighbors at distances t = len(y)//50 and immediate neighbors.
- idstools.compute.common.find_nearest(a, a0)[source]¶
Find the element in an n-dimensional array closest to a scalar value.
- idstools.compute.common.findfwhm(x, y, maxind, lowbnd, uppbnd)[source]¶
Calculate the Full Width at Half Maximum (FWHM) of a peak in a dataset.
The FWHM is the width of the curve at half the maximum height of a peak. This function finds the x-axis span between the two points at half the peak height.
- idstools.compute.common.get_closest_of_given_value_from_array(array: numpy.ndarray, value: float) None | tuple[source]¶
Find the index of the element in the array that is closest to the given value using the minimum absolute difference.
- Parameters:¶
- array: numpy.ndarray¶
A NumPy array of numbers.
- value: float¶
The value to which we want to find the nearest element in the array.
- Returns:¶
The function get_closest_of_given_value_from_array returns a tuple containing the index of the element in the input array that is closest to the input value, and the value of that element. If the input array is None or empty, the function returns None.
-
idstools.compute.common.get_conductor_outline(conductor, skip=
1)[source]¶ Extract inner and outer contour coordinates for coil conductor cross-sections.
This function computes the inner and outer boundary coordinates of a coil conductor by analyzing the cross-section geometry and applying the maximum normal offset from the conductor centerline using a three-point algorithm that uses middle points from three consecutive points.
This function works with conductors from IDS that use the coil_conductor structure reference (e.g., tf, coils_non_axisymmetric).
- Parameters:¶
- conductor¶
A conductor object containing elements and cross_section data from the IMAS coil data structure (structure reference: coil_conductor).
- skip=
1¶ Sampling rate for points. If skip=1 (default), use all points. If skip=10, use every 10th point for faster computation. Useful for visualization when high precision is not required.
- Returns:¶
A dictionary with the following structure:
{ 'inner': {'r': list, 'z': list}, 'outer': {'r': list, 'z': list} }where:
’inner’ contains the inner boundary coordinates (R, Z)
’outer’ contains the outer boundary coordinates (R, Z)
- Return type:¶
Notes
Only processes elements with type 1 (line segment)
Only handles cross-sections with geometry_type == 1 (polygon outline)
Selects middle points of non-collinear triplets
Uses the maximum normal coordinate to determine conductor thickness
Returns empty lists if no valid cross-section data is found
Higher skip values reduce computation time but lower outline resolution
- idstools.compute.common.get_middle_element_from_array(array: numpy.ndarray) None | tuple[source]¶
The “get_middle_element_from_array” function returns the index and value of the middle element in a given numpy array.
- Parameters:¶
- array: numpy.ndarray¶
A NumPy array for which we want to find the middle element.
- Returns:¶
The function get_middle_element_from_array takes a numpy array as input and returns a tuple containing the index and value of the middle element of the array. If the input array is None or empty, the function returns None.
- idstools.compute.common.get_nearest_time(time_array: numpy.ndarray, requested_time: float) tuple[int, float][source]¶
The function get_nearest_time takes an array of time values and a requested time, and returns the index and value of the nearest time in the array to the requested time.
- Parameters:¶
- time_array: numpy.ndarray¶
The time_array parameter is a numpy array containing a list of time values.
- requested_time: float¶
The requestedTime parameter is the time value that you want to find the nearest value to in the time_array.
- Returns:¶
The function get_nearest_time returns a tuple containing the time index and time value.
-
idstools.compute.common.line_polygon_intersection(line_p, line_dir, polygon_data, close=
True)[source]¶ This function calculates the intersection points between a line and a polygon.
- Parameters:¶
- line_p¶
A numpy array representing the starting point of the line segment(s) to be intersected with the polygon. It has shape (n,3) where n is the number of line segments and each row represents the x, y, z coordinates of the starting point of the line segment.
- line_dir¶
The direction vector(s) of the line(s) for which intersection with the polygon is being calculated. It is a numpy array of shape (n,3) where n is the number of lines and each row represents the direction vector of a line. polygon_data: The coordinates of the vertices of a polygon in 3D space.
- close=
True¶ A boolean parameter that determines whether the polygon is closed or not. If set to True (default), the polygon is assumed to be closed, otherwise, it is assumed to be open. Defaults to True
- Returns:¶
n_xp and xp_data.
- Return type:¶
two arrays
- idstools.compute.common.xyz2cyl(rvec)[source]¶
The function converts a set of 3D Cartesian coordinates to cylindrical coordinates.
- Parameters:¶
- rvec¶
rvec is a numpy array containing the coordinates of points in 3D space in the Cartesian coordinate system (x, y, z). The function xyz2cyl converts these coordinates to cylindrical coordinates (r, phi, z) and returns them as a numpy array with the same shape as the rvec
- Returns:¶
The function xyz2cyl returns a numpy array rcyl which contains the cylindrical coordinates (radius, azimuthal angle, and height) of the input vector rvec which is in Cartesian coordinates.
- idstools.compute.common.logger¶