yxma commited on
Commit
fef9da1
·
verified ·
1 Parent(s): 5b9d9bf

scripts: add make_pie_charts.py

Browse files
Files changed (1) hide show
  1. scripts/make_pie_charts.py +129 -0
scripts/make_pie_charts.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate a 4-panel pie-chart summary for the dataset card.
3
+
4
+ Panels:
5
+ (A) Image resolution — 320×240 vs 640×480
6
+ (B) Gel variant — markered vs markerless
7
+ (C) Source contribution — 8 subsets (legend instead of inline labels
8
+ to avoid overlap)
9
+ (D) Gel variant × source — donut: outer ring = gel variant,
10
+ inner ring = subset within variant
11
+ """
12
+ import glob, os
13
+ import matplotlib
14
+ matplotlib.use("Agg")
15
+ import matplotlib.pyplot as plt
16
+ import numpy as np
17
+ import pyarrow.parquet as pq
18
+
19
+ BASE = "/media/yxma/Disk1/yuxiang/mini_data_parquet"
20
+ OUT = f"{BASE}/assets"
21
+ SUBSETS = ["fota_unlabeled", "real_tactile_mnist", "gelslam", "feelanyforce",
22
+ "threedcal", "fota_labeled", "feats", "tactile_tracking"]
23
+ # Reordered descending by typical size so colors line up sensibly.
24
+
25
+ def aggregate():
26
+ agg = {}
27
+ for sub in SUBSETS:
28
+ paths = sorted(glob.glob(f"{BASE}/{sub}/*.parquet"))
29
+ m = u = 0
30
+ res = {}
31
+ for p in paths:
32
+ t = pq.read_table(p, columns=["markered", "width", "height"])
33
+ for mki, wi, hi in zip(t.column("markered").to_pylist(),
34
+ t.column("width").to_pylist(),
35
+ t.column("height").to_pylist()):
36
+ if mki: m += 1
37
+ else: u += 1
38
+ res[(wi, hi)] = res.get((wi, hi), 0) + 1
39
+ agg[sub] = {"markered": m, "markerless": u, "res": res, "total": m + u}
40
+ return agg
41
+
42
+
43
+ def main():
44
+ agg = aggregate()
45
+ fig, axes = plt.subplots(2, 2, figsize=(13, 12))
46
+
47
+ # (A) by resolution
48
+ tot_res = {}
49
+ for sub in SUBSETS:
50
+ for k, v in agg[sub]["res"].items():
51
+ tot_res[k] = tot_res.get(k, 0) + v
52
+ ax = axes[0, 0]
53
+ items = sorted(tot_res.items(), key=lambda kv: -kv[1])
54
+ labels = [f"{w}×{h}\n{n:,} ({100*n/sum(tot_res.values()):.1f}%)"
55
+ for (w, h), n in items]
56
+ vals = [n for (_, _), n in items]
57
+ ax.pie(vals, labels=labels, colors=["#4c95d6", "#d6794c"],
58
+ startangle=90, wedgeprops={"edgecolor": "white", "linewidth": 2},
59
+ textprops={"fontsize": 12})
60
+ ax.set_title("Image resolution\n(GelSight Mini native modes)",
61
+ fontsize=14, pad=14)
62
+
63
+ # (B) by gel variant
64
+ m = sum(agg[s]["markered"] for s in SUBSETS)
65
+ u = sum(agg[s]["markerless"] for s in SUBSETS)
66
+ ax = axes[0, 1]
67
+ ax.pie([u, m],
68
+ labels=[f"markerless\n{u:,} ({100*u/(m+u):.1f}%)",
69
+ f"markered\n{m:,} ({100*m/(m+u):.1f}%)"],
70
+ colors=["#4c95d6", "#d6794c"], startangle=90,
71
+ wedgeprops={"edgecolor": "white", "linewidth": 2},
72
+ textprops={"fontsize": 12})
73
+ ax.set_title("Gel variant", fontsize=14, pad=14)
74
+
75
+ # (C) by source — legend instead of inline labels
76
+ ax = axes[1, 0]
77
+ src_vals = [agg[s]["total"] for s in SUBSETS]
78
+ src_total = sum(src_vals)
79
+ cmap = plt.cm.tab10(np.linspace(0, 1, max(len(SUBSETS), 10)))
80
+ wedges, _ = ax.pie(src_vals, colors=cmap, startangle=90,
81
+ wedgeprops={"edgecolor": "white", "linewidth": 2})
82
+ legend_labels = [f"{s:<19s} {n:>7,d} ({100*n/src_total:5.2f}%)"
83
+ for s, n in zip(SUBSETS, src_vals)]
84
+ ax.legend(wedges, legend_labels, loc="center left",
85
+ bbox_to_anchor=(1.0, 0.5), fontsize=10,
86
+ prop={"family": "monospace", "size": 10},
87
+ frameon=False, title="subset (frames)",
88
+ title_fontsize=11)
89
+ ax.set_title("Source contribution", fontsize=14, pad=14)
90
+
91
+ # (D) gel variant × source donut
92
+ ax = axes[1, 1]
93
+ outer_sizes = [u, m]
94
+ outer_colors = ["#4c95d6", "#d6794c"]
95
+ ax.pie(outer_sizes,
96
+ labels=[f"markerless\n{u:,}", f"markered\n{m:,}"],
97
+ colors=outer_colors, radius=1.0,
98
+ wedgeprops={"edgecolor": "white", "linewidth": 2, "width": 0.35},
99
+ startangle=90, textprops={"fontsize": 12, "fontweight": "bold"},
100
+ labeldistance=1.1)
101
+ inner_sizes, inner_colors, inner_lbls = [], [], []
102
+ blue_pal = plt.cm.Blues(np.linspace(0.4, 0.9, len(SUBSETS)))
103
+ orng_pal = plt.cm.Oranges(np.linspace(0.4, 0.9, len(SUBSETS)))
104
+ for i, s in enumerate(SUBSETS):
105
+ if agg[s]["markerless"] > 0:
106
+ inner_sizes.append(agg[s]["markerless"])
107
+ inner_colors.append(blue_pal[i])
108
+ inner_lbls.append(s if agg[s]["markerless"] > u * 0.06 else "")
109
+ for i, s in enumerate(SUBSETS):
110
+ if agg[s]["markered"] > 0:
111
+ inner_sizes.append(agg[s]["markered"])
112
+ inner_colors.append(orng_pal[i])
113
+ inner_lbls.append(s if agg[s]["markered"] > m * 0.06 else "")
114
+ ax.pie(inner_sizes, radius=0.62, colors=inner_colors,
115
+ wedgeprops={"edgecolor": "white", "linewidth": 1, "width": 0.30},
116
+ startangle=90, labels=inner_lbls, labeldistance=0.78,
117
+ textprops={"fontsize": 8})
118
+ ax.set_title("Gel variant × source (donut)", fontsize=14, pad=14)
119
+
120
+ fig.suptitle(f"gelsight-mini-pretrain · summary pie charts "
121
+ f"(total {m+u:,} frames)", fontsize=16, y=0.995)
122
+ plt.tight_layout(rect=[0, 0, 1, 0.97])
123
+ out = f"{OUT}/summary_pies.png"
124
+ plt.savefig(out, dpi=140, bbox_inches="tight")
125
+ print(f"saved {out} total={m+u:,} markered={m:,} markerless={u:,}")
126
+
127
+
128
+ if __name__ == "__main__":
129
+ main()