Skip to content

std_distance

Calculate the std_distance of xy-coords in a GeoDataFrame.

The std_distance is defined as the square root of the variance of the distances of the xy-coords from their mean center.

Parameters:

Name Type Description Default
xy ndarray

A numpy array of shape (n, 2) containing the x and y coordinates. (centroids of the nuclei).

required

Returns:

Name Type Description
float float

The std_distance of the xy-coords as a float value.

Source code in src/histolytics/spatial_clust/centrography.py
def std_distance(xy: np.ndarray) -> float:
    """Calculate the std_distance of xy-coords in a GeoDataFrame.

    The std_distance is defined as the square root of the variance of the distances of
    the xy-coords from their mean center.

    Parameters:
        xy (np.ndarray):
            A numpy array of shape (n, 2) containing the x and y coordinates.
            (centroids of the nuclei).

    Returns:
        float:
            The std_distance of the xy-coords as a float value.
    """
    n, p = xy.shape
    m = mean_center(xy)
    return np.sqrt(((xy * xy).sum(axis=0) / n - m * m).sum())