cytometer/data.py
def aida_contour_items(contours, f_area2quantile, cm='quantiles_aida', xres=1.0, yres=1.0, cell_prob=None):
    """
    Create list of contour items for AIDA.

    This function computes the area of each contour, it's quantile, and maps it to a colour.

    :param contours: List [contour_0, contour_1...], where contour_i is an (Ni, 2)-np.array with Ni 2D points.
    :param f_area2quantile: Function to map areas to quantiles. Compute with cytometer.data.area2quantile(manual_areas).
    :param cm: (def 'quantiles_aida'). String or matplotlib.colors.ListedColormap to map [0.0, 1.0] to RGB colours. If
    cm is a string, currently only 'quantiles_aida' is accepted.
    :param xres: (def 1.0) Pixel size in the x-coordinate.
    :param yres: (def 1.0) Pixel size in the y-coordinate.
    :param cell_prob: (def None) Vector with one value per contour. This value is interpreted as the probability of the
    object being a cell.
    :return: List of dictionaries, each one with the structure of a contour object.
    """


    def aida_contour_item(contour, rgb_colour, cell_prob=None):
        """
        Create an object that describes a closed contour in AIDA. The user provides the coordinates of the contour
        points and the colour for the contour.

        :param contour: np.array or list of points of a contour: [[x0, y0], [x1, y1], ...]
        :param rgb_colour: (r, g, b) or (r, g, b, alpha). RGB colour for this contour.
        :param cell_prob: (def None) Scalar in [0.0, 1.0] with the probability of the contour being a cell.
        :return: item: dictionary with the structure of the contour object.
        """

        if type(contour) != 'numpy.ndarray':
            contour = list(contour)

        # convert RGB to HSL
        hls_colour = colorsys.rgb_to_hls(rgb_colour[0], rgb_colour[1], rgb_colour[2])

        # create the item object
        item = {
            'class': '',
            'type': 'path',
            'color': {
                'fill': {
                    'hue': hls_colour[0] * 360,
                    'saturation': hls_colour[2],
                    'lightness': hls_colour[1],
                    'alpha': 0.7
                },
                'stroke': {
                    'hue': hls_colour[0] * 360,
                    'saturation': hls_colour[2],
                    'lightness': hls_colour[1],
                    'alpha': 1.0
                }
            },
            'segments': [list(x) for x in contour],
            'closed': True
        }

        if cell_prob is not None:
            item['cell_prob'] = cell_prob

        return item

    ## main function

    # load colourmap
    if cm == 'quantiles_aida':
        cm = aida_colourmap()
    else:
        raise ValueError('Only quantiles_aida colourmap is implemented')

    # compute area of each contour
    areas = [Polygon(c).area * xres * yres for c in contours]  # (um^2)

    # convert to quantiles
    q = f_area2quantile(areas)

    # create the list of contour objects (each item is a contour object)
    if cell_prob is None:
        items = [aida_contour_item(contour=contours[i], rgb_colour=cm(q[i]))
                 for i in range(len(contours))]
    else:
        items = [aida_contour_item(contour=contours[i], rgb_colour=cm(q[i]), cell_prob=cell_prob[i])
                 for i in range(len(contours))]

    return items

    Create list of contour items for AIDA.

    This function computes the area of each contour, it's quantile, and maps it to a colour.

    :param contours: List [contour_0, contour_1...], where contour_i is an (Ni, 2)-np.array with Ni 2D points.
    :param f_area2quantile: Function to map areas to quantiles. Compute with cytometer.data.area2quantile(manual_areas).
    :param cm: (def 'quantiles_aida'). String or matplotlib.colors.ListedColormap to map [0.0, 1.0] to RGB colours. If
    cm is a string, currently only 'quantiles_aida' is accepted.
    :param xres: (def 1.0) Pixel size in the x-coordinate.
    :param yres: (def 1.0) Pixel size in the y-coordinate.
    :param cell_prob: (def None) Vector with one value per contour. This value is interpreted as the probability of the
    object being a cell.
    :return: List of dictionaries, each one with the structure of a contour object.
    
Create list of contour items for AIDA.
This function computes the area of each contour, it's quantile, and maps it to a colour.
Create list of contour items for AIDA . This function computes the area of each contour it ' s quantile and maps it to a colour .
def aida_contour_items(contours, f_area2quantile, cm='quantiles_aida', xres=1.0, yres=1.0, cell_prob=None):
    def aida_contour_item(contour, rgb_colour, cell_prob=None):
        if type(contour) != 'numpy.ndarray':
            contour = list(contour)
        hls_colour = colorsys.rgb_to_hls(rgb_colour[0], rgb_colour[1], rgb_colour[2])
        item = {
            'class': '',
            'type': 'path',
            'color': {
                'fill': {
                    'hue': hls_colour[0] * 360,
                    'saturation': hls_colour[2],
                    'lightness': hls_colour[1],
                    'alpha': 0.7
                },
                'stroke': {
                    'hue': hls_colour[0] * 360,
                    'saturation': hls_colour[2],
                    'lightness': hls_colour[1],
                    'alpha': 1.0
                }
            },
            'segments': [list(x) for x in contour],
            'closed': True
        }
        if cell_prob is not None:
            item['cell_prob'] = cell_prob
        return item
    if cm == 'quantiles_aida':
        cm = aida_colourmap()
    else:
        raise ValueError('Only quantiles_aida colourmap is implemented')
    areas = [Polygon(c).area * xres * yres for c in contours]  
    q = f_area2quantile(areas)
    if cell_prob is None:
        items = [aida_contour_item(contour=contours[i], rgb_colour=cm(q[i]))
                 for i in range(len(contours))]
    else:
        items = [aida_contour_item(contour=contours[i], rgb_colour=cm(q[i]), cell_prob=cell_prob[i])
                 for i in range(len(contours))]
    return items
def aida_contour_items ( contours , f_area2quantile , cm = 'quantiles_aida' , xres = 1.0 , yres = 1.0 , cell_prob = None ) : def aida_contour_item ( contour , rgb_colour , cell_prob = None ) : """
        Create an object that describes a closed contour in AIDA. The user provides the coordinates of the contour
        points and the colour for the contour.

        :param contour: np.array or list of points of a contour: [[x0, y0], [x1, y1], ...]
        :param rgb_colour: (r, g, b) or (r, g, b, alpha). RGB colour for this contour.
        :param cell_prob: (def None) Scalar in [0.0, 1.0] with the probability of the contour being a cell.
        :return: item: dictionary with the structure of the contour object.
        """ if type ( contour ) != 'numpy.ndarray' : contour = list ( contour ) hls_colour = colorsys . rgb_to_hls ( rgb_colour [ 0 ] , rgb_colour [ 1 ] , rgb_colour [ 2 ] ) item = { 'class' : '' , 'type' : 'path' , 'color' : { 'fill' : { 'hue' : hls_colour [ 0 ] * 360 , 'saturation' : hls_colour [ 2 ] , 'lightness' : hls_colour [ 1 ] , 'alpha' : 0.7 } , 'stroke' : { 'hue' : hls_colour [ 0 ] * 360 , 'saturation' : hls_colour [ 2 ] , 'lightness' : hls_colour [ 1 ] , 'alpha' : 1.0 } } , 'segments' : [ list ( x ) for x in contour ] , 'closed' : True } if cell_prob is not None : item [ 'cell_prob' ] = cell_prob return item if cm == 'quantiles_aida' : cm = aida_colourmap ( ) else : raise ValueError ( 'Only quantiles_aida colourmap is implemented' ) areas = [ Polygon ( c ) . area * xres * yres for c in contours ] q = f_area2quantile ( areas ) if cell_prob is None : items = [ aida_contour_item ( contour = contours [ i ] , rgb_colour = cm ( q [ i ] ) ) for i in range ( len ( contours ) ) ] else : items = [ aida_contour_item ( contour = contours [ i ] , rgb_colour = cm ( q [ i ] ) , cell_prob = cell_prob [ i ] ) for i in range ( len ( contours ) ) ] return items
Create list of contour items for AIDA.
Create list of contour items for AIDA .
"""
    Create list of contour items for AIDA.

    This function computes the area of each contour, it's quantile, and maps it to a colour.

    :param contours: List [contour_0, contour_1...], where contour_i is an (Ni, 2)-np.array with Ni 2D points.
    :param f_area2quantile: Function to map areas to quantiles. Compute with cytometer.data.area2quantile(manual_areas).
    :param cm: (def 'quantiles_aida'). String or matplotlib.colors.ListedColormap to map [0.0, 1.0] to RGB colours. If
    cm is a string, currently only 'quantiles_aida' is accepted.
    :param xres: (def 1.0) Pixel size in the x-coordinate.
    :param yres: (def 1.0) Pixel size in the y-coordinate.
    :param cell_prob: (def None) Vector with one value per contour. This value is interpreted as the probability of the
    object being a cell.
    :return: List of dictionaries, each one with the structure of a contour object.
    """ """
        Create an object that describes a closed contour in AIDA. The user provides the coordinates of the contour
        points and the colour for the contour.

        :param contour: np.array or list of points of a contour: [[x0, y0], [x1, y1], ...]
        :param rgb_colour: (r, g, b) or (r, g, b, alpha). RGB colour for this contour.
        :param cell_prob: (def None) Scalar in [0.0, 1.0] with the probability of the contour being a cell.
        :return: item: dictionary with the structure of the contour object.
        """ # convert RGB to HSL # create the item object ## main function # load colourmap # compute area of each contour # (um^2) # convert to quantiles # create the list of contour objects (each item is a contour object)
List of dictionaries, each one with the structure of a contour object.
List of dictionaries each one with the structure of a contour object .
contours
List [contour_0, contour_1...], where contour_i is an (Ni, 2)-np.array with Ni 2D points.
List [ contour_0 contour_1 ... ] where contour_i is an ( Ni 2 ) - np . array with Ni 2D points .
f_area2quantile
Function to map areas to quantiles. Compute with cytometer.data.area2quantile(manual_areas).
Function to map areas to quantiles . Compute with cytometer . data . area2quantile ( manual_areas ) .
cm
(def 'quantiles_aida'). String or matplotlib.colors.ListedColormap to map [0.0, 1.0] to RGB colours. If
cm is a string, currently only 'quantiles_aida' is accepted.
( def ' quantiles_aida ' ) . String or matplotlib . colors . ListedColormap to map [ 0 . 0 1 . 0 ] to RGB colours . If cm is a string currently only ' quantiles_aida ' is accepted .
xres
(def 1.0) Pixel size in the x-coordinate.
( def 1 . 0 ) Pixel size in the x - coordinate .
yres
(def 1.0) Pixel size in the y-coordinate.
( def 1 . 0 ) Pixel size in the y - coordinate .
cell_prob
(def None) Vector with one value per contour. This value is interpreted as the probability of the
object being a cell.
( def None ) Vector with one value per contour . This value is interpreted as the probability of the object being a cell .