fitting.py¶
Different functions for the fitting of vortices
-
fitting.
correlation_coef
(u_data, v_data, u_model, v_model)¶ Calculates the correlation coefficient between two 2D arrays
Parameters: - u_data (ndarray) – velocity u from the data at the proposed window
- v_data (ndarray) – velocity v from the data at the proposed window
- u_model (ndarray) – velocity u from the calculated model
- v_model (ndarray) – velocity v from the calculated model
Returns: correlation
Return type: float
-
fitting.
create_links
(path, vortices_list, output_dir, time_step, output_format)¶ create links: add some links between the accepted.svg file and the detected vortices
Parameters: - path (str) – path of the accepted.svg file
- vortices_list (list) – contains all the detected vortices
- output_dir (str) – directory where the results are written
- time_step (int) – current time_step
- output_format (str) – format for output files (pdf, png …)
Returns: file
Return type: image
-
fitting.
direction_rotation
(vorticity, peaks)¶ Identify the direction of the vortices rotation using the vorticity.
Parameters: - vorticity (ndarray) – 2D array with the computed vorticity
- peaks (list) – list of the detected peaks
Returns: vortices_clockwise, vortices_counterclockwise, arrays containing the direction of rotation for each vortex
Return type: list
-
fitting.
find_peaks
(data, threshold, box_size)¶ Find local peaks in an image that are above above a specified threshold value.
Peaks are the maxima above the “threshold” within a local region. The regions are defined by the “box_size” parameters. “box_size” defines the local region around each pixel as a square box.
Parameters: - data (ndarray) – The 2D array of the image/data.
- threshold (float) – The data value or pixel-wise data values to be used for the detection threshold. A 2D “threshold” must have the same shape as “data”.
- box_size (int) – The size of the local region to search for peaks at every point
Returns: An array containing the x and y pixel location of the peaks and their values.
Return type: list
-
fitting.
fit
(core_radius, gamma, x, y, x_real, y_real, u_data, v_data, u_advection, v_advection, i)¶ Fitting of the Lamb-Oseen Vortex
Parameters: - core_radius (float) – core radius of the vortex
- gamma (float) – circulation contained in the vortex
- x (ndarray) – x position
- y (ndarray) – y position
- x_real (float) – x position of the vortex center
- y_real (float) – y position of the vortex center
- u_data (ndarray) – velocity u from the data at the proposed window
- v_data (ndarray) – velocity v from the data at the proposed window
- u_advection (float) – uniform advection velocity u
- v_advection (float) – uniform advection velocity u
- i (iterator) – current iteration for fitting
Returns: fitted parameters (core_radius, gamma,xcenter,ycenter, u_advection, v_advection…)
Return type: list
-
fitting.
full_fit
(core_radius, gamma, vfield, x_center_index, y_center_index)¶ Full fitting procedure
Parameters: - core_radius (float) – core radius of the vortex
- gamma (float) – circulation contained in the vortex
- vfield (class) – data from the input file
- x_center_index (int) – x index of the vortex center
- y_center_index (int) – y index of the vortex center
Returns: fitted[i], dist
Return type: list
-
fitting.
get_fluctuations
(velocity_matrix, mean, homogeneous_axis)¶ Used when you have a advective velocity along one axis
Parameters: - velocity_matrix (ndarray) – velocity field
- mean (float) – advective velocity to subtract
- homogeneous_axis (str) – False, ‘x’, or ‘y’. The axis which the mean is subtracted
Returns: input array, minus the advective velocity
Return type: ndarray
-
fitting.
get_vortices
(vfield, peaks, vorticity, rmax, correlation_threshold)¶ General routine to check if the detected vortex is a real vortex
Parameters: - vfield (class VelocityField) – data from the input file
- peaks (list) – list of vortices
- vorticity (ndarray) – calculated field
- rmax (float) – maximum radius (adapt it to your data domain)
- correlation_threshold (float) – threshold to detect a vortex (default is 0.75)
Returns: list of detected vortices
Return type: list
-
fitting.
normalize
(velocity_matrix, homogeneous_axis)¶ Normalize with swirling strength
Parameters: - velocity_matrix (ndarray) – velocity field
- homogeneous_axis (str) – False, ‘x’, or ‘y’. The axis which the mean is subtracted
Returns: normalized array
Return type: ndarray
-
fitting.
plot_accepted
(vfield, vortices_list, detection_field, output_dir, time_step, output_format)¶ Plot accepted: display the accepted vortices, with respect to the different criteria (correlation threshold, box size …)
Parameters: - vfield (class VelocityField()) – contains spatial mesh and velocity components
- vortices_list (list) – contains all the detected vortices
- detection_field (ndarray) – detection field (vorticity …)
- output_dir (str) – directory where the results are written
- time_step (int) – current time_step
- output_format (str) – format for output files (pdf, png …)
Returns: popup
Return type: image
-
fitting.
plot_detect
(vortices_counterclockwise, vortices_clockwise, detection_field, flip_axis)¶ Plot detect: display the location and rotation of the vortices
Parameters: - vortices_counterclockwise (list of vortices) – vortices spinning counterclockwise
- vortices_clockwise (list of vortices) – vortices spinning clockwise
- detection_field (ndarray) – detection field (vorticity …)
- flip_axis (bool) – for flipping x/y axis
Returns: popup
Return type: image
-
fitting.
plot_fields
(vfield, detection_field)¶ Plot fields: display the (u,v,w) fields and the vorticity field.
Parameters: - vfield (class VelocityField()) – contains spatial mesh and velocity components
- detection_field (ndarray) – detection field (vorticity …)
Returns: popup
Return type: image
-
fitting.
plot_fit
(x_index, y_index, u_data, v_data, u_model, v_model, xc, yc, core_radius, gamma, u_advection, v_advection, correlation_value, cpt_vortex, subtract_advection_field, output_dir, time_step, output_format)¶ Plot fit
Parameters: - x_index (ndarray) – contains spatial mesh (x direction)
- y_index (ndarray) – contains spatial mesh (y direction)
- u_data (ndarray) – contains velocity data (u component)
- v_data (ndarray) – contains velocity data (v component)
- u_model (ndarray) – contains velocity data (u component)
- v_model (ndarray) – contains velocity data (v component)
- xc (float) – x coordinate of the vortex center
- yc (float) – y coordinate of the vortex center
- core_radius (float) – dimension of the vortex core radius
- gamma (float) – circulation of the vortex
- u_advection (ndarray) – contains velocity data (u component)
- v_advection (ndarray) – contains velocity data (v component)
- cpt_vortex (int) – current n° of the vortex
- subtract_advection_field (bool) – if True, the advection field (u_advection, v_advection) is subtracted
- output_dir (str) – directory where the results are written
- correlation_value (float) – correlation between the vortex and a Lamb-Oseen model
- time_step (int) – current time_step
- output_format (str) – format for output files (pdf, png …)
Returns: image file
Return type: image
-
fitting.
plot_quiver
(x_index, y_index, u_data, v_data, detection_field)¶ Plot quiver: display a specific (x,y) location with vector fields.
Parameters: - x_index (ndarray) – contains spatial mesh (x direction)
- y_index (ndarray) – contains spatial mesh (y direction)
- u_data (ndarray) – contains velocity data (u component)
- v_data (ndarray) – contains velocity data (v component)
- detection_field (ndarray) – detection field (vorticity …)
Returns: popup
Return type: image
-
fitting.
plot_vortex
(vfield, vortices_list, output_dir, time_step, output_format)¶ Plot vortex: plot a vortex and its corresponding vortex model
Parameters: - vfield (class VelocityField()) – contains spatial mesh and velocity components
- vortices_list (list) – contains all the detected vortices
- output_dir (str) – directory where the results are written
- time_step (int) – current time_step
- output_format (str) – format for output files (pdf, png …)
Returns: file
Return type: image
-
fitting.
velocity_model
(core_radius, gamma, x_real, y_real, u_advection, v_advection, x, y)¶ Generates the Lamb-Oseen vortex velocity array
Parameters: - core_radius (float) – core radius of the vortex
- gamma (float) – circulation contained in the vortex
- x_real (float) – relative x position of the vortex center
- y_real (float) – relative y position of the vortex center
- u_advection (float) – u advective velocity at the center
- v_advection (float) – v advective velocity at the center
- x (float) –
- y (float) –
Returns: velx, vely
Return type: float
-
fitting.
window
(vfield, x_center_index, y_center_index, dist)¶ Defines a window around (x; y) coordinates
Parameters: - vfield (ndarray) – full size velocity field
- x_center_index (int) – box center index (x)
- y_center_index (int) – box center index (y)
- dist – size of the vortex (mesh units)
- dist – int
Returns: cropped arrays for x, y, u and v
Return type: 2D arrays of floats