Skip to main content

The statistical process control library for Python: control charts, capability analysis, and measurement systems analysis, validated against published reference values.

Project description

shewhart

Statistical process control for Python.

Control charts with the standard run rules, process capability analysis, and measurement systems analysis. Results are computed from the published formulas and checked against reference values in the test suite.

Named after Walter A. Shewhart.

Motivation

R has had a maintained SPC package (qcc) since 2004. Python does not: the existing packages are unmaintained, cover only fragments of the toolkit, and none of them validate their output against reference data. This library is an attempt to fix that, with a few specific goals:

  • correct constants and estimators, validated against published values
  • a clean separation between estimating control limits (Phase I) and monitoring new data against frozen limits (Phase II)
  • rule violations as structured data, usable in pipelines, not only in plots
  • an API that works headless, so a weekly control chart review can run as a cron job

Status

Under active development, pre 0.1. Implemented and tested so far:

  • control charts: I-MR, Xbar-R, Xbar-S, p, np, c, u (stair-step limits for varying subgroup sizes), EWMA (exact and asymptotic limits), run chart with the four runs tests, Pareto analysis
  • time-window subgrouping on DatetimeIndex data (subgroup="1H")
  • process capability: Cp, Cpk, Pp, Ppk, Cpm with confidence intervals (chi-square for Cp/Pp, Bissell approximation for Cpk/Ppk), within vs overall sigma, expected and observed PPM, stability gate, normality check
  • Nelson rules 1 to 8 and Western Electric rules 1 to 4, returned as structured signal events
  • chart constants (d2, d3, c4, A2, A3, D3, D4, B3, B4), computed from their defining integrals rather than copied from tables
  • baseline freezing and reuse (JSON), self-contained HTML reports
  • a reference-case validation suite (tests/validation_cases.json), anchored externally: NIST StRD certified values (Michelso, NumAcc1) and the NIST/SEMATECH e-Handbook EWMA worked example are reproduced in CI

The version on PyPI (0.0.1) predates most of this. Until 0.1 is released, install from source:

pip install git+https://github.com/bertanucar/shewhart

Usage

import shewhart as sw

r = sw.imr(df, value="torque", rules="nelson")
r.ok           # False if any rule fired
r.summary()    # plain text verdict
r.table        # per-point DataFrame with signal flags
r.plot()

Subgrouped data:

r = sw.xbar_r(df, value="torque", subgroup="batch")

Fit limits once, then monitor new data against them:

sw.imr(df_baseline, value="torque").baseline.save("line3_baseline.json")

# later, e.g. in a scheduled job:
r = sw.imr(df_new, value="torque", limits="line3_baseline.json")
sys.exit(0 if r.ok else 1)

Capability analysis, with the confidence intervals that the usual hand-rolled Cpk calculation cannot give you:

r = sw.capability(df, value="dia", lsl=9.95, usl=10.05)
r.stats["cpk"], r.stats["cpk_lci"], r.stats["cpk_uci"]

Several analyses in one self-contained HTML file, e.g. as a weekly job:

sw.report([
    sw.imr(df, value="torque", limits="line3_baseline.json"),
    sw.p_chart(df2, defectives="rejects", size="inspected"),
    sw.capability(df, value="torque", lsl=9.5, usl=11.0),
], "weekly_report.html", title="Line 3 weekly")

Every analysis returns the same Result object: named statistics, a tidy per-point table, a tuple of structured rule violations, and provenance metadata (library version, input hash, timestamp).

Roadmap

Version Scope
0.1 documentation site, PyPI release
0.1.x CUSUM, Laney p'/u', non-normal capability, tolerance intervals
0.2 measurement systems analysis: ANOVA gauge R&R (crossed and nested), Type 1 studies, attribute agreement
0.3 process screening across many characteristics, drift monitoring with control chart semantics

Out of scope: DOE (see pyDOE3), reliability engineering (see reliability), general statistics (see statsmodels), GUIs.

License

MIT. Written and maintained by Bertan Ucar, PhD researcher at Tsinghua University.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shewhart-0.1.0.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shewhart-0.1.0-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file shewhart-0.1.0.tar.gz.

File metadata

  • Download URL: shewhart-0.1.0.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shewhart-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1fab5c15052b39d27169f516a5830b49151c9e79d1732c09cc08f877fa6a0d1
MD5 78ccd068b40e709edd127031ec0f3c93
BLAKE2b-256 ed4607971779141fed678820c2b1ffb213fe6d5e6f781d5226fe1fbc3614a2b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for shewhart-0.1.0.tar.gz:

Publisher: release.yml on bertanucar/shewhart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shewhart-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shewhart-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shewhart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2d616eb3bd8eeb2977188e91d8191416a4f5e9372eed4eddc82e5d0d3b2a505
MD5 37e1b770a26770484d6ddcb93e65cf50
BLAKE2b-256 70bb77a796edb9563ee2682be65e65ac6060e8bc5f6cfd8a9723302ed6f4e773

See more details on using hashes here.

Provenance

The following attestation bundles were made for shewhart-0.1.0-py3-none-any.whl:

Publisher: release.yml on bertanucar/shewhart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page