sinapsis-data-visualization 0.1.13__tar.gz → 0.1.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sinapsis_data_visualization-0.1.13/src/sinapsis_data_visualization.egg-info → sinapsis_data_visualization-0.1.14}/PKG-INFO +2 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/README.md +1 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/pyproject.toml +1 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/annotation_drawer_tools.py +14 -13
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/plot_distributions.py +4 -3
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/scikit_pca_analysis.py +1 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/tags.py +1 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/__init__.py +1 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/base_annotation_drawer.py +4 -2
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/base_visualization_template.py +11 -10
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/bbox_drawer.py +2 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/data_distribution_visualization.py +17 -10
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/key_points_drawer.py +2 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/label_drawer.py +5 -2
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/oriented_bbox_drawer.py +2 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/segmentation_mask_drawer.py +4 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/templates/tabular_data_visualization.py +29 -25
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14/src/sinapsis_data_visualization.egg-info}/PKG-INFO +2 -1
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/LICENSE +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/setup.cfg +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/__init__.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/__init__.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/__init__.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/annotation_drawer_types.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/color_utils.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization/helpers/detection_utils.py +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization.egg-info/SOURCES.txt +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization.egg-info/dependency_links.txt +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization.egg-info/requires.txt +0 -0
- {sinapsis_data_visualization-0.1.13 → sinapsis_data_visualization-0.1.14}/src/sinapsis_data_visualization.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-data-visualization
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
4
4
|
Summary: Templates to perform visualization of data distributions and image annotations.
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -19,6 +19,7 @@ Provides-Extra: all
|
|
|
19
19
|
Requires-Dist: sinapsis-data-visualization[visualization-matplotlib]; extra == "all"
|
|
20
20
|
Dynamic: license-file
|
|
21
21
|
|
|
22
|
+
[](https://github.com/Sinapsis-AI/sinapsis-data-tools/blob/main/README.es.md)
|
|
22
23
|
<h1 align="center">
|
|
23
24
|
<br>
|
|
24
25
|
<a href="https://sinapsis.tech/">
|
|
@@ -236,17 +236,18 @@ def get_extra_ann_labels(
|
|
|
236
236
|
"""
|
|
237
237
|
text_y_offsets = []
|
|
238
238
|
extra_str_repr = []
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
239
|
+
if annotation.extra_labels is not None:
|
|
240
|
+
for label_k, label_v in annotation.extra_labels.items():
|
|
241
|
+
extra_text: str = label_k
|
|
242
|
+
if isinstance(label_v, (float, int)):
|
|
243
|
+
extra_text = get_numeric_str(extra_text, label_v)
|
|
244
|
+
else:
|
|
245
|
+
extra_text = f"{label_k}: {label_v}"
|
|
246
|
+
extra_text_w, extra_text_h = get_text_size(extra_text, text_style)
|
|
247
|
+
|
|
248
|
+
extra_text_h += spacing
|
|
249
|
+
text_h += extra_text_h
|
|
250
|
+
text_w = max(extra_text_w, text_w)
|
|
251
|
+
text_y_offsets.append(extra_text_h)
|
|
252
|
+
extra_str_repr.append(extra_text)
|
|
252
253
|
return text_y_offsets, extra_str_repr, text_h, text_w
|
|
@@ -4,17 +4,18 @@ from typing import Sequence
|
|
|
4
4
|
import matplotlib
|
|
5
5
|
import matplotlib.pyplot as plt
|
|
6
6
|
import numpy as np
|
|
7
|
+
from matplotlib.figure import Figure
|
|
7
8
|
from sinapsis_core.utils.logging_utils import sinapsis_logger
|
|
8
9
|
from sklearn.metrics import ConfusionMatrixDisplay
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def plot_distribution(
|
|
12
|
-
figure:
|
|
13
|
+
figure: Figure,
|
|
13
14
|
labels: Sequence[str] | np.ndarray,
|
|
14
15
|
counts: list[float] | np.ndarray,
|
|
15
16
|
plot_type: str,
|
|
16
17
|
kwargs: dict,
|
|
17
|
-
) ->
|
|
18
|
+
) -> Figure:
|
|
18
19
|
"""
|
|
19
20
|
Base method to plot a distribution.
|
|
20
21
|
|
|
@@ -168,7 +169,7 @@ def plot_confusion_matrix(labels: Sequence[str], counts: np.ndarray, kwargs: dic
|
|
|
168
169
|
kwargs (dict): Additional keyword arguments (cmap, etc.)
|
|
169
170
|
"""
|
|
170
171
|
|
|
171
|
-
cmap = kwargs.pop("cmap",
|
|
172
|
+
cmap = kwargs.pop("cmap", matplotlib.colormaps["Blues"])
|
|
172
173
|
disp = ConfusionMatrixDisplay(confusion_matrix=counts, display_labels=labels)
|
|
173
174
|
disp.plot(cmap=cmap, **kwargs)
|
|
174
175
|
plt.tight_layout()
|
|
@@ -29,7 +29,7 @@ def perform_k_means_analysis(feature_vec: np.ndarray) -> tuple[np.ndarray, np.nd
|
|
|
29
29
|
return labels, reduced_vectors
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def pre_process_images(images: list[ImagePacket], size: int = 28) -> np.ndarray
|
|
32
|
+
def pre_process_images(images: list[ImagePacket], size: int = 28) -> np.ndarray:
|
|
33
33
|
"""Resizes and flatten images to homogenize them
|
|
34
34
|
|
|
35
35
|
Args:
|
|
@@ -53,6 +53,8 @@ class BaseAnnotationDrawer(Template, abc.ABC):
|
|
|
53
53
|
overwrite: bool = False
|
|
54
54
|
randomized_color: bool = True
|
|
55
55
|
|
|
56
|
+
attributes: AttributesBaseModel
|
|
57
|
+
|
|
56
58
|
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
57
59
|
"""Initializes the Image Annotation Drawer with the given attributes."""
|
|
58
60
|
super().__init__(attributes)
|
|
@@ -88,7 +90,7 @@ class BaseAnnotationDrawer(Template, abc.ABC):
|
|
|
88
90
|
"""
|
|
89
91
|
return get_color_rgb_tuple(
|
|
90
92
|
color_map=self.COLOR_MAP,
|
|
91
|
-
class_id=ann.label,
|
|
93
|
+
class_id=int(ann.label) if ann.label is not None else None,
|
|
92
94
|
randomized=self.attributes.randomized_color,
|
|
93
95
|
)
|
|
94
96
|
|
|
@@ -154,7 +156,7 @@ class BaseAnnotationDrawer(Template, abc.ABC):
|
|
|
154
156
|
ImagePacket(
|
|
155
157
|
content=annotated_image,
|
|
156
158
|
color_space=image_packet.color_space,
|
|
157
|
-
source=f"a_{Path(image_packet
|
|
159
|
+
source=f"a_{Path(getattr(image_packet, 'source')).name}",
|
|
158
160
|
)
|
|
159
161
|
)
|
|
160
162
|
container.images.extend(annotated_images)
|
|
@@ -5,10 +5,10 @@ from abc import ABC, abstractmethod
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
|
-
import matplotlib
|
|
9
8
|
import matplotlib.pyplot as plt
|
|
10
9
|
import numpy as np
|
|
11
10
|
import PIL.Image
|
|
11
|
+
from matplotlib.figure import Figure
|
|
12
12
|
from pydantic import Field
|
|
13
13
|
from sinapsis_core.data_containers.data_packet import DataContainer, ImagePacket
|
|
14
14
|
from sinapsis_core.template_base import Template
|
|
@@ -90,6 +90,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
90
90
|
tags=[Tags.IMAGE, Tags.MATPLOTLIB, Tags.VISUALIZATION],
|
|
91
91
|
)
|
|
92
92
|
AttributesBaseModel = BasePlotAttributes
|
|
93
|
+
attributes: BasePlotAttributes
|
|
93
94
|
|
|
94
95
|
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
95
96
|
super().__init__(attributes)
|
|
@@ -97,7 +98,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
97
98
|
if self.attributes.save_image_dir and not os.path.exists(self.attributes.save_image_dir):
|
|
98
99
|
os.makedirs(self.attributes.save_image_dir)
|
|
99
100
|
|
|
100
|
-
def create_figure(self, text: str | None = None, rotate_x_ticks: bool = False) ->
|
|
101
|
+
def create_figure(self, text: str | None = None, rotate_x_ticks: bool = False) -> Figure:
|
|
101
102
|
"""
|
|
102
103
|
Creates a matplotlib figure with basic configuration.
|
|
103
104
|
|
|
@@ -106,7 +107,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
106
107
|
rotate_x_ticks (bool): Whether to rotate x-axis tick labels.
|
|
107
108
|
|
|
108
109
|
Returns:
|
|
109
|
-
|
|
110
|
+
Figure: The configured figure.
|
|
110
111
|
"""
|
|
111
112
|
figure = plt.figure(figsize=(self.attributes.fig_width, self.attributes.fig_height))
|
|
112
113
|
plt.xlabel(self.attributes.x_label or "X-Axis")
|
|
@@ -123,7 +124,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
123
124
|
|
|
124
125
|
def save_figure(
|
|
125
126
|
self,
|
|
126
|
-
figure:
|
|
127
|
+
figure: Figure,
|
|
127
128
|
name: str,
|
|
128
129
|
container_id: str | None = None,
|
|
129
130
|
) -> str:
|
|
@@ -131,7 +132,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
131
132
|
Saves the figure to disk and records the path.
|
|
132
133
|
|
|
133
134
|
Args:
|
|
134
|
-
figure (
|
|
135
|
+
figure (Figure): The figure to save.
|
|
135
136
|
name (str): Base name for the figure file.
|
|
136
137
|
container_id (str | None): Optional container ID to append to filename.
|
|
137
138
|
|
|
@@ -156,13 +157,13 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
156
157
|
|
|
157
158
|
return fig_path
|
|
158
159
|
|
|
159
|
-
def add_figure_to_container(self, container: DataContainer, figure:
|
|
160
|
+
def add_figure_to_container(self, container: DataContainer, figure: Figure, name: str) -> None:
|
|
160
161
|
"""
|
|
161
162
|
Adds the figure to the container as an image packet if requested.
|
|
162
163
|
|
|
163
164
|
Args:
|
|
164
165
|
container (DataContainer): The data container to update.
|
|
165
|
-
figure (
|
|
166
|
+
figure (Figure): The figure to add.
|
|
166
167
|
name (str): Name key for the figure.
|
|
167
168
|
"""
|
|
168
169
|
if self.attributes.add_to_image_packets:
|
|
@@ -185,7 +186,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
185
186
|
counts: list[float] | np.ndarray,
|
|
186
187
|
text: str | None = None,
|
|
187
188
|
rotate_x_ticks: bool = False,
|
|
188
|
-
) ->
|
|
189
|
+
) -> Figure:
|
|
189
190
|
"""
|
|
190
191
|
Creates a figure, plots data, saves it, and adds it to the container.
|
|
191
192
|
|
|
@@ -198,7 +199,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
198
199
|
rotate_x_ticks (bool): Whether to rotate x-axis tick labels.
|
|
199
200
|
|
|
200
201
|
Returns:
|
|
201
|
-
|
|
202
|
+
Figure: The created figure.
|
|
202
203
|
"""
|
|
203
204
|
figure = self.create_figure(text=text, rotate_x_ticks=rotate_x_ticks)
|
|
204
205
|
|
|
@@ -211,7 +212,7 @@ class BaseVisualizationTemplate(Template, ABC):
|
|
|
211
212
|
)
|
|
212
213
|
|
|
213
214
|
plot_name = f"{plot_type}" if not text else f"{plot_type}_{text}"
|
|
214
|
-
self.save_figure(figure, plot_name, container.container_id)
|
|
215
|
+
self.save_figure(figure, plot_name, str(container.container_id))
|
|
215
216
|
self.add_figure_to_container(container, figure, plot_name)
|
|
216
217
|
return figure
|
|
217
218
|
|
|
@@ -8,7 +8,8 @@ from sinapsis_data_visualization.helpers.tags import Tags
|
|
|
8
8
|
from sinapsis_data_visualization.templates.label_drawer import LabelDrawer
|
|
9
9
|
|
|
10
10
|
BBoxDrawerUIProperties = LabelDrawer.UIProperties
|
|
11
|
-
BBoxDrawerUIProperties.tags
|
|
11
|
+
if BBoxDrawerUIProperties.tags is not None:
|
|
12
|
+
BBoxDrawerUIProperties.tags.extend([Tags.BBOX])
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class BBoxDrawer(LabelDrawer):
|
|
@@ -31,7 +31,8 @@ class DataDistributionAttributes(BasePlotAttributes):
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
DataDistributionUIProperties = BaseVisualizationTemplate.UIProperties
|
|
34
|
-
DataDistributionUIProperties.tags
|
|
34
|
+
if DataDistributionUIProperties.tags is not None:
|
|
35
|
+
DataDistributionUIProperties.tags.extend([Tags.CHARTS, Tags.CLUSTERING, Tags.DISTRIBUTION, Tags.PLOTS])
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
class DataDistributionVisualization(BaseVisualizationTemplate):
|
|
@@ -46,8 +47,9 @@ class DataDistributionVisualization(BaseVisualizationTemplate):
|
|
|
46
47
|
|
|
47
48
|
AttributesBaseModel = DataDistributionAttributes
|
|
48
49
|
UIProperties = DataDistributionUIProperties
|
|
50
|
+
attributes: DataDistributionAttributes
|
|
49
51
|
|
|
50
|
-
def retrieve_labels_from_images(self, container: DataContainer) -> tuple[list[str
|
|
52
|
+
def retrieve_labels_from_images(self, container: DataContainer) -> tuple[list[str], list[int]]:
|
|
51
53
|
"""
|
|
52
54
|
Iterates through the ImagePackets, extracting each of the
|
|
53
55
|
annotations for all of them.
|
|
@@ -55,18 +57,23 @@ class DataDistributionVisualization(BaseVisualizationTemplate):
|
|
|
55
57
|
with that label.
|
|
56
58
|
|
|
57
59
|
Returns:
|
|
58
|
-
tuple[list[str
|
|
60
|
+
tuple[list[str], list[int]]: list of labels and number of coincidences for each label
|
|
59
61
|
"""
|
|
60
|
-
labels: list[str | int] = [ann.label_str for image in container.images for ann in image.annotations]
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
labels: list[str] = []
|
|
64
|
+
for image in container.images:
|
|
65
|
+
for ann in image.annotations:
|
|
66
|
+
if ann.label_str is not None:
|
|
67
|
+
labels.extend([ann.label_str])
|
|
68
|
+
|
|
69
|
+
label_count: dict[str, int] = {}
|
|
63
70
|
for label in labels:
|
|
64
71
|
label_count[label] = label_count.get(label, 0) + 1
|
|
65
72
|
|
|
66
73
|
labels, counts = list(label_count.keys()), list(label_count.values())
|
|
67
74
|
return labels, counts
|
|
68
75
|
|
|
69
|
-
def process_cluster(self, container: DataContainer) -> tuple[list[
|
|
76
|
+
def process_cluster(self, container: DataContainer) -> tuple[list[str], np.ndarray]:
|
|
70
77
|
"""
|
|
71
78
|
For the k-means clustering, the images need to be flattened first
|
|
72
79
|
and then returned as a reduced vector. This method calls the pre_process_images
|
|
@@ -79,15 +86,15 @@ class DataDistributionVisualization(BaseVisualizationTemplate):
|
|
|
79
86
|
container (DataContainer): Container to extract the images from
|
|
80
87
|
|
|
81
88
|
Returns:
|
|
82
|
-
list[str
|
|
89
|
+
list[str]: list of labels
|
|
83
90
|
np.ndarray : transformed values from the pca analysis
|
|
84
91
|
"""
|
|
85
92
|
images = container.images
|
|
86
93
|
feature_arr = pre_process_images(images)
|
|
87
94
|
label, counts = perform_k_means_analysis(feature_arr)
|
|
88
|
-
return label, counts
|
|
95
|
+
return label.tolist(), counts.tolist()
|
|
89
96
|
|
|
90
|
-
def get_data_for_visualization(self, container: DataContainer) -> tuple[list[str
|
|
97
|
+
def get_data_for_visualization(self, container: DataContainer) -> tuple[list[str], list[int]]:
|
|
91
98
|
"""
|
|
92
99
|
Gets labels and counts from images in the container.
|
|
93
100
|
|
|
@@ -99,7 +106,7 @@ class DataDistributionVisualization(BaseVisualizationTemplate):
|
|
|
99
106
|
"""
|
|
100
107
|
return self.retrieve_labels_from_images(container)
|
|
101
108
|
|
|
102
|
-
def generate_visualizations(self, container: DataContainer, data: tuple[list[str
|
|
109
|
+
def generate_visualizations(self, container: DataContainer, data: tuple[list[str], list[int | float]]) -> None:
|
|
103
110
|
"""
|
|
104
111
|
Generates all requested visualizations.
|
|
105
112
|
|
|
@@ -11,7 +11,8 @@ from sinapsis_data_visualization.helpers.tags import Tags
|
|
|
11
11
|
from sinapsis_data_visualization.templates.bbox_drawer import BBoxDrawer
|
|
12
12
|
|
|
13
13
|
KeyPointsDrawerUIProperties = BBoxDrawer.UIProperties
|
|
14
|
-
KeyPointsDrawerUIProperties.tags
|
|
14
|
+
if KeyPointsDrawerUIProperties.tags is not None:
|
|
15
|
+
KeyPointsDrawerUIProperties.tags.extend([Tags.KEYPOINTS])
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class KeyPointsDrawer(BBoxDrawer):
|
|
@@ -28,7 +28,8 @@ from sinapsis_data_visualization.templates.base_annotation_drawer import (
|
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
LabelDrawerUIProperties = BaseAnnotationDrawer.UIProperties
|
|
31
|
-
LabelDrawerUIProperties.tags
|
|
31
|
+
if LabelDrawerUIProperties.tags is not None:
|
|
32
|
+
LabelDrawerUIProperties.tags.extend([Tags.LABELS, Tags.CLASSIFICATION])
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
class LabelDrawer(BaseAnnotationDrawer):
|
|
@@ -97,6 +98,8 @@ class LabelDrawer(BaseAnnotationDrawer):
|
|
|
97
98
|
if isinstance(self.text_style, dict):
|
|
98
99
|
self.text_style = TextStyle(**self.text_style)
|
|
99
100
|
|
|
101
|
+
attributes: AttributesBaseModel
|
|
102
|
+
|
|
100
103
|
def set_drawing_strategy(self) -> None:
|
|
101
104
|
"""Appends the annotation to be drawn (i.e., label)
|
|
102
105
|
to the list of tasks in the execute method"""
|
|
@@ -270,7 +273,7 @@ class LabelDrawer(BaseAnnotationDrawer):
|
|
|
270
273
|
image = image_info[0]
|
|
271
274
|
font_scale, font_thickness = get_dynamic_text_properties(image)
|
|
272
275
|
self.attributes.text_style.font_scale = font_scale
|
|
273
|
-
self.attributes.text_style.thickness = font_thickness
|
|
276
|
+
self.attributes.text_style.thickness = int(font_thickness)
|
|
274
277
|
|
|
275
278
|
image = self.add_label(image_info=image_info, class_label=class_label, spacing=int(5 * font_scale))
|
|
276
279
|
|
|
@@ -12,7 +12,8 @@ from sinapsis_data_visualization.helpers.tags import Tags
|
|
|
12
12
|
from sinapsis_data_visualization.templates.bbox_drawer import BBoxDrawer
|
|
13
13
|
|
|
14
14
|
OrientedBBoxDrawerUIProperties = BBoxDrawer.UIProperties
|
|
15
|
-
OrientedBBoxDrawerUIProperties.tags
|
|
15
|
+
if OrientedBBoxDrawerUIProperties.tags is not None:
|
|
16
|
+
OrientedBBoxDrawerUIProperties.tags.extend([Tags.ORIENTED_BBOX])
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
class OrientedBBoxDrawer(BBoxDrawer):
|
|
@@ -7,7 +7,8 @@ from sinapsis_data_visualization.helpers.tags import Tags
|
|
|
7
7
|
from sinapsis_data_visualization.templates.bbox_drawer import BBoxDrawer
|
|
8
8
|
|
|
9
9
|
SegmentationMaskDrawerUIProperties = BBoxDrawer.UIProperties
|
|
10
|
-
SegmentationMaskDrawerUIProperties.tags
|
|
10
|
+
if SegmentationMaskDrawerUIProperties.tags is not None:
|
|
11
|
+
SegmentationMaskDrawerUIProperties.tags.extend([Tags.SEGMENTATION, Tags.MASKS])
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class SegmentationMaskDrawer(BBoxDrawer):
|
|
@@ -59,6 +60,8 @@ class SegmentationMaskDrawer(BBoxDrawer):
|
|
|
59
60
|
|
|
60
61
|
alpha: float = 0.5
|
|
61
62
|
|
|
63
|
+
attributes: AttributesBaseModel
|
|
64
|
+
|
|
62
65
|
def set_drawing_strategy(self) -> None:
|
|
63
66
|
"""
|
|
64
67
|
Appends the method to draw the segmentation masks on the image, to
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
from typing import Sequence
|
|
3
3
|
|
|
4
|
-
import matplotlib
|
|
5
4
|
import matplotlib.pyplot as plt
|
|
6
5
|
import numpy as np
|
|
7
6
|
import pandas as pd
|
|
7
|
+
from matplotlib.figure import Figure
|
|
8
8
|
from pydantic import Field
|
|
9
9
|
from sinapsis_core.data_containers.data_packet import DataContainer
|
|
10
10
|
from sinapsis_data_visualization.helpers.tags import Tags
|
|
@@ -40,7 +40,8 @@ class TabularDataVisualizationAttributes(BasePlotAttributes):
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
TabularDataVisualizationUIProperties = BaseVisualizationTemplate.UIProperties
|
|
43
|
-
TabularDataVisualizationUIProperties.tags
|
|
43
|
+
if TabularDataVisualizationUIProperties.tags is not None:
|
|
44
|
+
TabularDataVisualizationUIProperties.tags.extend([Tags.CHARTS, Tags.PLOTS, Tags.CORRELATION, Tags.PANDAS])
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
class TabularDataVisualization(BaseVisualizationTemplate):
|
|
@@ -53,6 +54,8 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
53
54
|
|
|
54
55
|
AttributesBaseModel = TabularDataVisualizationAttributes
|
|
55
56
|
|
|
57
|
+
attributes: TabularDataVisualizationAttributes
|
|
58
|
+
|
|
56
59
|
def get_data_for_visualization(self, container: DataContainer) -> pd.DataFrame | None:
|
|
57
60
|
"""
|
|
58
61
|
Extracts and converts tabular data from the container.
|
|
@@ -67,20 +70,21 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
67
70
|
self.logger.warning("No generic_field_key specified")
|
|
68
71
|
return None
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
dataframes = getattr(container, "data_frames", None)
|
|
71
74
|
|
|
72
|
-
if
|
|
75
|
+
if dataframes is None:
|
|
73
76
|
self.logger.warning(f"No data found with key '{self.attributes.generic_field_key}'")
|
|
74
77
|
return None
|
|
78
|
+
dataframe = dataframes[0].content
|
|
75
79
|
|
|
76
|
-
if isinstance(
|
|
77
|
-
|
|
80
|
+
if isinstance(dataframe, pd.DataFrame):
|
|
81
|
+
data = dataframe
|
|
78
82
|
else:
|
|
79
|
-
self.logger.warning(f"Data format not recognized: {type(
|
|
83
|
+
self.logger.warning(f"Data format not recognized: {type(dataframe)}")
|
|
80
84
|
return None
|
|
81
85
|
|
|
82
|
-
self.logger.info(f"Available columns: {
|
|
83
|
-
return
|
|
86
|
+
self.logger.info(f"Available columns: {data.columns}")
|
|
87
|
+
return data
|
|
84
88
|
|
|
85
89
|
def identify_feature_types(self, df: pd.DataFrame) -> tuple[list[str], list[str]]:
|
|
86
90
|
"""
|
|
@@ -114,7 +118,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
114
118
|
|
|
115
119
|
return numeric_cols, categorical_cols
|
|
116
120
|
|
|
117
|
-
def prepare_histogram_data(self, df: pd.DataFrame, feature: str) -> tuple[list[
|
|
121
|
+
def prepare_histogram_data(self, df: pd.DataFrame, feature: str) -> tuple[list[str], list[float]]:
|
|
118
122
|
"""
|
|
119
123
|
Prepares data for a histogram plot.
|
|
120
124
|
|
|
@@ -131,9 +135,9 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
131
135
|
bins = np.linspace(min_val, max_val, 20)
|
|
132
136
|
counts, edges = np.histogram(df[feature].to_numpy(), bins=bins)
|
|
133
137
|
|
|
134
|
-
labels = [(edges[i] + edges[i + 1]) / 2 for i in range(len(edges) - 1)]
|
|
138
|
+
labels = [str((edges[i] + edges[i + 1]) / 2) for i in range(len(edges) - 1)]
|
|
135
139
|
|
|
136
|
-
return labels, counts
|
|
140
|
+
return labels, counts.tolist()
|
|
137
141
|
|
|
138
142
|
def prepare_boxplot_data(self, df: pd.DataFrame, feature: str) -> tuple[list[str], list[np.ndarray]]:
|
|
139
143
|
"""
|
|
@@ -187,7 +191,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
187
191
|
|
|
188
192
|
return features_to_correlate, corr_matrix
|
|
189
193
|
|
|
190
|
-
def prepare_categorical_data(self, df: pd.DataFrame, feature: str) -> tuple[list[str], list[int]]:
|
|
194
|
+
def prepare_categorical_data(self, df: pd.DataFrame, feature: str) -> tuple[list[str], list[int | float]]:
|
|
191
195
|
"""
|
|
192
196
|
Prepares data for a categorical distribution plot.
|
|
193
197
|
|
|
@@ -203,7 +207,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
203
207
|
counts = value_counts.values.tolist()
|
|
204
208
|
return labels, counts
|
|
205
209
|
|
|
206
|
-
def prepare_target_pie_data(self, df: pd.DataFrame) -> tuple[list[str], list[int]]:
|
|
210
|
+
def prepare_target_pie_data(self, df: pd.DataFrame) -> tuple[list[str], list[int | float]]:
|
|
207
211
|
"""
|
|
208
212
|
Prepares data for a target distribution pie chart.
|
|
209
213
|
|
|
@@ -224,7 +228,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
224
228
|
|
|
225
229
|
def create_boxplot(
|
|
226
230
|
self, labels: Sequence[str], data_points: Sequence[np.ndarray], title: str | None = None
|
|
227
|
-
) ->
|
|
231
|
+
) -> Figure:
|
|
228
232
|
"""
|
|
229
233
|
Creates a boxplot figure.
|
|
230
234
|
|
|
@@ -237,21 +241,21 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
237
241
|
matplotlib.figure.Figure: The created boxplot.
|
|
238
242
|
"""
|
|
239
243
|
fig = self.create_figure(text=title)
|
|
240
|
-
plt.boxplot(data_points, labels=labels)
|
|
244
|
+
plt.boxplot(data_points, labels=labels) # ty: ignore[unknown-argument]
|
|
241
245
|
plt.ylabel("Value")
|
|
242
246
|
plt.xticks(rotation=45, ha="right")
|
|
243
247
|
plt.tight_layout()
|
|
244
248
|
return fig
|
|
245
249
|
|
|
246
|
-
def generate_visualizations(self, container: DataContainer,
|
|
250
|
+
def generate_visualizations(self, container: DataContainer, data: pd.DataFrame) -> None:
|
|
247
251
|
"""
|
|
248
252
|
Generates all requested visualizations for the tabular data.
|
|
249
253
|
|
|
250
254
|
Args:
|
|
251
255
|
container (DataContainer): Data container.
|
|
252
|
-
|
|
256
|
+
data (pd.DataFrame): The tabular data.
|
|
253
257
|
"""
|
|
254
|
-
numeric_cols, categorical_cols = self.identify_feature_types(
|
|
258
|
+
numeric_cols, categorical_cols = self.identify_feature_types(data)
|
|
255
259
|
self.logger.info(f"Found {len(numeric_cols)} numeric features and {len(categorical_cols)} categorical features")
|
|
256
260
|
|
|
257
261
|
if not numeric_cols and not categorical_cols:
|
|
@@ -260,7 +264,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
260
264
|
|
|
261
265
|
if self.attributes.histogram:
|
|
262
266
|
for feature in numeric_cols:
|
|
263
|
-
labels, counts = self.prepare_histogram_data(
|
|
267
|
+
labels, counts = self.prepare_histogram_data(data, feature)
|
|
264
268
|
if len(labels) > 0 and len(counts) > 0:
|
|
265
269
|
self.plot_and_save(
|
|
266
270
|
container=container,
|
|
@@ -272,14 +276,14 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
272
276
|
|
|
273
277
|
if self.attributes.box_plot:
|
|
274
278
|
for feature in numeric_cols:
|
|
275
|
-
box_labels, data_points = self.prepare_boxplot_data(
|
|
279
|
+
box_labels, data_points = self.prepare_boxplot_data(data, feature)
|
|
276
280
|
if len(box_labels) > 0 and len(data_points) > 0:
|
|
277
281
|
fig = self.create_boxplot(labels=box_labels, data_points=data_points, title=f"{feature}")
|
|
278
|
-
self.save_figure(fig, f"boxplot_{feature}", container.container_id)
|
|
282
|
+
self.save_figure(fig, f"boxplot_{feature}", str(container.container_id))
|
|
279
283
|
self.add_figure_to_container(container, fig, f"boxplot_{feature}")
|
|
280
284
|
|
|
281
285
|
if self.attributes.correlation and len(numeric_cols) > 1:
|
|
282
|
-
corr_labels, corr_matrix = self.prepare_correlation_data(
|
|
286
|
+
corr_labels, corr_matrix = self.prepare_correlation_data(data, numeric_cols)
|
|
283
287
|
if len(corr_labels) > 0 and corr_matrix.size > 0:
|
|
284
288
|
self.plot_and_save(
|
|
285
289
|
container=container,
|
|
@@ -291,7 +295,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
291
295
|
|
|
292
296
|
if self.attributes.categorical_dist and categorical_cols:
|
|
293
297
|
for feature in categorical_cols:
|
|
294
|
-
cat_labels, cat_counts = self.prepare_categorical_data(
|
|
298
|
+
cat_labels, cat_counts = self.prepare_categorical_data(data, feature)
|
|
295
299
|
if len(cat_labels) > 0 and len(cat_counts) > 0:
|
|
296
300
|
self.plot_and_save(
|
|
297
301
|
container=container,
|
|
@@ -303,7 +307,7 @@ class TabularDataVisualization(BaseVisualizationTemplate):
|
|
|
303
307
|
)
|
|
304
308
|
|
|
305
309
|
if self.attributes.pie_chart:
|
|
306
|
-
pie_labels, pie_counts = self.prepare_target_pie_data(
|
|
310
|
+
pie_labels, pie_counts = self.prepare_target_pie_data(data)
|
|
307
311
|
if len(pie_labels) > 0 and len(pie_counts) > 0:
|
|
308
312
|
self.plot_and_save(
|
|
309
313
|
container=container,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-data-visualization
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
4
4
|
Summary: Templates to perform visualization of data distributions and image annotations.
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -19,6 +19,7 @@ Provides-Extra: all
|
|
|
19
19
|
Requires-Dist: sinapsis-data-visualization[visualization-matplotlib]; extra == "all"
|
|
20
20
|
Dynamic: license-file
|
|
21
21
|
|
|
22
|
+
[](https://github.com/Sinapsis-AI/sinapsis-data-tools/blob/main/README.es.md)
|
|
22
23
|
<h1 align="center">
|
|
23
24
|
<br>
|
|
24
25
|
<a href="https://sinapsis.tech/">
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|