3.2.1. broh5.lib.utilities
Module for utility methods:
Get height and with of a screen.
Convert hdf tree to a nested dictionary.
Get data-type and value from a dataset in a hdf file.
Convert 1d/2d array to a table format.
Save 2d array to an image.
Save 1d/2d array to a csv file.
Save/get path of the last opened folder
Functions:
Get the height and width of the current screen. |
|
|
Convert an HDF5 file structure to a nested dictionary. |
|
Get data type and value from a specified dataset in an HDF5 file. |
|
Check if the dataset at a specified path is an external link and whether it's broken. |
|
Check if a dataset is compressed, including checking for external compression filters. |
|
Format a NumPy array into a structure suitable for displaying as a table using NiceGUI framework. |
|
Save a 2D array as an image file. |
|
Save a 1D or 2D NumPy array to a CSV file. |
Get path to save a config file depending on the OS system. |
|
|
Save data (dictionary) to the config file (json format). |
Load the config file. |
- broh5.lib.utilities.get_height_width_screen()[source]
Get the height and width of the current screen.
- Returns:
tuple – A tuple of (screen height, screen width).
- broh5.lib.utilities.hdf_tree_to_dict(hdf_file)[source]
Convert an HDF5 file structure to a nested dictionary.
- Parameters:
hdf_file (str) – Path to the HDF5 file.
- Returns:
dict or str – A nested dictionary representing the structure of the HDF5 file, or a string describing an error if one occurs.
- broh5.lib.utilities.get_hdf_data(file_path, dataset_path)[source]
Get data type and value from a specified dataset in an HDF5 file.
- Parameters:
file_path (str) – Path to the HDF5 file.
dataset_path (str) – Path to the dataset within the HDF5 file.
- Returns:
tuple – A tuple containing the data type and the value of the dataset.
- broh5.lib.utilities.check_external_link(file_path, dataset_path)[source]
Check if the dataset at a specified path is an external link and whether it’s broken.
- Parameters:
file_path (str) – Path to the HDF5 file.
dataset_path (str) – Path to the dataset within the HDF5 file.
- Returns:
tuple – A tuple containing a boolean indicating if it’s an external link, a boolean indicating if the link is broken, and a message string.
- broh5.lib.utilities.check_compressed_dataset(file_path, dataset_path)[source]
Check if a dataset is compressed, including checking for external compression filters.
- Parameters:
file_path (str) – Path to the HDF5 file.
dataset_path (str) – Path to the dataset within the HDF5 file.
- Returns:
tuple – A tuple containing two booleans indicating if the dataset is compressed and if it uses external compression filters, and a message string.
- broh5.lib.utilities.format_table_from_array(data)[source]
Format a NumPy array into a structure suitable for displaying as a table using NiceGUI framework.
- Parameters:
data (ndarray) – The NumPy array to format.
- Returns:
tuple – A tuple containing the rows and columns formatted for the table.
- broh5.lib.utilities.format_statistical_info(image)[source]
Get statistical information of a 2d array and format the output as a Nicegui table object.
- Parameters:
image (ndarray) – NumPy array to format.
- Returns:
tuple – A tuple containing the rows and columns formatted for the table.
- broh5.lib.utilities.save_image(file_path, mat)[source]
Save a 2D array as an image file.
- Parameters:
file_path (str) – Path where the image will be saved.
mat (ndarray) – 2D array to be saved as an image.
- Returns:
None or str – Returns None if successful, or a string message if an error occurs.
- broh5.lib.utilities.save_table(file_path, data)[source]
Save a 1D or 2D NumPy array to a CSV file.
- Parameters:
file_path (str) – Path where the CSV file will be saved.
data (ndarray) – The 1D or 2D array to be saved.
- Returns:
None or str – Returns None if successful, or a string message if an error occurs.
- broh5.lib.utilities.get_config_path()[source]
Get path to save a config file depending on the OS system.
- broh5.lib.utilities.save_config(data)[source]
Save data (dictionary) to the config file (json format).
- broh5.lib.utilities.get_image_roi(x, y, mat, zoom=2)[source]
Get the square ROI (Region of Interest) of an image given a zoom value and the region center.
- Parameters:
x (int) – x-center of the squared ROI
y (int) – y-center of the squared ROI
mat (ndarray) – 2d array.
zoom (float) – Zoom-in value of the ROI.
- Returns:
roi (ndarray) – ROI of the image
x_start (int) – x-start of the ROI
y_start (int) – y_start of the ROI
size (int) – Size of the ROI.