phenotypic.abc_.PostMeasurement#

class phenotypic.abc_.PostMeasurement[source]

Bases: BaseOperation, ABC

Transform a measurement DataFrame after feature extraction.

PostMeasurement is the abstract base class for operations that reshape, enrich, or clean measurement DataFrames produced by the pipeline’s measurement step. Unlike MeasureFeatures (which extracts data from images), PostMeasurement operates on the already-assembled DataFrame.

Post-measurement transforms run after all MeasureFeatures have executed and their results have been merged. They receive the complete DataFrame and return a modified copy.

Parameters:

None

Returns:

The transformed measurement DataFrame.

Return type:

pd.DataFrame

Examples

Subclass to create a custom post-measurement transform:

>>> from phenotypic.abc_ import PostMeasurement
>>> import pandas as pd
>>> class AddConstant(PostMeasurement):
...     def __init__(self, column, value):
...         super().__init__()
...         self.column = column
...         self.value = value
...     def _operate(self, df):
...         df[self.column] = self.value
...         return df
>>> post = AddConstant("Metadata_Flag", "OK")
>>> df = pd.DataFrame({"ObjectLabel": [1, 2]})
>>> result = post.apply(df)
>>> list(result.columns)
['ObjectLabel', 'Metadata_Flag']

Methods

__init__

apply

Apply the post-measurement transform.

apply(df: pandas.DataFrame) pandas.DataFrame[source]

Apply the post-measurement transform.

Parameters:

df (pandas.DataFrame) – The merged measurement DataFrame.

Returns:

The transformed DataFrame.

Return type:

pandas.DataFrame

__del__()

Automatically stop tracemalloc when the object is deleted.