Skip to content

afmslicer.classes

Classes for the AFMSlicer package.

AFMSlicer

Bases: TopoStats

Class for AFMSlicer data and attributes.

The class inherits TopoStats class and has all of its attributes such as image, image_original, filename and pixel_to_nm_scaling which are used (as well as others which are not used such as grain_crops).

Attributes:

Name Type Description
image NDArray[float64]

Two-dimensional array of heights after filtering/flattening.

image_original NDArray[float64]

Two-dimensional array of original heights.

filename str

Image filename.

pixel_to_nm_scaling float

Pixel to nano-metre scaling factor.

layers (NDArray[float64], optional)

The boundaries of heights for sliced layers to be taken through the original image.

sliced_array (NDArray[float64], optional)

Three dimensional array of slices of the original image.

sliced_mask (NDArray[bool], optional)

A three dimensional array of slices where each layer is a mask for the heights given in layers.

sliced_segments NDArray[int32]

A three dimensional array of slices where each layer has been segmented.

sliced_segments_clean NDArray[int32]

A three dimensional array of slices where small objects have been masked. The threshold for masking comes from the configuration file under slicing.minimum_size and is 8000 nanometres squared by default.

sliced_region_properties list[list[Any]]

A list of region_props for each object in each layer. There is one list for each layer.

segment_method (str, optional)

Method for segmenting individual layers.

min_height (float, optional)

Minimum height. Determined from the data if not provided.

max_height (float, optional)

Maximum height. Determined from the data if not provided.

slices (int, optional)

The number of slices taken through the image between the min_height and max_height.

full_width_half_max tuple[int, int]

The lower and upper bound of the Full Width Half Max from the distribution of the number of pores per layer. Used to select the layers whose areas are of interest and are plotted.

fig_objects_per_layer (tuple[Figure, Axes], optional)

Matplotlib figure and axes objects from plotting the layer vs the number of objects.

fig_log_objects_per_layer (tuple[Figure, Axes], optional)

Matplotlib figure and axes objects from plotting the layer vs the log number of objects.

fig_area_per_layer (tuple[Figure, Axes], optional)

Matplotlib figure and axes objects from plotting the layer vs the total area of objects.

fig_log_area_per_layer (tuple[Figure, Axes], optional)

Matplotlib figure and axes objects from plotting the layer vs the log of the total area of objects.

area_by_layer (list[list[float]], optional)

List of the area of each object within a given layer.

cumulative_area_by_layer (DataFrame, optional)

List of pandas dataframes of the sorted area, cumulative sum and cumulative fraction.

hcfa (DataFrame, optional)

Pandas dataframes of the Half Cumulative Fraction of the total Area for each layer.

centroid_by_layer (list[list[tuple[float, float]]], optional)

List of the centroid (as a tuple) of each object within a given layer.

feret_maximum_by_layer (list[list[float]], optional)

List of the maximum feret distance of each object within a given layer.

statistics DataFrame

Data frame of statistics about each pore on each layer. At a bare minimum it will contain the area of each pore, but optionally can contain the feret_max_diameter and centroid coordinates of each pore.

Source code in src/afmslicer/classes.py
@dataclass(
    repr=True,
    eq=True,
    config=ConfigDict(arbitrary_types_allowed=True, validate_assignment=True),
    validate_on_init=True,
)
class AFMSlicer(TopoStats):  # type: ignore[misc]
    """
    Class for AFMSlicer data and attributes.

    The class inherits ``TopoStats`` class and has all of its attributes such as ``image``, ``image_original``,
    ``filename`` and ``pixel_to_nm_scaling`` which are used (as well as others which are not used such as
    ``grain_crops``).

    Attributes
    ----------
    image : npt.NDArray[np.float64]
        Two-dimensional array of heights after filtering/flattening.
    image_original : npt.NDArray[np.float64]
        Two-dimensional array of original heights.
    filename : str
        Image filename.
    pixel_to_nm_scaling : float
        Pixel to nano-metre scaling factor.
    layers : npt.NDArray[np.float64], optional
        The boundaries of heights for sliced layers to be taken through the original image.
    sliced_array : npt.NDArray[np.float64], optional
        Three dimensional array of ``slices`` of the original ``image``.
    sliced_mask : npt.NDArray[bool], optional
        A three dimensional array of ``slices`` where each layer is a mask for the heights given in ``layers``.
    sliced_segments : npt.NDArray[np.int32]
        A three dimensional array of ``slices`` where each layer has been segmented.
    sliced_segments_clean : npt.NDArray[np.int32]
        A three dimensional array of ``slices`` where small objects have been masked. The threshold for masking comes
        from the configuration file under ``slicing.minimum_size`` and is ``8000`` nanometres squared by default.
    sliced_region_properties : list[list[Any]]
        A list of ``region_props`` for each object in each layer. There is one list for each layer.
    segment_method : str, optional
        Method for segmenting individual layers.
    min_height : float, optional
        Minimum height. Determined from the data if not provided.
    max_height : float, optional
        Maximum height. Determined from the data if not provided.
    slices : int, optional
        The number of slices taken through the image between the ``min_height`` and ``max_height``.
    full_width_half_max : tuple[int, int]
        The lower and upper bound of the Full Width Half Max from the distribution of the number of pores per
        layer. Used to select the layers whose areas are of interest and are plotted.
    fig_objects_per_layer : tuple[plt.Figure, plt.Axes], optional
        Matplotlib figure and axes objects from plotting the layer vs the number of objects.
    fig_log_objects_per_layer : tuple[plt.Figure, plt.Axes], optional
        Matplotlib figure and axes objects from plotting the layer vs the log number of objects.
    fig_area_per_layer : tuple[plt.Figure, plt.Axes], optional
        Matplotlib figure and axes objects from plotting the layer vs the total area of objects.
    fig_log_area_per_layer : tuple[plt.Figure, plt.Axes], optional
        Matplotlib figure and axes objects from plotting the layer vs the log of the total area of objects.
    area_by_layer : list[list[float]], optional
        List of the area of each object within a given layer.
    cumulative_area_by_layer : pd.DataFrame, optional
        List of pandas dataframes of the sorted area, cumulative sum and cumulative fraction.
    hcfa : pd.DataFrame, optional
        Pandas dataframes of the Half Cumulative Fraction of the total Area for each layer.
    centroid_by_layer : list[list[tuple[float, float]]], optional
        List of the centroid (as a tuple) of each object within a given layer.
    feret_maximum_by_layer : list[list[float]], optional
        List of the maximum feret distance of each object within a given layer.
    statistics : pd.DataFrame
        Data frame of statistics about each pore on each layer. At a bare minimum it will contain the ``area`` of each
        pore, but optionally can contain the ``feret_max_diameter`` and ``centroid`` coordinates of each pore.
    """

    # We may need to set a default_factory see
    # https://stackoverflow.com/questions/70306311/pydantic-initialize-numpy-ndarray
    # https://docs.pydantic.dev/latest/concepts/dataclasses/
    layers: npt.NDArray[np.float64] | None = None
    sliced_array: npt.NDArray[np.float64] | None = None
    sliced_mask: npt.NDArray[np.bool] | None = None
    sliced_segments: npt.NDArray[np.int32] | None = None
    sliced_segments_clean: npt.NDArray[np.int32] | None = None
    sliced_region_properties: list[Any] | None = None
    sliced_clean_region_properties: list[Any] | None = None
    pores_per_layer: list[int] | None = None
    segment_method: str | None = None
    minimum_size: int | float | None = None
    min_height: float | None = None
    max_height: float | None = None
    slices: int | None = None
    full_width_half_max: tuple[int, int] | None = None
    fig_objects_per_layer: tuple[plt.Figure, plt.Axes] | None = None
    fig_log_objects_per_layer: tuple[plt.Figure, plt.Axes] | None = None
    fig_area_per_layer: tuple[plt.Figure, plt.Axes] | None = None
    fig_log_area_per_layer: tuple[plt.Figure, plt.Axes] | None = None
    area_by_layer: list[list[float]] | None = None
    cumulative_area_by_layer: list[pd.DataFrame] | None = None
    hcfa: pd.DataFrame | None = None
    centroid_by_layer: list[list[tuple[float, float]]] | None = None
    feret_maximum_by_layer: list[list[float]] | None = None
    pores_per_layer_mean: float | None = None
    pores_per_layer_std: float | None = None
    layer_max_pores: int | None = None
    statistics: pd.DataFrame | None = None
    afmslicer_version: str | None = None
    # slice_max_pores: dict[str, int | float] | None = None

    def __post_init__(self) -> None:
        """
        Set attributes for the ``AFMSlice`` class on instantiation.
        """
        self.slices = 255 if self.slices is None else self.slices
        # If no config is supplied we load the default
        if self.config is None:
            self.config = get_data(package="afmslicer", resource="default_config.yaml")
        if self.image is not None:
            self.min_height = (
                np.min(self.image) if self.min_height is None else self.min_height
            )
            self.max_height = (
                np.max(self.image) if self.max_height is None else self.max_height
            )
        else:
            self.min_height = (
                np.min(self.image_original)
                if self.min_height is None
                else self.min_height
            )
            self.max_height = (
                np.max(self.image_original)
                if self.max_height is None
                else self.max_height
            )
        self.layers = (
            np.linspace(self.min_height, self.max_height, self.slices)
            if self.layers is None
            else self.layers
        )
        self.segment_method = (
            self.config["slicing"]["segment_method"]
            if self.segment_method is None
            else self.segment_method
        )
        self.minimum_size = (
            self.config["slicing"]["minimum_size"]
            if self.minimum_size is None
            else self.minimum_size
        )
        self.filename = self.image_name if self.filename is None else self.filename
        self.image_name = self.filename if self.image_name is None else self.image_name
        self.afmslicer_version = (
            __version__ if self.afmslicer_version is None else self.afmslicer_version
        )
        logger.info(f"[{self.filename}] : AFMSlicer object created. 🔪")
        self.config["output_dir"] = self.config["output_dir"] / self.filename
        logger.info(
            f"[{self.filename}] : Output will be in {self.config['output_dir']}"
        )

    def update_heights(self) -> None:
        """
        Update minimum and maximum height attributes.

        Initially heights are taken from the raw image stored in ``AFMSlicer.image_original``. Flattening with
        ``Filters`` changes the range of these values so we need to update the heights.
        """
        self.min_height = np.min(self.image)
        self.max_height = np.max(self.image)

    def slice_image(self) -> None:
        """
        Slice the image.
        """
        # Slice the array (i.e. duplicate it `slices` times)
        if self.image is None:
            logger.warning(
                f"[{self.filename}] 🚨 No flattenend image detected, using original. 🚨"
            )
            self.image = self.image_original
        self.sliced_array = slicer.slicer(heights=self.image, slices=self.slices)
        logger.debug(f"[{self.filename}] : Created {self.slices} 🔪")
        # Update heights after flattening
        self.update_heights()
        # Mask each layer
        self.sliced_mask = slicer.mask_slices(
            stacked_array=self.sliced_array,
            slices=self.slices,
            layers=self.layers,
            min_height=self.min_height,
            max_height=self.max_height,
        )
        logger.debug(f"[{self.filename}] : Mask created 👹")
        # Detect segments within each slice
        self.sliced_segments = slicer.segment_slices(
            self.sliced_mask,
            method=self.segment_method,
        )
        logger.debug(f"[{self.filename}] : Slices segmented")
        # ns-rse 2025-12-10 : Consider first pass of areas using skimage.measure.moments() to quickly get _just_ areas
        # so that small objects can be excluded, only then calculate regionprops on remaining items. Could possibly be
        # extended to only do regionprops on the layers of interest after the Full-Width Half Max has been determeind.
        # Calculate region properties
        self.sliced_region_properties = slicer.region_properties_by_slices(
            array=self.sliced_segments, spacing=self.pixel_to_nm_scaling
        )
        logger.debug(f"[{self.filename}] : Region properties calculated")
        # Remove small objects
        self.config["slicing"]["minimum_size"] = 0
        if self.config["slicing"]["minimum_size"] > 0:
            self.sliced_segments_clean = slicer.mask_small_artefacts_all_layers(
                labelled_array=self.sliced_segments,
                properties=self.sliced_region_properties,
                minimum_size=self.minimum_size,
            )
            logger.debug(
                f"[{self.filename}] : Small artefacts masked across all layers"
            )
        else:
            self.sliced_segments_clean = self.sliced_segments
        # ns-rse 2025-12-10 : Need to redo sliced_region_properties using "clean" version with small regions masked
        # Calculate region properties on clean slices after removal of small objects
        self.sliced_clean_region_properties = slicer.region_properties_by_slices(
            array=self.sliced_segments_clean, spacing=self.pixel_to_nm_scaling
        )
        logger.debug(f"[{self.filename}] : Clean region properties calculated")
        # Count the number of pores per layer
        self.pores_per_layer = statistics.count_pores(
            sliced_region_properties=self.sliced_region_properties
        )
        logger.debug(f"[{self.filename}] : Pores per layer extracted")
        if self.config["plotting"]["plot_layers"]:
            # Plot all segmented layers
            plotting.plot_all_layers(
                array=self.sliced_segments_clean,
                img_name=self.filename,
                outdir=self.config["output_dir"],
                format=self.config["plotting"]["format"],
                cmap=self.config["plotting"]["cmap"],
            )
        if self.config["plotting"]["plot_gif"]:
            # Create a GIF of all layers
            plotting.generate_gif(
                sliced_segments=self.sliced_segments_clean,
                outdir=self.config["output_dir"],
                img_name=self.filename,
                duration=self.config["plotting"]["gif_duration"],
                loop=self.config["plotting"]["gif_loop"],
            )
        if self.config["plotting"]["plot_summary"]:
            # Plot pores per layer
            self.fig_objects_per_layer = plotting.plot_pores_by_layer(
                pores_per_layer=self.pores_per_layer,
                img_name=self.filename,
                outdir=self.config["output_dir"],
                format=self.config["plotting"]["format"],
                log=False,
                grid=self.config["plotting"]["grid"],
            )
        # Plot pores per layer (log scale)
        # self.fig_log_objects_per_layer = plotting.plot_pores_by_layer(
        #     pores_per_layer=self.pores_per_layer,
        #     img_name=self.filename,
        #     outdir=self.config["output_dir"],
        #     format=self.config["plotting"]["format"],
        #     log=True,
        # )
        # Optionally calculate additional statistics
        # Areas
        if self.config["slicing"]["area"]:
            logger.debug(f"[{self.filename}] : Calculating areas")
            # Calculate the area by layer
            self.area_by_layer = statistics.area_pores(
                sliced_region_properties=self.sliced_region_properties
            )
            # Calculate the cumulative sum and fraction of areas across layers
            logger.debug(f"[{self.filename}] : Calculating cumulative areas")
            self.cumulative_area_by_layer = statistics.cumulative_areas(
                areas=self.area_by_layer
            )
            # Write cumulative areas across all layers to csv
            statistics.concatenate_areas(areas=self.cumulative_area_by_layer).to_csv(
                self.config["output_dir"] / "cumulative_area.csv",
                index=False,
            )
            # HCFA
            logger.debug(f"[{self.filename}] : Calculating HCFA areas")
            self.hcfa = statistics.hcfa(
                areas=self.cumulative_area_by_layer,
                fraction=self.config["slicing"]["fraction"],
            )
            self.hcfa.to_csv(self.config["output_dir"] / "hcfa.csv", index=False)
            self.hcfa["image"] = self.filename
            # Calculate PDF of objects per layer
            pdf = statistics.calculate_pdf(array=self.pores_per_layer)
            logger.debug(f"[{self.filename}] : Calculating FWHM areas")
            self.full_width_half_max = statistics.full_width_half_max(pdf=pdf["y"])
            # Plot area per layer
            # subset self.area_by_layer selecting the full_width_half_max derived from number of pores per layer
            self.fig_area_per_layer = plotting.plot_area_by_layer(
                area_per_layer=self.area_by_layer,
                img_name=self.filename,
                outdir=self.config["output_dir"],
                format=self.config["plotting"]["format"],
                fwhm=self.full_width_half_max,
                log=False,
                grid=self.config["plotting"]["grid"],
            )
            # Plot log area per layer
            # subset self.area_by_layer selecting the full_width_half_max derived from number of pores per layer
            self.fig_log_area_per_layer = plotting.plot_area_by_layer(
                area_per_layer=self.area_by_layer,
                img_name=self.filename,
                outdir=self.config["output_dir"],
                format=self.config["plotting"]["format"],
                fwhm=self.full_width_half_max,
                log=True,
                grid=self.config["plotting"]["grid"],
            )
        # Centroid
        if self.config["slicing"]["centroid"]:
            self.centroid_by_layer = statistics.centroid_pores(
                sliced_region_properties=self.sliced_region_properties
            )
        # Feret Maximum
        if self.config["slicing"]["feret_maximum"]:
            self.feret_maximum_by_layer = statistics.feret_diameter_maximum_pores(
                sliced_region_properties=self.sliced_region_properties
            )
        self._extract_statistics()

    def _extract_statistics(self) -> None:
        """Extract statistics from the ``sliced_region_properties`` attribute."""
        try:
            stats = statistics.create_statistics_dictionary(
                sliced_region_properties=self.sliced_region_properties,
                feret_maximum=self.config["slicing"]["feret_maximum"],
                centroid=self.config["slicing"]["centroid"],
            )
            self.statistics = io.dict_to_df(data=stats)
        except AttributeError:
            raise
        except TypeError:  # pylint: disable=try-except-raise
            raise

__post_init__()

Set attributes for the AFMSlice class on instantiation.

Source code in src/afmslicer/classes.py
def __post_init__(self) -> None:
    """
    Set attributes for the ``AFMSlice`` class on instantiation.
    """
    self.slices = 255 if self.slices is None else self.slices
    # If no config is supplied we load the default
    if self.config is None:
        self.config = get_data(package="afmslicer", resource="default_config.yaml")
    if self.image is not None:
        self.min_height = (
            np.min(self.image) if self.min_height is None else self.min_height
        )
        self.max_height = (
            np.max(self.image) if self.max_height is None else self.max_height
        )
    else:
        self.min_height = (
            np.min(self.image_original)
            if self.min_height is None
            else self.min_height
        )
        self.max_height = (
            np.max(self.image_original)
            if self.max_height is None
            else self.max_height
        )
    self.layers = (
        np.linspace(self.min_height, self.max_height, self.slices)
        if self.layers is None
        else self.layers
    )
    self.segment_method = (
        self.config["slicing"]["segment_method"]
        if self.segment_method is None
        else self.segment_method
    )
    self.minimum_size = (
        self.config["slicing"]["minimum_size"]
        if self.minimum_size is None
        else self.minimum_size
    )
    self.filename = self.image_name if self.filename is None else self.filename
    self.image_name = self.filename if self.image_name is None else self.image_name
    self.afmslicer_version = (
        __version__ if self.afmslicer_version is None else self.afmslicer_version
    )
    logger.info(f"[{self.filename}] : AFMSlicer object created. 🔪")
    self.config["output_dir"] = self.config["output_dir"] / self.filename
    logger.info(
        f"[{self.filename}] : Output will be in {self.config['output_dir']}"
    )

slice_image()

Slice the image.

Source code in src/afmslicer/classes.py
def slice_image(self) -> None:
    """
    Slice the image.
    """
    # Slice the array (i.e. duplicate it `slices` times)
    if self.image is None:
        logger.warning(
            f"[{self.filename}] 🚨 No flattenend image detected, using original. 🚨"
        )
        self.image = self.image_original
    self.sliced_array = slicer.slicer(heights=self.image, slices=self.slices)
    logger.debug(f"[{self.filename}] : Created {self.slices} 🔪")
    # Update heights after flattening
    self.update_heights()
    # Mask each layer
    self.sliced_mask = slicer.mask_slices(
        stacked_array=self.sliced_array,
        slices=self.slices,
        layers=self.layers,
        min_height=self.min_height,
        max_height=self.max_height,
    )
    logger.debug(f"[{self.filename}] : Mask created 👹")
    # Detect segments within each slice
    self.sliced_segments = slicer.segment_slices(
        self.sliced_mask,
        method=self.segment_method,
    )
    logger.debug(f"[{self.filename}] : Slices segmented")
    # ns-rse 2025-12-10 : Consider first pass of areas using skimage.measure.moments() to quickly get _just_ areas
    # so that small objects can be excluded, only then calculate regionprops on remaining items. Could possibly be
    # extended to only do regionprops on the layers of interest after the Full-Width Half Max has been determeind.
    # Calculate region properties
    self.sliced_region_properties = slicer.region_properties_by_slices(
        array=self.sliced_segments, spacing=self.pixel_to_nm_scaling
    )
    logger.debug(f"[{self.filename}] : Region properties calculated")
    # Remove small objects
    self.config["slicing"]["minimum_size"] = 0
    if self.config["slicing"]["minimum_size"] > 0:
        self.sliced_segments_clean = slicer.mask_small_artefacts_all_layers(
            labelled_array=self.sliced_segments,
            properties=self.sliced_region_properties,
            minimum_size=self.minimum_size,
        )
        logger.debug(
            f"[{self.filename}] : Small artefacts masked across all layers"
        )
    else:
        self.sliced_segments_clean = self.sliced_segments
    # ns-rse 2025-12-10 : Need to redo sliced_region_properties using "clean" version with small regions masked
    # Calculate region properties on clean slices after removal of small objects
    self.sliced_clean_region_properties = slicer.region_properties_by_slices(
        array=self.sliced_segments_clean, spacing=self.pixel_to_nm_scaling
    )
    logger.debug(f"[{self.filename}] : Clean region properties calculated")
    # Count the number of pores per layer
    self.pores_per_layer = statistics.count_pores(
        sliced_region_properties=self.sliced_region_properties
    )
    logger.debug(f"[{self.filename}] : Pores per layer extracted")
    if self.config["plotting"]["plot_layers"]:
        # Plot all segmented layers
        plotting.plot_all_layers(
            array=self.sliced_segments_clean,
            img_name=self.filename,
            outdir=self.config["output_dir"],
            format=self.config["plotting"]["format"],
            cmap=self.config["plotting"]["cmap"],
        )
    if self.config["plotting"]["plot_gif"]:
        # Create a GIF of all layers
        plotting.generate_gif(
            sliced_segments=self.sliced_segments_clean,
            outdir=self.config["output_dir"],
            img_name=self.filename,
            duration=self.config["plotting"]["gif_duration"],
            loop=self.config["plotting"]["gif_loop"],
        )
    if self.config["plotting"]["plot_summary"]:
        # Plot pores per layer
        self.fig_objects_per_layer = plotting.plot_pores_by_layer(
            pores_per_layer=self.pores_per_layer,
            img_name=self.filename,
            outdir=self.config["output_dir"],
            format=self.config["plotting"]["format"],
            log=False,
            grid=self.config["plotting"]["grid"],
        )
    # Plot pores per layer (log scale)
    # self.fig_log_objects_per_layer = plotting.plot_pores_by_layer(
    #     pores_per_layer=self.pores_per_layer,
    #     img_name=self.filename,
    #     outdir=self.config["output_dir"],
    #     format=self.config["plotting"]["format"],
    #     log=True,
    # )
    # Optionally calculate additional statistics
    # Areas
    if self.config["slicing"]["area"]:
        logger.debug(f"[{self.filename}] : Calculating areas")
        # Calculate the area by layer
        self.area_by_layer = statistics.area_pores(
            sliced_region_properties=self.sliced_region_properties
        )
        # Calculate the cumulative sum and fraction of areas across layers
        logger.debug(f"[{self.filename}] : Calculating cumulative areas")
        self.cumulative_area_by_layer = statistics.cumulative_areas(
            areas=self.area_by_layer
        )
        # Write cumulative areas across all layers to csv
        statistics.concatenate_areas(areas=self.cumulative_area_by_layer).to_csv(
            self.config["output_dir"] / "cumulative_area.csv",
            index=False,
        )
        # HCFA
        logger.debug(f"[{self.filename}] : Calculating HCFA areas")
        self.hcfa = statistics.hcfa(
            areas=self.cumulative_area_by_layer,
            fraction=self.config["slicing"]["fraction"],
        )
        self.hcfa.to_csv(self.config["output_dir"] / "hcfa.csv", index=False)
        self.hcfa["image"] = self.filename
        # Calculate PDF of objects per layer
        pdf = statistics.calculate_pdf(array=self.pores_per_layer)
        logger.debug(f"[{self.filename}] : Calculating FWHM areas")
        self.full_width_half_max = statistics.full_width_half_max(pdf=pdf["y"])
        # Plot area per layer
        # subset self.area_by_layer selecting the full_width_half_max derived from number of pores per layer
        self.fig_area_per_layer = plotting.plot_area_by_layer(
            area_per_layer=self.area_by_layer,
            img_name=self.filename,
            outdir=self.config["output_dir"],
            format=self.config["plotting"]["format"],
            fwhm=self.full_width_half_max,
            log=False,
            grid=self.config["plotting"]["grid"],
        )
        # Plot log area per layer
        # subset self.area_by_layer selecting the full_width_half_max derived from number of pores per layer
        self.fig_log_area_per_layer = plotting.plot_area_by_layer(
            area_per_layer=self.area_by_layer,
            img_name=self.filename,
            outdir=self.config["output_dir"],
            format=self.config["plotting"]["format"],
            fwhm=self.full_width_half_max,
            log=True,
            grid=self.config["plotting"]["grid"],
        )
    # Centroid
    if self.config["slicing"]["centroid"]:
        self.centroid_by_layer = statistics.centroid_pores(
            sliced_region_properties=self.sliced_region_properties
        )
    # Feret Maximum
    if self.config["slicing"]["feret_maximum"]:
        self.feret_maximum_by_layer = statistics.feret_diameter_maximum_pores(
            sliced_region_properties=self.sliced_region_properties
        )
    self._extract_statistics()

update_heights()

Update minimum and maximum height attributes.

Initially heights are taken from the raw image stored in AFMSlicer.image_original. Flattening with Filters changes the range of these values so we need to update the heights.

Source code in src/afmslicer/classes.py
def update_heights(self) -> None:
    """
    Update minimum and maximum height attributes.

    Initially heights are taken from the raw image stored in ``AFMSlicer.image_original``. Flattening with
    ``Filters`` changes the range of these values so we need to update the heights.
    """
    self.min_height = np.min(self.image)
    self.max_height = np.max(self.image)