cytometer/utils.py
def sphericity(poly):
    """
    Sphericity measure of a polygon, or degree to which an object approximates a sphere.

            Sphericity = R_inscribed / R_circumscribing

    where R_incribed, R_circumscribing are the minimum and maximum distances, respectively, from polygon vertices to the
    polygon's centroid. Sphericity \in [0, 1], and it's maximum for a circle.

    Note that the centroid could be outside a polygon, and the sphericity measure wouldn't make much sense, but we are
    not checking for those cases.

    :param poly: shapely.geometry.polygon.Polygon object describing a closed polygon (the last vertex is a repetition of
    the first).
    :return: float scalar with the sphericity measure for the polygon.
    """

    if type(poly) != shapely.geometry.polygon.Polygon:
        raise TypeError('poly must be a shapely.geometry.polygon.Polygon')

    # distance of each polygon point to polygon centroid
    d = np.array([shapely.geometry.Point(p).distance(poly.centroid) for p in list(poly.exterior.coords[:-1])])

    # sphericity measure
    return d.min() / d.max()

    Sphericity measure of a polygon, or degree to which an object approximates a sphere.

            Sphericity = R_inscribed / R_circumscribing

    where R_incribed, R_circumscribing are the minimum and maximum distances, respectively, from polygon vertices to the
    polygon's centroid. Sphericity \in [0, 1], and it's maximum for a circle.

    Note that the centroid could be outside a polygon, and the sphericity measure wouldn't make much sense, but we are
    not checking for those cases.

    :param poly: shapely.geometry.polygon.Polygon object describing a closed polygon (the last vertex is a repetition of
    the first).
    :return: float scalar with the sphericity measure for the polygon.
    
Sphericity measure of a polygon, or degree to which an object approximates a sphere.



Note that the centroid could be outside a polygon, and the sphericity measure wouldn't make much sense, but we are
not checking for those cases.
Sphericity measure of a polygon or degree to which an object approximates a sphere . Note that the centroid could be outside a polygon and the sphericity measure wouldn ' t make much sense but we are not checking for those cases .
def sphericity(poly):
    if type(poly) != shapely.geometry.polygon.Polygon:
        raise TypeError('poly must be a shapely.geometry.polygon.Polygon')
    d = np.array([shapely.geometry.Point(p).distance(poly.centroid) for p in list(poly.exterior.coords[:-1])])
    return d.min() / d.max()
def sphericity ( poly ) : if type ( poly ) != shapely . geometry . polygon . Polygon : raise TypeError ( 'poly must be a shapely.geometry.polygon.Polygon' ) d = np . array ( [ shapely . geometry . Point ( p ) . distance ( poly . centroid ) for p in list ( poly . exterior . coords [ : - 1 ] ) ] ) return d . min ( ) / d . max ( )
Sphericity measure of a polygon, or degree to which an object approximates a sphere.
Sphericity measure of a polygon or degree to which an object approximates a sphere .
"""
    Sphericity measure of a polygon, or degree to which an object approximates a sphere.

            Sphericity = R_inscribed / R_circumscribing

    where R_incribed, R_circumscribing are the minimum and maximum distances, respectively, from polygon vertices to the
    polygon's centroid. Sphericity \in [0, 1], and it's maximum for a circle.

    Note that the centroid could be outside a polygon, and the sphericity measure wouldn't make much sense, but we are
    not checking for those cases.

    :param poly: shapely.geometry.polygon.Polygon object describing a closed polygon (the last vertex is a repetition of
    the first).
    :return: float scalar with the sphericity measure for the polygon.
    """ # distance of each polygon point to polygon centroid # sphericity measure
float scalar with the sphericity measure for the polygon.
float scalar with the sphericity measure for the polygon .
poly
shapely.geometry.polygon.Polygon object describing a closed polygon (the last vertex is a repetition of
the first).
shapely . geometry . polygon . Polygon object describing a closed polygon ( the last vertex is a repetition of the first ) .