File size: 1,820 Bytes
5a9a305 2f49758 5a9a305 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """Shared helpers for scripts/plots/*.py."""
import json
from pathlib import Path
ROOT = Path(__file__).parent.parent.parent
DATA_DIR = ROOT / "data"
OUT_DIR = ROOT / "assets"
# Kept consistent across figures so e.g. batch C is the same color everywhere.
BATCH_COLORS = {
"A": "#1f77b4", # blue
"B": "#ff7f0e", # orange
"C": "#2ca02c", # green
"D": "#d62728", # red
"E": "#9467bd", # purple
"F": "#8c564b", # brown
"G": "#e377c2", # pink
"H": "#bcbd22", # olive
"I": "#17becf", # cyan
"J": "#aec7e8", # light blue
"J_MB": "#08519c", # dark blue (media blasted variant of Batch J)
"K": "#98df8a", # light green
"L": "#ff9896", # light red
}
CONTROL_COLOR = "#7f7f7f" # gray for PLA/PETG
MATERIAL_STYLES = {"SLS": "-", "PLA": "--", "PETG": ":"}
FILAMENT_CONTROLS = {"PLA", "PETG"}
def load_specimen(path: Path) -> dict | None:
with path.open() as f:
row = json.loads(f.readline())
pairs = [
(s, t)
for s, t in zip(row["curves"]["strain"], row["curves"]["stress_pa"])
if s is not None and t is not None
]
if not pairs:
return None
strain, stress_pa = zip(*pairs)
return {
"row": row,
"strain": list(strain),
"stress_mpa": [t / 1e6 for t in stress_pa],
}
def load_standard(standard: str) -> list[dict]:
"""Load every specimen with a non-empty curve for a config."""
paths = sorted((DATA_DIR / standard).glob("*.jsonl"))
return [s for p in paths if (s := load_specimen(p))]
def style_for(row: dict) -> tuple[str, str]:
material = row["material_class"]
batch = row["batch_label"]
color = BATCH_COLORS.get(batch, CONTROL_COLOR) if batch else CONTROL_COLOR
linestyle = MATERIAL_STYLES.get(material, "-")
return color, linestyle
|