import math


def parse_properties(props, img_scale_factor, analys_name, verbose = False,
                     addit_props = []):
    """Parses a skimage RegionProperties instance and scales image
       measurements to real-world measurments (microns).

    Parameters
    ----------
    props : skimage RegionProperties instance
        Ideally, the skimage RegionProperties instance corresponding
        to a zircon crystal.
    img_scale_factor : float
        Scale factor in microns/pixel for converting pixel measurements.
    analys_name : str
        A name for the analysis being parsed (e.g., 'Spot-210'). Added to output.
    verbose : Boolean, optional
        If True, some calculated measurments are printed. The default is False.
    addit_props : list, optional
        Additonal values to append to output props list. The default is [].

    Returns
    -------
    list
        A list of calculated properties. Added to export dict in
        main colab_zirc_dims Colab Notebook. Format:
            [analys_name, area, convex_area, eccent, eq_diam, perim,
             major_leng, minor_leng, roundness, scale_factor, *addit_props]

    """
    #initialize empty (null values) props list
    props_list = [analys_name, 0, 0, 0, 0, 0, 0, 0, 0, img_scale_factor]
    #if no region found, skip and return null properties
    if props == []:
        if verbose:
            print('null properties entered')
        for addit_prop in addit_props:
            props_list.append(addit_prop)
        return props_list

    area = props.area * img_scale_factor**2
    convex_area = props.convex_area * img_scale_factor**2
    eccent = props.eccentricity
    eq_diam = props.equivalent_diameter * img_scale_factor
    perim = props.perimeter * img_scale_factor
    major_leng = props.major_axis_length * img_scale_factor
    minor_leng = props.minor_axis_length * img_scale_factor
    roundness = 4 * math.pi * props.area / props.perimeter**2
    scale_factor = img_scale_factor

    props_list = [analys_name, area, convex_area, eccent, eq_diam, perim,
                  major_leng, minor_leng, roundness, scale_factor]
    for addit_prop in addit_props:
        props_list.append(addit_prop)

    if verbose:
        print('Major axis length =', round(major_leng, 1), 'µm,',
              'Minor axis length =', round(minor_leng, 1), 'µm')

    return props_list