main
John Lauer ECAS vs MLCC: a study of moving the buck to polymer capacitors, with its section card 531f515
#!/usr/bin/env python3
"""Pull Murata SimSurfing characteristic curves (DC bias, |Z|, ESR vs frequency) for each part.

Run: python3 murata_curves.py -> ../research/murata/<pn>.json
The same endpoint the SimSurfing page uses (ds.murata.com/simserve/characteristics); one GET per
part and curve, cached on disk so a re-run costs nothing.
"""
import json, os, subprocess, sys, urllib.parse

OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "research", "murata")
os.makedirs(OUT, exist_ok=True)
PARTS = {
    # MLCCs (Murata equivalents where the board uses another brand: same size, voltage, dielectric)
    "GRM21BR61A226ME44": "22uF 10V X5R 0805 (Murata twin of the board's Samsung CL21A226MPQNNNE, C6-C8)",
    "GRM31CR71E106KA12": "10uF 25V X7R 1206 (Murata twin of the board's Yageo CC1206KKX7R8BB106, C2-C3)",
    "GRM21BR61A476ME15": "47uF 10V X5R 0805",
    "GRM31CR61A476ME15": "47uF 10V X5R 1206",
    "GRM21BR61E226ME44": "22uF 25V X5R 0805",
    "GRM188R61E106MA73": "10uF 25V X5R 0603",
    "GRM31CR61E226ME15": "22uF 25V X5R 1206",
    # polymer aluminium (ECAS)
    "ECASD41E336M040KA0": "33uF 25V 40mOhm ECAS D-case 2.0 mm",
    "ECASD61A157M010KA0": "150uF 10V 10mOhm ECAS D-case 3.1 mm",
    "ECASD61C107M012KA0": "100uF 16V 12mOhm ECAS D-case",
    "ECASD40J107M015K00": "100uF 6.3V 15mOhm ECAS D-case",
}
CHARAS = ["c_dcbias_capchange", "z", "r"]


def fetch(pn, chara):
    req = [{"partnumber": pn, "chara_type": chara, "parameter": {},
            "WorkInfo": {"color": "#ea002a", "supply_status": "B", "graph_set_y_name": ""}}]
    q = urllib.parse.urlencode({"callback": "nothing", "ReqType": "Characteristics", "ReqChara": json.dumps(req),
                                "CallBack": "mycallback", "WorkInfo": "svgGraph1"})
    r = subprocess.run(["curl", "-s", "-m", "40", "-A", "Mozilla/5.0", "-e", "https://ds.murata.com/simsurfing/mlcc.html",
                        "https://ds.murata.com/simserve/characteristics?" + q], capture_output=True, text=True)
    d = json.loads(r.stdout)["JsonCharaData"][0]["charadata"][0]
    return {"caption": d.get("caption"), "conditions": d.get("caption2"), "error": d.get("error"),
            "x": [p[0][0] for p in d.get("data", [])], "y": [p[1][0] for p in d.get("data", [])],
            "x_unit": d.get("x_unit"), "y_unit": d.get("y_unit")}


for pn, note in PARTS.items():
    path = os.path.join(OUT, pn + ".json")
    if os.path.exists(path):
        continue
    rec = {"partnumber": pn, "note": note, "source": "Murata SimSurfing (ds.murata.com/simserve), fetched 2026-10-11"}
    for c in CHARAS:
        try:
            rec[c] = fetch(pn, c)
        except Exception as e:
            rec[c] = {"error": str(e)}
    json.dump(rec, open(path, "w"), indent=1)
    print(pn, {c: (len(rec[c].get("x", [])), rec[c].get("error")) for c in CHARAS}, file=sys.stderr)