Skip to content

Statistics

Calculate statistics on grain volumes and aggregate and summarise the data.

Functions:

Name Description
area_pores

Extract area of objects in each layer.

calculate_pdf

Calculate the scaled probability density function for an array.

centroid_pores

Extract centroid of objects in each layer.

classify_pore_size

Classify pore sizes in a dataframe into colors.

count_pores

Count the number of region_properties, each of which represents a pore for all layers.

create_statistics_dictionary

Extract statistics of objects from each layer.

feret_diameter_maximum_pores

Extract the maximum feret diameter of objects in each layer.

full_width_half_max

Calculate the full-width half max.

sum_area_by_layer

Sum the area of pores on each layer.

summarise_pores

Summarise pore types by image, layer and color.

area_pores

Extract area of objects in each layer.

Parameters:

Name Type Description Default

sliced_region_properties

list[Any]

A list (one for each layer) of lists which contain the region_props for each object within that layer.

required

Returns:

Type Description
list[list[float]]

A list with the same length as the number of layers, each item is a list of the area of objects within that layer.

calculate_pdf

calculate_pdf(array, xmin=None, xmax=None)

Calculate the scaled probability density function for an array.

Parameters:

Name Type Description Default

array

list[float]

Array of data points to be summarised.

required

xmin

int | float

Minimum value.

None

xmax

int | float

Maximum value.

None

Returns:

Type Description
dict[str, NDArray]

Dictionary of x and y values for the PDF.

centroid_pores

centroid_pores(sliced_region_properties)

Extract centroid of objects in each layer.

Parameters:

Name Type Description Default

sliced_region_properties

list[Any]

A list (one for each layer) of lists which contain the region_props for each object within that layer.

required

Returns:

Type Description
list[list[float]]

A list with the same length as the number of layers, each item is a list of the centroid of objects within that layer.

classify_pore_size

classify_pore_size(
    df, area_thresholds, pore_colors, area_val="area"
)

Classify pore sizes in a dataframe into colors.

Parameters:

Name Type Description Default

df

DataFrame

Dataframe with areas to be classified.

required

area_thresholds

dict[str, int]

Dictionary of thresholds, there should be three values for low, medium and high thresholds resulting in four categories.

required

pore_colors

list[str]

Colors to use for the four categories.

required

area_val

str

Column name containing the area data, default is area and is unlikely to need changing.

'area'

Returns:

Type Description
DataFrame

Dataframe with additional column with text categorisation of pore area.

count_pores

Count the number of region_properties, each of which represents a pore for all layers.

Parameters:

Name Type Description Default

sliced_region_properties

list[Any]

A list of region properties found on each layer.

required

Returns:

Type Description
NDArray[int32]

A list of the number of region properties detected in each layer.

create_statistics_dictionary

create_statistics_dictionary(
    sliced_region_properties,
    feret_maximum=False,
    centroid=False,
)

Extract statistics of objects from each layer.

Parameters:

Name Type Description Default

sliced_region_properties

list[list[Any]]

List of lists of region properties, the top level is layer, the nesting within it is each of the objects within the layer.

required

feret_maximum

bool

Whether to extract the maximum feret distance.

False

centroid

bool

Whether to extract the centroid coordinates of the region.

False

Returns:

Type Description
dict[int, dict[int, Any]]

Dictionary of statistics, top-level is the layer/slice through the image, and nested within are statistics for each pore.

feret_diameter_maximum_pores

feret_diameter_maximum_pores(sliced_region_properties)

Extract the maximum feret diameter of objects in each layer.

Parameters:

Name Type Description Default

sliced_region_properties

list[Any]

A list (one for each layer) of lists which contain the region_props for each object within that layer.

required

Returns:

Type Description
list[list[float]]

A list with the same length as the number of layers, each item is a list of the maximum feret diameter of objects within that layer.

full_width_half_max

full_width_half_max(pdf)

Calculate the full-width half max.

We are interested in the layers that cover the full-width half-max of the number of pores in an image. And therefore extract the indices the calculated PDF (y_pdf)

Parameters:

Name Type Description Default

pdf

NDArray

Array probability density function for which peak and full-width half-max are to be calculated.

required

Returns:

Type Description
tuple[int, int]

Dictionary of the lower and upper layers for the full-width half-max range.

sum_area_by_layer

sum_area_by_layer(areas, min_size=None)

Sum the area of pores on each layer.

Parameters:

Name Type Description Default

areas

list[list[float]]

A list of areas of pores on each layer.

required

min_size

float

Minimum size to include in calculation.

None

Returns:

Type Description
list[float]

A list with the total area per slice.

summarise_pores

summarise_pores(df, pore_colors)

Summarise pore types by image, layer and color.

Parameters:

Name Type Description Default

df

DataFrame

Pandas dataframe to aggregate, typically will be AFMSlicer.statistics. Must have columns image, layer, pore_color and counter.

required

pore_colors

list[str]

List of pore color columns that should be present in the resulting dataframe.

required

Returns:

Type Description
DataFrame

Aggregated data frame of counts of pore_color by image/layer with counts of each pore_color.