ShockOscillationAnalysis.slice_list_generator package

Submodules

ShockOscillationAnalysis.slice_list_generator.list_generation_tools module

Created on Wed Feb 28 12:28:27 2024

@author: Ahmed H. Hanfy

ShockOscillationAnalysis.slice_list_generator.list_generation_tools.GenerateIndicesList(total_n_files: int, files: list[int, int] = [0, 0], every_n_files: int = 1, log_dirc: str = '') tuple[range, int]

Generate a list of indices based on the specified range and step.

Parameters:
  • total_n_files (int): The total number of available files.

  • files (list[int, int], optional): A list specifying the start and end files (default is [0, 0]).

  • every_n_files (int, optional): Step value to determine the frequency of indices (default is 1).

  • log_dirc (str): log file directory.

Returns:

tuple[range, int]: A tuple containing a range object of the indices and the total number of images.

Note

  • If files list is empty or contains values beyond the available range, defaults will be used.

  • If files is a list with two integers, it determines the start and end of the range.

  • If files is a single integer greater than zero, it determines the end of the range.

  • If files is greater than the total number of files, a warning is printed and total_n_files is used as the end.

  • The function calculates the number of images based on the specified range and step.

Example:
>>> indices, num_images = GenerateIndicesList(100, [10, 50], 5)
>>> print(list(indices))
[10, 15, 20, 25, 30, 35, 40, 45]
>>> print(num_images)
8
ShockOscillationAnalysis.slice_list_generator.list_generation_tools.genratingRandomNumberList(ShockAngleSamples: int, n1: int, log_dirc: str = '') list[int]

Generate a list of random indices based on the given sample size.

Parameters:
  • ShockAngleSamples (int): The desired number of shock angle samples.

  • n1 (int): The total number of files available.

  • log_dirc (str): log file directory.

Returns:

list: A list of randomly selected indices.

Note

  • If ShockAngleSamples is greater than n1, it will be set to n1.

  • Prints a warning if ShockAngleSamples is adjusted to match n1.

Example:
>>> random_indices = genratingRandomNumberList(10, 15)
>>> print(random_indices)
[3, 7, 12, 1, 9, 4, 0, 8, 5, 2]

ShockOscillationAnalysis.slice_list_generator.slice_list_generator module

Created on Sun Dec 3 16:45:35 2023

@author: Ahmed H. Hanfy

class ShockOscillationAnalysis.slice_list_generator.slice_list_generator.SliceListGenerator(f: int, D: float = 1, pixelScale: float = 1)

Bases: SOA

GenerateSlicesArray(path: str, scale_pixels: bool = True, full_img_width: bool = False, slice_loc: int = 0, slice_thickness: int | list[int, str] = 0, shock_angle_samples=30, inclination_est_info: list[int, tuple, tuple] = [], preview: bool = True, angle_samples_review=10, output_directory: str = '', comment: str = '', **kwargs) tuple[ndarray[int], int, dict, float]

Generate a sequence of image slices for single horizontal line shock wave analysis. This function imports a sequence of images to perform an optimized analysis by extracting a single pixel slice from each image as defined by the user, appending them together, and generating a single image where each row represents a snapshot.

Parameters:
  • path (str): Directory path containing the sequence of image files.

  • scale_pixels (bool): Whether to scale the pixels. Default is True.

  • full_img_width (bool): Whether to use the full image width for slicing. Default is False.

  • slice_loc (int): Location of the slice.

  • slice_thickness (int): Thickness of the slice.

  • shock_angle_samples (int): Number of samples to use for shock angle estimation. Default is 30.

  • inclination_est_info (list[int, tuple, tuple]): Information for inclination estimation. Default is an empty list.

  • preview (bool): Whether to display a preview of the investigation domain before rotating. Default is True.

  • angle_samples_review (int): Number of samples to review for angle estimation. Default is 10.

  • output_directory (str): Directory to store the output images. Default is an empty string.

  • comment (str): Comment to include in the output filename. Default is an empty string.

  • **kwargs: Additional arguments for fine-tuning/Automate the function.

Returns:
  • tuple:
    • numpy.ndarray: Concatenated image slices.

    • int: Number of images imported.

    • dict: Working range details.

    • float: Pixel scale.

Note

  • The function assumes the input images are in RGB format.

  • The kwargs parameter can include:
    • Ref_x0 (list[int, int]): Reference x boundaries.for scaling

    • Ref_y0 (int): Reference y datum (zero y location)

    • Ref_y1 (int): slice location (The scanning line, y-center of rotation)

    • avg_shock_angle (float): Average shock angle. (if known, to skip average shock inc check)

    • avg_shock_loc (int): Average shock location. (if known, x-center of rotation)

    • sat_vr (int | list[int,’str’]): Shock Angle Test Vertical Range (If not provided the vertical renge will be equal to the slice_thickness, could be provided as number then value will be added equally to upper and lower the traking location in pixels, it also can be added as list [upper bound, lower bound, unit(optional)] in current version unit should match the universal units 'px', etc. if the unit not provided the defualt 'px' will be considered)

    • n_files (int): Number of files to import

    • within_range (tuple[int, int]): Range of files to import (start, end)

    • every_n_files (int): Step for file import.

    • Inclind angle tracking parameters:
      • Confidance: nPnts, conf_interval, residual_preview

      • Preview: avg_preview_mode, points_opacity, points_size, avg_lin_color

      • Output Background: op_bg_path, bg_x_crop, bg_y_crop, bg_90rotate, bg_resize

Steps:
  1. Define reference vertical boundaries (for scaling).

  2. Define reference horizontal line (slice shifted by HLP from reference).

  3. Optionally define the estimated line of shock.

  4. Run shock tracking function within the selected slice to define the shock angle (if step 3 is valid).

  5. Generate shock rotating matrix (if step 3 is valid).

  6. Import files, slice them, and store the generated slices list into an image.

Example:
>>> img_list, n, working_range, pixel_scale = GenerateSlicesArray(r'/path/to/*.ext', 
                                                                  slice_loc=10, 
                                                                  slice_thickness=5)
ImportingFiles(pathlist: list[str], indices_list: list[int], n_images: int, imgs_shp: tuple[int], x_range: tuple[int], tk: tuple[int], M: ndarray[float]) tuple[ndarray, int]

Import images from specified paths, and return a concatenated image list.

Parameters:
  • pathlist (list): List of paths to image files.

  • indices_list (list): List of indices specifying which images to import from pathlist.

  • n_images (int): Total number of images to import.

  • imgs_shp (tuple): Tuple specifying the shape of the images to be resized to (height, width).

  • x_range (tuple): Tuple specifying the range of x-values to crop from the images (start, end).

  • tk (tuple): Tuple specifying the range of y-values to crop from the images (start, end).

  • M (numpy.ndarray): 2x3 transformation matrix for image rotation.

Returns:
  • numpy.ndarray: Concatenated image list.

  • int: Number of imported images

Note

  • Requires the OpenCV (cv2) and NumPy libraries.

  • Assumes the input images are RGB.

IntersectionPoint(M: list[float], A: list[float], Ref: list[tuple, tuple], log_dirc: str = '') tuple[tuple[int, int]]

Calculate the intersection point between two lines.

Parameters:
  • M (list): List containing slopes of the two lines.

  • A (list): List containing y-intercepts of the two lines.

  • Ref (list): List containing reference points for each line.

  • log_dirc (str): log file directory.

Returns:
tuple:
  • A tuple containing: Pint (tuple): Intersection point coordinates (x, y).

Example:
>>> from __importImages import importSchlierenImages
>>> instance = importSchlierenImages(f)
>>> slopes = [0.5, -2]
>>> intercepts = [2, 5]
>>> references = [(0, 2), (0, 5)]
>>> intersection, angles = instance.IntersectionPoint(slopes, intercepts, references)
>>> print(intersection, angles)

Note

  • The function calculates the intersection point and angles between two lines specified by their slopes and y-intercepts.

  • Returns the intersection point coordinates and angles of the lines in degrees.