sarcasm.structure
Attributes
Classes
Class to analyze sarcomere morphology. |
Module Contents
- class sarcasm.structure.Structure(filepath: str | os.PathLike, restart: bool = False, channel: int | None | Literal['RGB'] = None, auto_save: bool = True, use_gui: bool = False, device: torch.device | Literal['auto'] = 'auto', **info: Dict[str, Any])[source]
Bases:
sarcasm.core.SarcAsM
Class to analyze sarcomere morphology.
- data
A dictionary with structure data.
- Type:
dict
- __get_structure_data_file(is_temp_file: bool = False) str
Returns the path to the structure data file.
- Parameters:
is_temp_file (bool, optional) – If True, returns the path to a temporary file. This temporary file is used to prevent creating corrupted data files due to aborted operations (e.g., exceptions or user intervention). The temporary file can be committed to a final file by renaming it. Default is False.
- Returns:
The path to the structure data file, either temporary or final.
- Return type:
str
- store_structure_data(override: bool = True) None [source]
Store structure data in a JSON file.
- Parameters:
override (bool, optional) – If True, override the file.
- _load_structure_data() None [source]
Load structure data from the final data file; fall back to the temporary file if needed. :raises Exception: If no valid structure data could be loaded.
- detect_sarcomeres(frames: str | int | List[int] | numpy.ndarray = 'all', model_path: str = None, max_patch_size: Tuple[int, int] = (1024, 1024), normalization_mode: str = 'all', clip_thres: Tuple[float, float] = (0.0, 99.98), progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm())[source]
Predict sarcomeres (Z-bands, mbands, distance, orientation) with U-Net.
- Parameters:
frames (Union[str, int, List[int], np.ndarray]) – Frames for sarcomere detection (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). Defaults to ‘all’.
model_path (str, optional) – Path of trained network weights for U-Net. Default is None.
max_patch_size (tuple of int, optional) – Maximal patch dimensions for convolutional neural network (n_x, n_y). Default is (1024, 1024).
normalization_mode (str, optional) – Mode for intensity normalization for 3D stacks prior to prediction (‘single’: each image individually, ‘all’: based on histogram of full stack, ‘first’: based on histogram of first image in stack). Default is ‘all’.
clip_thres (tuple of float, optional) – Clip threshold (lower / upper) for intensity normalization. Default is (0., 99.8).
progress_notifier (ProgressNotifier, optional) – Progress notifier for inclusion in GUI. Default is ProgressNotifier.progress_notifier_tqdm().
- Return type:
None
- detect_z_bands_fast_movie(model_path: str | None = None, max_patch_size: Tuple[int, int, int] = (32, 256, 256), normalization_mode: str = 'all', clip_thres: Tuple[float, float] = (0.0, 99.8), progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm()) None [source]
Predict sarcomere z-bands with 3D U-Net for high-speed movies for improved temporal consistency.
- Parameters:
model_path (str, optional) – Path of trained network weights for 3D U-Net. Default is None.
max_patch_size (tuple of int, optional) – Maximal patch dimensions for convolutional neural network (n_frames, n_x, n_y). Dimensions need to be divisible by 16. Default is (32, 256, 256).
normalization_mode (str, optional) – Mode for intensity normalization for 3D stacks prior to prediction (‘single’: each image individually, ‘all’: based on histogram of full stack, ‘first’: based on histogram of first image in stack). Default is ‘all’.
clip_thres (tuple of float, optional) – Clip threshold (lower / upper) for intensity normalization. Default is (0., 99.8).
progress_notifier (ProgressNotifier, optional) – Progress notifier for inclusion in GUI. Default is ProgressNotifier.progress_notifier_tqdm().
- Return type:
None
- analyze_cell_mask(frames: str | int | List[int] | numpy.ndarray = 'all', threshold: float = 0.1) None [source]
Analyzes the area occupied by cells in the given image(s) and calculates the average cell intensity and cell area ratio.
- Parameters:
threshold (float, optional) – Threshold value for binarizing the cell mask image. Pixels with intensity above threshold are considered cell. Defaults to 0.1.
frames ({'all', int, list, np.ndarray}, optional) – Frames for z-band analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). Defaults to ‘all’.
- analyze_z_bands(frames: str | int | List[int] | numpy.ndarray = 'all', threshold: float = 0.5, min_length: float = 0.2, median_filter_radius: float = 0.2, theta_phi_min: float = 0.4, a_min: float = 0.3, d_max: float = 3.0, d_min: float = 0.0, progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm()) None [source]
Segment and analyze sarcomere z-bands.
- Parameters:
frames ({'all', int, list, np.ndarray}, optional) – Frames for z-band analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). Defaults to ‘all’.
threshold (float, optional) – Threshold for binarizing z-bands prior to labeling (0 - 1). Defaults to 0.1.
min_length (float, optional) – Minimal length of z-bands; smaller z-bands are removed (in µm). Defaults to 0.5.
median_filter_radius (float, optional) – Radius of kernel to smooth sarcomere orientation field. Default is 0.2 µm.
theta_phi_min (float, optional) – Minimal cosine of the angle between the pointed z-band vector and the connecting vector between ends of z-bands. Smaller values are not recognized as connections (for lateral alignment and distance analysis). Defaults to 0.25.
a_min (float, optional) – Minimal lateral alignment between z-band ends to create a lateral connection. Defaults to 0.3.
d_max (float, optional) – Maximal distance between z-band ends (in µm). Z-band end pairs with larger distances are not connected (for lateral alignment and distance analysis). Defaults to 5.0.
d_min (float, optional) – Minimal distance between z-band ends (in µm). Z-band end pairs with smaller distances are not connected. Defaults to 0.25.
progress_notifier (ProgressNotifier) – Wraps progress notification, default is progress notification done with tqdm
- analyze_sarcomere_vectors(frames: str | int | List[int] | numpy.ndarray = 'all', threshold_mbands: float = 0.5, median_filter_radius: float = 0.25, linewidth: float = 0.2, interp_factor: int = 0, slen_lims: Tuple[float, float] = (1, 3), threshold_sarcomere_mask=0.1, backend='loky', progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm()) None [source]
Extract sarcomere orientation and length vectors.
- Parameters:
frames ({'all', int, list, np.ndarray}, optional) – frames for sarcomere vector analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). Defaults to ‘all’.
threshold_mbands (float, optional) – Threshold to binarize sarcomere M-bands. Lower values might result in more false-positive sarcomere vectors. Defaults to 0.2.
median_filter_radius (float, optional) – Radius of kernel to smooth orientation field before assessing orientation at M-points, in µm (default 0.25 µm).
linewidth (float, optional) – Line width of profile lines to analyze sarcomere lengths, in µm (default is 0.3 µm).
interp_factor (int, optional) – Interpolation factor for profiles to calculate sarcomere length. Default to 4.
slen_lims (tuple of float, optional) – Sarcomere size limits in µm (default is (1, 3) µm).
threshold_sarcomere_mask (float) – Threshold to binarize sarcomere masks. Defaults to 0.1.
backend (str, optional) – Backend for parallelization of profile processing. Defaults to ‘loky’.
progress_notifier (ProgressNotifier) – Wraps progress notification, default is progress notification done with tqdm
- Returns:
sarcomere_orientation_points (np.ndarray) – Sarcomere orientation values at midline points.
sarcomere_length_points (np.ndarray) – Sarcomere length values at midline points.
- analyze_myofibrils(frames: str | int | List[int] | numpy.ndarray | None = None, ratio_seeds: float = 0.1, persistence: int = 3, threshold_distance: float = 0.5, n_min: int = 4, median_filter_radius: float = 0.5, progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm()) None [source]
Estimate myofibril lines by line growth algorithm and analyze length and curvature.
- Parameters:
frames ({'all', int, list, np.ndarray}, optional) – frames for myofibril analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). If None, frames from sarcomere vector analysis are used. Defaults to None.
ratio_seeds (float, optional) – Ratio of sarcomere vector used as seeds for line growth. Defaults to 0.1.
persistence (int, optional) – Persistence of line (average vector length and orientation for prior estimation), needs to be > 0. Defaults to 3.
threshold_distance (float, optional) – Maximal distance for nearest neighbor estimation (in micrometers). Defaults to 0.3.
n_min (int, optional) – Minimal number of sarcomere line segments per line. Shorter lines are removed. Defaults to 5.
median_filter_radius (float, optional) – Filter radius for smoothing myofibril length map (in micrometers). Defaults to 0.5.
progress_notifier (ProgressNotifier) – Wraps progress notification, default is progress notification done with tqdm
- analyze_sarcomere_domains(frames: str | int | List[int] | numpy.ndarray | None = None, d_max: float = 3, cosine_min: float = 0.65, leiden_resolution: float = 0.06, random_seed: int = 42, area_min: float = 20.0, dilation_radius: float = 0.3, progress_notifier: bio_image_unet.progress.ProgressNotifier = ProgressNotifier.progress_notifier_tqdm()) None [source]
Cluster sarcomeres into domains based on their spatial and orientational properties using the Leiden algorithm for community detection.
- Parameters:
frames ({'all', int, list, np.ndarray}, optional) – frames for domain analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames). If None, frames from sarcomere vector analysis are used. Defaults to None.
d_max (float) – Max. distance threshold for creating a network edge between vector ends
cosine_min (float) – Minimal absolute cosine between vector angles for creating a network edge between vector ends
leiden_resolution (float, optional) – Control parameter for domain size. If resolution is small, the algorithm favors larger domains. Greater resolution favors smaller domains. Defaults to 0.05.
random_seed (int, optional) – Random seed for Leiden algorithm, to ensure reproducibility. Defaults to 2.
area_min (float, optional) – Minimal area of domains/clusters (in µm^2). Defaults to 50.0.
dilation_radius (float, optional) – Dilation radius for refining domain area masks, in µm. Defaults to 0.3.
progress_notifier (ProgressNotifier) – Wraps progress notification, default is progress notification done with tqdm
- _grow_lois(frame: int = 0, ratio_seeds: float = 0.1, persistence: int = 2, threshold_distance: float = 0.3, random_seed: None | int = None) None [source]
Find LOIs (lines of interest) using a line growth algorithm. The parameters **lims can be used to filter LOIs.
- Parameters:
frame (int, optional) – Frame to select frame. Selects i-th frame of frames specified in sarcomere vector analysis. Defaults to 0.
ratio_seeds (float, optional) – Ratio of sarcomere vectors to take as seeds for line growth. Default 0.1.
persistence (int, optional) – Persistence of line (average vector length and orientation for prior estimation). Defaults to 2.
threshold_distance (float, optional) – Maximal distance for nearest neighbor estimation. Defaults to 0.5.
random_seed (int, optional) – Random seed for reproducibility. Defaults to None.
- _filter_lois(number_lims: Tuple[int, int] = (10, 100), length_lims: Tuple[float, float] = (0, 200), sarcomere_mean_length_lims: Tuple[float, float] = (1, 3), sarcomere_std_length_lims: Tuple[float, float] = (0, 1), midline_mean_length_lims: Tuple[float, float] = (0, 50), midline_std_length_lims: Tuple[float, float] = (0, 50), midline_min_length_lims: Tuple[float, float] = (0, 50)) None [source]
Filters Lines of Interest (LOIs) based on various geometric and morphological criteria.
- Parameters:
number_lims (tuple of int, optional) – Limits of sarcomere numbers in LOI (min, max). Defaults to (10, 100).
length_lims (tuple of float, optional) – Limits for LOI lengths (in µm) (min, max). Defaults to (0, 200).
sarcomere_mean_length_lims (tuple of float, optional) – Limits for mean length of sarcomeres in LOI (min, max). Defaults to (1, 3).
sarcomere_std_length_lims (tuple of float, optional) – Limits for standard deviation of sarcomere lengths in LOI (min, max). Defaults to (0, 1).
midline_mean_length_lims (tuple of float, optional) – Limits for mean length of the midline in LOI (min, max). Defaults to (0, 50).
midline_std_length_lims (tuple of float, optional) – Limits for standard deviation of the midline length in LOI (min, max). Defaults to (0, 50).
midline_min_length_lims (tuple of float, optional) – Limits for minimum length of the midline in LOI (min, max). Defaults to (0, 50).
- _hausdorff_distance_lois(symmetry_mode: str = 'max') None [source]
Compute Hausdorff distances between all good LOIs.
- Parameters:
symmetry_mode (str, optional) – Choose ‘min’ or ‘max’, whether min/max(H(loi_i, loi_j), H(loi_j, loi_i)). Defaults to ‘max’.
- _cluster_lois(distance_threshold_lois: float = 40, linkage: str = 'single') None [source]
Agglomerative clustering of good LOIs using predefined Hausdorff distance matrix using scikit-learn.
- Parameters:
distance_threshold_lois (float, optional) – The linkage distance threshold above which clusters will not be merged. Defaults to 40.
linkage ({'complete', 'average', 'single'}, optional) – Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observations. The algorithm will merge the pairs of clusters that minimize this criterion. - ‘average’ uses the average of the distances of each observation of the two sets. - ‘complete’ or ‘maximum’ linkage uses the maximum distances between all observations of the two sets. - ‘single’ uses the minimum of the distances between all observations of the two sets. Defaults to ‘single’.
- _fit_straight_line(add_length=1, n_lois=None)[source]
Fit linear lines to cluster points
- Parameters:
add_length (float) – Elongate line at end with add_length (in length unit)
n_lois (int) – If int, only n longest LOIs are saved. If None, all are saved.
- create_loi_data(line: numpy.ndarray, linewidth: float = 0.65, order: int = 0, export_raw: bool = False) None [source]
Extract intensity kymograph along LOI and create LOI file from line.
- Parameters:
line (np.ndarray) – Line start and end coordinates ((start_x, start_y), (end_x, end_y)) or list of segments [(x0, y0), (x1, y1), (x2, y2), …]
linewidth (float, optional) – Width of the scan in µm, perpendicular to the line. Defaults to 0.65.
order (int, optional) – The order of the spline interpolation, default is 0 if image.dtype is bool and 1 otherwise. The order has to be in the range 0-5. See skimage.transform.warp for details. Defaults to 0.
export_raw (bool, optional) – If True, intensity kymograph along LOI from raw microscopy image is additionally stored. Defaults to False.
- detect_lois(frame: int = 0, n_lois: int = 4, ratio_seeds: float = 0.1, persistence: int = 4, threshold_distance: float = 0.5, mode: str = 'longest_in_cluster', random_seed: int | None = None, number_lims: Tuple[int, int] = (10, 50), length_lims: Tuple[float, float] = (0, 200), sarcomere_mean_length_lims: Tuple[float, float] = (1, 3), sarcomere_std_length_lims: Tuple[float, float] = (0, 1), midline_mean_length_lims: Tuple[float, float] = (0, 50), midline_std_length_lims: Tuple[float, float] = (0, 50), midline_min_length_lims: Tuple[float, float] = (0, 50), distance_threshold_lois: float = 40, linkage: str = 'single', linewidth: float = 0.65, order: int = 0, export_raw: bool = False) None [source]
Detects Regions of Interest (LOIs) for tracking sarcomere Z-band motion and creates kymographs.
This method integrates several steps: growing LOIs based on seed vectors, filtering LOIs based on specified criteria, clustering LOIs, fitting lines to LOI clusters, and extracting intensity profiles to generate kymographs.
- Parameters:
frame (int) – The index of the frame to select for analysis.
n_lois (int) – Number of LOIs.
ratio_seeds (float) – Ratio of sarcomere vectors to take as seed vectors for initiating LOI growth.
persistence (int) – Persistence parameter influencing line growth direction and termination.
threshold_distance (float) – Maximum distance for nearest neighbor estimation during line growth.
mode (str) – Mode for selecting LOIs from identified clusters. - ‘fit_straight_line’ fits a straight line to all midline points in the cluster. - ‘longest_in_cluster’ selects the longest line of each cluster, also allowing curved LOIs. - ‘random_from_cluster’ selects a random line from each cluster, also allowing curved LOIs. - ‘random_line’ selects a set of random lines that fulfil the filtering criteria.
random_seed (int, optional) – Random seed for selection of random starting vectors for line growth algorithm, for reproducible outcomes. If None, no random seed is set, and outcomes in every run will differ.
number_lims (tuple of int) – Limits for the number of sarcomeres within an LOI (min, max).
length_lims (tuple of float) – Length limits for LOIs (in µm) (min, max).
sarcomere_mean_length_lims (tuple of float) – Limits for the mean length of sarcomeres within an LOI (min, max).
sarcomere_std_length_lims (tuple of float) – Limits for the standard deviation of sarcomere lengths within an LOI (min, max).
midline_mean_length_lims (tuple of float) – Limits for the mean length of the midline of vectors in LOI (min, max).
midline_std_length_lims (tuple of float) – Limits for the standard deviation of the midline length of vectors in LOI (min, max).
midline_min_length_lims (tuple of float) – Limits for the minimum length of the midline of vectors in LOI (min, max).
distance_threshold_lois (float) – Distance threshold for clustering LOIs. Clusters will not be merged above this threshold.
linkage (str) – Linkage criterion for clustering (‘complete’, ‘average’, ‘single’).
linewidth (float) – Width of the scan line (in µm), perpendicular to the LOIs.
order (int) – Order of spline interpolation for transforming LOIs (range 0-5).
export_raw (bool) – If True, exports raw intensity kymographs along LOIs.
- Return type:
None
- full_analysis_structure(frames='all')[source]
Analyze sarcomere structure with default parameters at specified frames
- Parameters:
frames ({'all', int, list, np.ndarray}) – frames for analysis (‘all’ for all frames, int for a single frame, list or ndarray for selected frames).
- static segment_z_bands(image: numpy.ndarray, threshold: float = 0.15) Tuple[numpy.ndarray, numpy.ndarray] [source]
Segment z-bands from U-Net result (threshold, make binary, skeletonize, label regions).
- Parameters:
image (np.ndarray) – Input image from U-Net.
threshold (float, optional) – Threshold value for binarizing the image. Defaults to 0.15.
- Returns:
labels (np.ndarray) – Labeled regions in the thresholded image.
labels_skel (np.ndarray) – Labeled regions in the skeletonized image.
- static _analyze_z_bands(zbands: numpy.ndarray, labels: numpy.ndarray, labels_skel: numpy.ndarray, image_raw: numpy.ndarray, orientation_field: numpy.ndarray, pixelsize: float, min_length: float = 1.0, threshold: float = 0.1, median_filter_radius: float = 0.25, a_min: float = 0.3, theta_phi_min: float = 0.2, d_max: float = 4.0, d_min: float = 0.25) Tuple [source]
Analyzes segmented z-bands in a single frame, extracting metrics such as length, intensity, orientation, straightness, lateral distance, alignment, number of lateral neighbors per z-band, and characteristics of groups of lateral z-bands (length, alignment, size).
- Parameters:
zbands (np.ndarray) – The segmented map of z-bands.
labels (np.ndarray) – The labeled image of z-bands.
labels_skel (np.ndarray) – The skeletonized labels of z-bands.
image_raw (np.ndarray) – The raw image.
orientation_field (np.ndarray) – Sarcomere orientation field.
pixelsize (float) – The size of pixels in the image.
min_length (float, optional) – The minimum length threshold for z-bands. Default is 1.0.
threshold (float, optional) – The threshold value for intensity. Default is 0.1.
median_filter_radius (float, optional) – Radius of kernel to smooth orientation field. Default is 0.2 µm.
a_min (float, optional) – The minimum value for alignment. Default is 0.25. Links with smaller alignment are set to np.nan.
theta_phi_min (float, optional) – The minimum dot product/cosine between the direction of a Z-band end and the direction of line from end to other Z-band end.
d_max (float, optional) – The maximum distance between z-band ends. Default is 5.0 µm. Larger distances are set to np.nan.
d_min (float, optional) – The minimum distance between z-band ends. Default is 0 µm. Smaller distances are set to np.nan.
- Returns:
A comprehensive tuple containing arrays and values describing the analyzed properties of z-bands: - Lengths, intensities, straightness, ratio of intensities, average intensity, orientations,
orientational order parameter, list of z-band labels, processed labels image, number of lateral neighbors, lateral distances, lateral alignments, links between z-band ends, coordinates of z-band ends, linked groups of z-bands, and their respective sizes, lengths, and alignments.
- Return type:
tuple
- static get_sarcomere_vectors(zbands: numpy.ndarray, mbands: numpy.ndarray, orientation_field: numpy.ndarray, pixelsize: float, median_filter_radius: float = 0.25, slen_lims: Tuple[float, float] = (1, 3), interp_factor: int = 4, linewidth: float = 0.3, backend: str = 'loky') Tuple[numpy.ndarray | List, numpy.ndarray | List, numpy.ndarray | List, numpy.ndarray | List, numpy.ndarray | List, numpy.ndarray | List, numpy.ndarray | List] [source]
Extract sarcomere orientation and length vectors.
- Parameters:
zbands (np.ndarray) – 2D array representing the semantic segmentation map of Z-bands.
mbands (np.ndarray) – 2D array representing the semantic segmentation map of mbands.
orientation_field (np.ndarray) – 2D array representing the orientation field.
pixelsize (float) – Size of a pixel in micrometers.
median_filter_radius (float, optional) – Radius of kernel to smooth orientation field before assessing orientation at M-points, in µm (default 0.25 µm).
slen_lims (tuple of float, optional) – Sarcomere size limits in micrometers (default is (1, 3)).
interp_factor (int, optional) – Interpolation factor for profiles to calculate sarcomere length. Defaults to 4.
linewidth (float, optional) – Line width of profiles to calculate sarcomere length. Defaults to 0.3 µm.
- Returns:
pos_vectors (np.ndarray) – Array of position vectors for sarcomeres.
sarcomere_orientation_vectors (np.ndarray) – Sarcomere orientation values at midline points.
sarcomere_length_vectors (np.ndarray) – Sarcomere length values at midline points.
sarcomere_mask (np.ndarray) – Mask indicating the presence of sarcomeres.
- static cluster_sarcomeres(pos_vectors: numpy.ndarray, sarcomere_length_vectors: numpy.ndarray, sarcomere_orientation_vectors: numpy.ndarray, pixelsize: float, size: Tuple[int, int], d_max: float = 3, cosine_min: float = 0.65, leiden_resolution: float = 0.06, random_seed: int = 42, area_min: float = 20, dilation_radius: float = 0.3) Tuple[int, List, List, List, List, List, numpy.ndarray] [source]
This function clusters sarcomeres into domains based on their spatial and orientational properties using the Leiden method for community detection in igraph. It considers sarcomere lengths, orientations, and positions along mbands to form networks of connected sarcomeres. Domains are then identified as communities within these networks, with additional criteria for minimum domain area and connectivity thresholds. Finally, this function quantifies the mean and std of sarcomere lengths, and the orientational order parameter and mean orientation of each domain.
- Parameters:
pos_vectors (np.ndarray) – Array of sarcomere midline point positions in µm.
sarcomere_length_vectors (np.ndarray) – List of midline point sarcomere lengths
sarcomere_orientation_vectors (np.ndarray) – List of midline point sarcomere orientations, in radians
pixelsize (float) – Pixel size in µm
size (tuple(int, int)) – Shape of the image in pixels
d_max (float) – Max. distance threshold for creating a network edge between vector ends
cosine_min (float) – Minimal absolute cosine between vector angles for creating a network edge between vector ends
leiden_resolution (float) – Resolution parameter for the Leiden algorithm
random_seed (int) – Random seed for reproducibility
area_min (float) – Minimal area (in µm²) for a domain to be kept
dilation_radius (float) – Dilation radius for refining domain area masks (in µm)
- Returns:
n_domains (int) – Number of domains
domains (list) – List of domain sets with point indices
area_domains (list) – List with domain areas
sarcomere_length_mean_domains (list) – Mean sarcomere length within each domain
sarcomere_length_std_domains (list) – Standard deviation of sarcomere length within each domain
sarcomere_oop_domains (list) – Orientational order parameter of sarcomeres in each domain
sarcomere_orientation_domains (list) – Main orientation of domains
mask_domains (ndarray) – Masks of domains with value representing domain label
- static _grow_line(seed, points_t, sarcomere_length_vectors_t, sarcomere_orientation_vectors_t, nbrs, threshold_distance, pixelsize, persistence)[source]
- static line_growth(points_t: numpy.ndarray, sarcomere_length_vectors_t: numpy.ndarray, sarcomere_orientation_vectors_t: numpy.ndarray, midline_length_vectors_t: numpy.ndarray, pixelsize: float, ratio_seeds: float = 0.1, persistence: int = 4, threshold_distance: float = 0.3, n_min: int = 5, random_seed: None | int = None)[source]
Line growth algorithm to determine myofibril lines perpendicular to sarcomere z-bands
- Parameters:
points_t (np.ndarray) – List of midline point positions
sarcomere_length_vectors_t (list) – Sarcomere length at midline points
sarcomere_orientation_vectors_t (list) – Sarcomere orientation angle at midline points, in radians
midline_length_vectors_t (list) – Length of sarcomere mbands of midline points
pixelsize (float) – Pixel size in µm
ratio_seeds (float) – Ratio of sarcomere vectors to be takes as seeds for line growth
persistence (int) – Number of points to consider for averaging length and orientation.
random_seed (int, optional) – Random seed for reproducibility. Defaults to None.
- Returns:
line_data – Dictionary with LOI data keys = (lines, line_features)
- Return type:
dict
- static kymograph_movie(movie: numpy.ndarray, line: numpy.ndarray, linewidth: int = 10, order: int = 0)[source]
Generate a kymograph using multiprocessing.
- Parameters:
movie (np.ndarray, shape (N, H, W)) – The movie.
line (np.ndarray, shape (N, 2)) – The coordinates of the segmented line (N>1)
linewidth (int, optional) – Width of the scan in pixels, perpendicular to the line
order (int in {0, 1, 2, 3, 4, 5}, optional) – The order of the spline interpolation, default is 0 if image.dtype is bool and 1 otherwise. The order has to be in the range 0-5. See skimage.transform.warp for detail.
- Returns:
return_value – Kymograph along segmented line
- Return type:
ndarray
Notes
Adapted from scikit-image (https://scikit-image.org/docs/0.22.x/api/skimage.measure.html#skimage.measure.profile_line).
- static __curved_line_profile_coordinates(points: numpy.ndarray, linewidth: int = 10)
Calculate the coordinates of a curved line profile composed of multiple segments with specified linewidth.
- Parameters:
points (np.ndarray) – A list of points (y, x) defining the segments of the curved line.
linewidth (int, optional) – The width of the line in pixels.
- Returns:
coords – The coordinates of the curved line profile. Shape is (2, N, linewidth), where N is the total number of points in the line.
- Return type:
ndarray
- static sarcomere_mask(points: numpy.ndarray, sarcomere_orientation_vectors: numpy.ndarray, sarcomere_length_vectors: numpy.ndarray, shape: Tuple[int, int], pixelsize: float, dilation_radius: float = 0.3) numpy.ndarray [source]
Calculates a binary mask of areas with sarcomeres.
- Parameters:
points (ndarray) – Positions of sarcomere vectors in µm. (n_vectors, 2)
sarcomere_orientation_vectors (ndarray) – Orientations of sarcomere vectors.
sarcomere_length_vectors (ndarray) – Lengths of sarcomere vectors in µm.
shape (tuple) – Shape of the image, in pixels.
pixelsize (float) – Pixel size in µm.
dilation_radius (float, optional) – Dilation radius to close small holes in mask, in µm (default is 0.3).
- Returns:
mask – Binary mask of sarcomeres.
- Return type:
ndarray
- static _analyze_domains(domains: List, pos_vectors: numpy.ndarray, sarcomere_orientation_vectors: numpy.ndarray, sarcomere_length_vectors: numpy.ndarray, size: Tuple[int, int], pixelsize: float, dilation_radius: float, area_min: float)[source]
Creates a domain mask, where each domain has a distinct label, and analyzes the individual domains.
- Parameters:
domains (list) – List with domain labels for each vector. Each domain is labeled with a unique integer.
pos_vectors (ndarray) – Position vectors in micrometers.
sarcomere_orientation_vectors (ndarray) – Orientation angles in radians.
sarcomere_length_vectors (ndarray) – Sarcomere lengths in micrometers.
size (tuple of int) – Output map dimensions (height, width) in pixels.
pixelsize (float) – Physical size of one pixel in micrometers.
dilation_radius (float, optional) – Dilation radius for refining domain masks, in µm.
area_min (float, optional) – Minimal area of a domain in µm^2, smaller domains are discarded.
- static create_myofibril_length_map(myof_lines: numpy.ndarray, myof_length: numpy.ndarray, pos_vectors: numpy.ndarray, sarcomere_orientation_vectors: numpy.ndarray, sarcomere_length_vectors: numpy.ndarray, size: tuple, pixelsize: float, median_filter_radius: float = 0.6) numpy.ndarray [source]
The create_myofibril_length_map function generates a 2D spatial map of myofibril lengths represented as pixel values. It achieves this by rasterizing myofibril line segments, assigning their corresponding lengths to the pixels they occupy, and averaging these values at overlapping pixels. The resulting map is optionally smoothed using a median filter to reduce noise and provide a more coherent spatial representation.
- Parameters:
myof_lines (ndarray) – Line indices for myofibril structures.
myof_length (ndarray) – Length values for each myofibril line.
pos_vectors (ndarray) – Position vectors in micrometers.
sarcomere_orientation_vectors (ndarray) – Orientation angles in radians.
sarcomere_length_vectors (ndarray) – Sarcomere lengths in micrometers.
size (tuple of int) – Output map dimensions (height, width) in pixels.
pixelsize (float) – Physical size of one pixel in micrometers.
median_filter_radius (float, optional) – Filter radius in micrometers, by default 0.6.
- Returns:
2D array of calculated myofibril lengths with NaN for empty regions.
- Return type:
ndarray
- sarcasm.structure.test_file = '../test_data/antibody_staining_2D_hiPSC_CM/stained hiPSC d60 a-actinin 488 63x 5.tif'