Datasets:
Upload scripts/verify_app.py with huggingface_hub
Browse files- scripts/verify_app.py +41 -0
scripts/verify_app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Check the app's figure without a browser: trace structure, palette, axes."""
|
| 2 |
+
|
| 3 |
+
import umap_app as app
|
| 4 |
+
|
| 5 |
+
PALETTE = set(app.THEMES["light"]["series"] + app.THEMES["dark"]["series"]
|
| 6 |
+
+ [app.THEMES["light"]["other"], app.THEMES["dark"]["other"],
|
| 7 |
+
app.THEMES["light"]["grid"], app.THEMES["dark"]["grid"]])
|
| 8 |
+
|
| 9 |
+
df = app.load_nodes()
|
| 10 |
+
print(f"nodes {len(df):,} · coords x[{df.x.min():.1f},{df.x.max():.1f}] "
|
| 11 |
+
f"y[{df.y.min():.1f},{df.y.max():.1f}]")
|
| 12 |
+
|
| 13 |
+
CASES = {
|
| 14 |
+
"top 3, light": dict(mode="light"),
|
| 15 |
+
"top 3, dark": dict(mode="dark"),
|
| 16 |
+
"highlight Homo sapiens": dict(highlight="Homo sapiens"),
|
| 17 |
+
"restrict to 2 species": dict(shown=("Bos taurus", "Mus musculus")),
|
| 18 |
+
"colour by tissue1": dict(group_by="tissue1"),
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
for name, kwargs in CASES.items():
|
| 22 |
+
fig, visible = app.build_figure(df, **kwargs)
|
| 23 |
+
hues = {t.marker.color for t in fig.data}
|
| 24 |
+
drawn = sum(len(t.x) for t in fig.data)
|
| 25 |
+
coloured = sum(len(t.x) for t in fig.data if t.marker.color
|
| 26 |
+
not in (app.THEMES["light"]["other"], app.THEMES["dark"]["other"],
|
| 27 |
+
app.THEMES["light"]["grid"], app.THEMES["dark"]["grid"]))
|
| 28 |
+
assert hues <= PALETTE, f"{name}: off-palette colour {hues - PALETTE}"
|
| 29 |
+
assert drawn == len(df), f"{name}: {drawn} points drawn, expected {len(df)}"
|
| 30 |
+
assert len([t for t in fig.data if t.showlegend is not False]) <= 4
|
| 31 |
+
assert fig.layout.xaxis.visible is False and fig.layout.yaxis.visible is False
|
| 32 |
+
assert fig.layout.xaxis.scaleanchor == "y", "aspect ratio not locked"
|
| 33 |
+
assert all("customdata" in t.hovertemplate for t in fig.data)
|
| 34 |
+
print(f"\n{name}")
|
| 35 |
+
print(f" traces {len(fig.data)} · all {drawn:,} nodes drawn · "
|
| 36 |
+
f"{coloured:,} in a series hue")
|
| 37 |
+
for t in fig.data:
|
| 38 |
+
print(f" {(t.name or '—'):<34} {len(t.x):>7,} {t.marker.color}")
|
| 39 |
+
|
| 40 |
+
print("\nall figure checks passed: palette clean, every node drawn, "
|
| 41 |
+
"axes hidden, aspect locked, hover wired")
|