Skip to content

Tabular

siapy.datasets.tabular

MetaDataEntity

Bases: BaseModel

image_idx instance-attribute

image_idx: int

image_filepath instance-attribute

image_filepath: Path

camera_id instance-attribute

camera_id: str

shape_idx instance-attribute

shape_idx: int

shape_type instance-attribute

shape_type: str

shape_label instance-attribute

shape_label: str | None

TabularDataEntity

Bases: MetaDataEntity

image_idx instance-attribute

image_idx: int

image_filepath instance-attribute

image_filepath: Path

camera_id instance-attribute

camera_id: str

shape_idx instance-attribute

shape_idx: int

shape_type instance-attribute

shape_type: str

shape_label instance-attribute

shape_label: str | None

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

signatures instance-attribute

signatures: Signatures

TabularDataset dataclass

TabularDataset(container: ImageContainerType)
PARAMETER DESCRIPTION
container

TYPE: ImageContainerType

Source code in siapy/datasets/tabular.py
34
35
36
37
38
39
40
def __init__(self, container: ImageContainerType):
    self._image_set = (
        SpectralImageSet([container])
        if isinstance(container, SpectralImage)
        else container
    )
    self._data_entities: list[TabularDataEntity] = []

image_set property

image_set: SpectralImageSet

data_entities property

data_entities: list[TabularDataEntity]

process_image_data

process_image_data()
Source code in siapy/datasets/tabular.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def process_image_data(self):
    self.data_entities.clear()
    for image_idx, image in enumerate(self.image_set):
        for shape_idx, shape in enumerate(image.geometric_shapes.shapes):
            signatures = image.to_signatures(shape.convex_hull())
            entity = TabularDataEntity(
                image_idx=image_idx,
                shape_idx=shape_idx,
                image_filepath=image.filepath,
                camera_id=image.camera_id,
                shape_type=shape.shape_type,
                shape_label=shape.label,
                signatures=signatures,
            )
            self.data_entities.append(entity)

generate_dataset_data

generate_dataset_data(mean_signatures=True) -> TabularDatasetData
PARAMETER DESCRIPTION
mean_signatures

DEFAULT: True

Source code in siapy/datasets/tabular.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def generate_dataset_data(self, mean_signatures=True) -> TabularDatasetData:
    self._check_data_entities()
    pixels_dfs = []
    signals_dfs = []
    metadata_dfs = []
    for entity in self.data_entities:
        signatures_df = entity.signatures.to_dataframe().dropna()
        if mean_signatures:
            signatures_df = signatures_df.mean().to_frame().T

        signatures_len = len(signatures_df)
        metadata_df = pd.DataFrame(
            {
                "image_idx": [str(entity.image_idx)] * signatures_len,
                "image_filepath": [str(entity.image_filepath)] * signatures_len,
                "camera_id": [entity.camera_id] * signatures_len,
                "shape_idx": [str(entity.shape_idx)] * signatures_len,
                "shape_type": [entity.shape_type] * signatures_len,
                "shape_label": [entity.shape_label] * signatures_len,
            }
        )

        assert (
            list(metadata_df.columns) == list(MetaDataEntity.model_fields.keys())
        ), "Sanity check failed! The columns in metadata_df do not match MetaDataEntity fields."

        signatures = Signatures.from_dataframe(signatures_df)

        pixels_dfs.append(signatures.pixels.df)
        signals_dfs.append(signatures.signals.df)
        metadata_dfs.append(metadata_df)

    return TabularDatasetData(
        pixels=pd.concat(pixels_dfs, ignore_index=True),
        signals=pd.concat(signals_dfs, ignore_index=True),
        metadata=pd.concat(metadata_dfs, ignore_index=True),
    )