fishdist.spot_data_utils

compute_and_plot_points_for_all_dims(measured_points, corrected_spots, reference_points, rescaling_factor=[0.1037832, 0.1037832, 0.25])

Compute and display statistics of 3D spot positions before and after correction.

This function calculates the vectors from measured to reference points, computes pairwise distances, medians, and interquartile ranges (IQRs), and prints mean vectors before and after correction. Intended for quality assessment of chromatic aberration correction.

Parameters:
  • measured_points (ndarray of shape (N,3)) –

    Original measured spot coordinates.

  • corrected_spots (ndarray of shape (N,3)) –

    Corrected spot coordinates after chromatic aberration correction.

  • reference_points (ndarray of shape (N,3)) –

    Reference spot coordinates.

  • rescaling_factor (list or array-like of length 3, default: [0.1037832, 0.1037832, 0.25] ) –

    Scaling factors for x, y, z dimensions to convert distances to physical units. Default is [0.1037832, 0.1037832, 0.25].

Returns:
  • None

    Prints summary statistics (mean vectors, medians, IQRs) for before/after correction.

Example
>>> import numpy as np
>>> measured = np.array([[0,0,0],[1,1,1],[2,2,2]])
>>> corrected = np.array([[0,0,0],[1,1,0.9],[2,2,1.9]])
>>> reference = np.array([[0,0,0],[1,1,1],[2,2,2]])
>>> compute_and_plot_points_for_all_dims(measured, corrected, reference)
Mean vector before correction: [0. 0. 0.]
Mean vector after correction: [ 0.          0.         -0.06666667]
Original distances (median * 1000 nm): 0.0 IQR: [0. 0.]
Corrected distances (median * 1000 nm): 24.999999999999993 IQR: [0.0125 0.025 ]

compute_pairwise_distance(coord_set1, coord_set2, rescaling_factor=None)

Compute pairwise distances between two sets of coordinates.

For each index i, calculates the distance between coord_set1[i] and coord_set2[i]. If the sets have different lengths, computes distances up to the length of the shorter set and prints a warning.

Parameters:
  • coord_set1 (list or ndarray) –

    First set of coordinates. Each element should be a point (array-like).

  • coord_set2 (list or ndarray) –

    Second set of coordinates. Each element should be a point (array-like).

  • rescaling_factor (float or sequence, default: None ) –

    Factor to scale coordinates before computing distances. Can be used to convert voxel coordinates to physical units. Default is None.

Returns:
  • list of float: Pairwise distances between corresponding points.

Example
>>> import numpy as np
>>> set1 = np.array([[0,0],[1,1],[2,2]])
>>> set2 = np.array([[1,0],[1,2],[2,3]])
>>> compute_pairwise_distance(set1, set2)
[1.0, 1.0, 1.0]

>>> compute_pairwise_distance(set1, set2, rescaling_factor=2)
[2.0, 2.0, 2.0]

get_green_and_blue_dots(src='coloc', order=['x', 'y', 'z'], TAG=False, check_voxel_size=True, atol=1e-06, table_name='points_n_distances3D_only_in_nuclei')

Load measured (blue) and reference (green) 3D spot coordinates from FISH datasets, optionally returning tags.

This function extracts 3D spot coordinates from database files or a list of file paths, checks for consistent voxel sizes, and optionally returns the source tag for each point.

Parameters:
  • src (str or list of str, default: 'coloc' ) –

    Source of the data. Can be a string key ('coloc', 'paired', 'all') or a list of file paths. Default is 'coloc'.

  • order (list of str, default: ['x', 'y', 'z'] ) –

    Order of axes for database queries. Default is ['x','y','z'].

  • TAG (bool, default: False ) –

    If True, returns an additional array of tags corresponding to the source of each point. Default is False.

  • check_voxel_size (bool, default: True ) –

    If True, ensures all files have the same voxel size. Default is True.

  • atol (float, default: 1e-06 ) –

    Tolerance for voxel size comparison. Default is 1e-6.

  • table_name (str, default: 'points_n_distances3D_only_in_nuclei' ) –

    Name of the table to query. Default is 'points_n_distances3D_only_in_nuclei'.

Returns:
  • blue_spots( np.ndarray of shape (N, 3) ) –

    Measured (blue) 3D coordinates.

  • green_spots( np.ndarray of shape (N, 3) ) –

    Reference (green) 3D coordinates.

  • tags( np.ndarray of shape (N, 1), optional ) –

    Returned only if TAG=True; contains file/source tags for each point.

Example
blue, green, tags = get_green_and_blue_dots(src='coloc', TAG=True)
blue, green = get_green_and_blue_dots(src=['file1.czi', 'file2.czi'])
blue, green = get_green_and_blue_dots(src='coloc', table_name='points_n_distances3D_ch1_ch2_only_in_nuclei')

plot_each_dim(blue_spots, corrected_spots, green_spots, axes_names=['X', 'Y', 'Z'], center_on_zero=True)

Plot displacement along each dimension before and after correction, with linear regression slopes.

This function visualizes the per-dimension displacements of 3D spots relative to reference positions, comparing measured (blue) and corrected (red) spots. It optionally centers displacements on zero, fits linear regressions, and prints slope values.

Parameters:
  • blue_spots (ndarray of shape (N,3)) –

    Original measured spot coordinates.

  • corrected_spots (ndarray of shape (N,3)) –

    Corrected spot coordinates after chromatic aberration correction.

  • green_spots (ndarray of shape (N,3)) –

    Reference spot coordinates.

  • axes_names (list of str, default: ['X', 'Y', 'Z'] ) –

    Names of axes to label plots. Default is ['X','Y','Z'].

  • center_on_zero (bool, default: True ) –

    If True, centers displacements by subtracting the mean. Default is True.

Returns:
  • None

    Displays 2D scatter plots with regression lines and prints slope statistics.

Example
import numpy as np
measured = np.array([[0,0,0],[1,1,1],[2,2,2]])
corrected = np.array([[0,0,0],[1,0.9,1],[2,1.9,2]])
reference = np.array([[0,0,0],[1,1,1],[2,2,2]])
plot_each_dim(measured, corrected, reference)

plot_points_3D(blue_spots, corrected_spots, green_spots)

Create a 3D scatter plot of blue, green, and corrected spot coordinates.

This function visualizes three sets of 3D points: the original measured (blue), reference (green), and corrected (red) spots, allowing visual assessment of chromatic aberration correction.

Parameters:
  • blue_spots (ndarray of shape (N,3)) –

    Original measured spot coordinates.

  • corrected_spots (ndarray of shape (N,3)) –

    Corrected spot coordinates after correction.

  • green_spots (ndarray of shape (N,3)) –

    Reference spot coordinates.

Returns:
  • None

    Displays a 3D scatter plot of the points.

Example
>>> import numpy as np
>>> measured = np.array([[0,0,0],[1,1,1],[2,2,2]])
>>> corrected = np.array([[0,0,0],[1,1,0.9],[2,2,1.9]])
>>> reference = np.array([[0,0,0],[1,1,1],[2,2,2]])
>>> plot_points_3D(measured, corrected, reference)