labqc 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
labqc-0.4.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Mantas Valantinavičius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
labqc-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: labqc
3
+ Version: 0.4.0
4
+ Summary: Laboratory quality calculations: GUM uncertainty budgets, method validation, proficiency-test scores, Westgard rules and flue-gas emission conversions
5
+ Author: Mantas Valantinavičius
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/mantas123456/lab-quality-toolkit
8
+ Project-URL: Documentation, https://mantas123456.github.io/lab-quality-toolkit/
9
+ Project-URL: Source, https://github.com/mantas123456/lab-quality-toolkit
10
+ Project-URL: Issues, https://github.com/mantas123456/lab-quality-toolkit/issues
11
+ Project-URL: Changelog, https://github.com/mantas123456/lab-quality-toolkit/blob/main/CHANGELOG.md
12
+ Keywords: metrology,uncertainty,GUM,ISO 17025,quality control,Westgard,method validation,proficiency testing,emissions
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.26
29
+ Requires-Dist: pandas>=2.1
30
+ Requires-Dist: scipy>=1.11
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8; extra == "dev"
33
+ Requires-Dist: ruff>=0.5; extra == "dev"
34
+ Requires-Dist: matplotlib>=3.8; extra == "dev"
35
+ Requires-Dist: build>=1.2; extra == "dev"
36
+ Requires-Dist: twine>=6; extra == "dev"
37
+ Provides-Extra: docs
38
+ Requires-Dist: mkdocs<2,>=1.6; extra == "docs"
39
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
40
+ Requires-Dist: mkdocstrings[python]>=0.26; extra == "docs"
41
+ Dynamic: license-file
42
+
43
+ # labqc: laboratory quality calculations in Python
44
+
45
+ [![CI](https://github.com/mantas123456/lab-quality-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/mantas123456/lab-quality-toolkit/actions/workflows/ci.yml)
46
+ [![PyPI](https://img.shields.io/pypi/v/labqc)](https://pypi.org/project/labqc/)
47
+ [![Docs](https://img.shields.io/badge/docs-online-blue)](https://mantas123456.github.io/lab-quality-toolkit/)
48
+
49
+ The calculations an ISO/IEC 17025 laboratory does every week, usually in spreadsheets,
50
+ written as small, tested Python functions:
51
+
52
+ <!-- --8<-- [start:modules] -->
53
+ | Module | What it covers | Reference |
54
+ |---|---|---|
55
+ | `uncertainty` | GUM uncertainty budgets: Type A and B components, sensitivity coefficients (analytic or numerical), correlated inputs, Welch–Satterthwaite degrees of freedom, coverage factor, relative uncertainty; Monte Carlo propagation | JCGM 100:2008 (GUM), JCGM 101:2008 (GUM S1) |
56
+ | `validation` | Calibration linearity (ordinary or weighted) with confidence intervals and lack-of-fit test, LOD/LOQ, precision (RSD), intermediate precision by ANOVA, spike recovery, trueness against a CRM | ICH Q2, Eurachem guide, ERM Application Note 1 |
57
+ | `proficiency` | z, zeta and E<sub>n</sub> scores with interpretation; robust consensus mean (Algorithm A); z-score history across rounds | ISO 13528, ISO/IEC 17043 |
58
+ | `control_charts` | Shewhart limits; Westgard rules 1<sub>2s</sub>, 1<sub>3s</sub>, 2<sub>2s</sub>, R<sub>4s</sub>, 4<sub>1s</sub>, 10<sub>x</sub>, also across two or three control levels; CUSUM and EWMA charts | Westgard multirule QC; Montgomery, *Introduction to Statistical Quality Control* |
59
+ | `emissions` | ppm ↔ mg/m³ at standard conditions, correction to reference O₂ and its uncertainty, wet ↔ dry, user-defined gases | Stack-emission practice, e.g. EN 303-5 at 10 % O₂ |
60
+
61
+ Every function is tested against hand-calculated values or textbook worked examples (58 tests),
62
+ and the examples below run in CI.
63
+ <!-- --8<-- [end:modules] -->
64
+
65
+ <!-- --8<-- [start:examples] -->
66
+ ## Example 1: uncertainty of a moisture determination
67
+
68
+ Oven-dry moisture of a wood-pellet sample, `M = (m2 − m3) / (m2 − m1) × 100`, with balance
69
+ calibration and resolution for each weighing plus repeatability from five test portions.
70
+ Sensitivity coefficients are found numerically from the model function
71
+ ([`examples/moisture_uncertainty.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/moisture_uncertainty.py)).
72
+
73
+ ```text
74
+ component u_i c_i contribution dof share_of_variance
75
+ Repeatability (5 test portions) 0.0191 1 0.0191 4 0.996
76
+ Weighing m3 0.00104 -0.798 0.00083 inf 0.00188
77
+ Weighing m2 0.00104 0.742 0.000772 inf 0.00162
78
+ Weighing m1 0.00104 0.0556 5.79e-05 inf 9.12e-06
79
+
80
+ u_c = 0.01916, v_eff = 4.0, k = 2.77, U (95%) = 0.05306
81
+ Report: M = 6.97 % ± 0.05 % (k = 2.77, 95 %)
82
+ ```
83
+
84
+ Over 99 % of the variance comes from sample repeatability. A better balance would change
85
+ nothing; more test portions would. With only four degrees of freedom the coverage factor is
86
+ 2.77, not 2, which a fixed "k = 2" spreadsheet gets wrong.
87
+
88
+ ## Example 2: Westgard rules on daily QC
89
+
90
+ Twenty baseline days set the limits. A +1.4 mg/kg shift is introduced from day 45
91
+ ([`examples/westgard_iqc.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/westgard_iqc.py)).
92
+
93
+ ![Levey-Jennings chart](https://raw.githubusercontent.com/mantas123456/lab-quality-toolkit/main/examples/westgard_chart.png)
94
+
95
+ ```text
96
+ value z status rules
97
+ 27 47.99 -2.817 warning 1_2s
98
+ 45 52.49 4.385 reject 1_2s, 1_3s
99
+ 47 52.09 3.745 reject 1_2s, 1_3s
100
+ 48 51.50 2.798 reject 1_2s, 2_2s
101
+ 50 53.00 5.206 reject 1_2s, 1_3s, 4_1s
102
+ ```
103
+
104
+ Day 27 is a lone 1<sub>2s</sub> warning that needs no action. The shift is caught on its
105
+ first day, and the 2<sub>2s</sub> and 4<sub>1s</sub> rules confirm the error is systematic
106
+ (calibration), not random.
107
+
108
+ ## Example 3: boiler test emissions at reference oxygen
109
+
110
+ ```text
111
+ Measured O2 12.8 %, correction factor 1.346
112
+ CO 310.0 ppm -> 521.3 mg/m3 at 10 % O2 (104% of example limit)
113
+ NO2 118.0 ppm -> 325.9 mg/m3 at 10 % O2
114
+ C3H8 6.5 ppm -> 17.2 mg/m3 at 10 % O2
115
+ ```
116
+
117
+ At high excess air, a raw reading that looks comfortably low can exceed a limit once it is
118
+ corrected to 10 % O₂ ([`examples/boiler_emissions.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/boiler_emissions.py)).
119
+
120
+ ## Example 4: Monte Carlo and correlated weighings
121
+
122
+ Version 0.2 adds Monte Carlo propagation (GUM Supplement 1) and correlated inputs
123
+ ([`examples/monte_carlo_vs_gum.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/monte_carlo_vs_gum.py)).
124
+
125
+ ```text
126
+ 1. Moisture, M = (m2 - m3) / (m2 - m1) x 100 [%]
127
+ GUM (linear): y = 6.971, u = 0.01916, k = 2.77, 95 % interval [6.918, 7.025]
128
+ Monte Carlo: y = 6.971, u = 0.02704, 95 % interval [6.917, 7.024]
129
+
130
+ 2. Recovery-corrected result, C = C_meas / R [mg/kg]
131
+ GUM (linear): y = 20, u = 3.371, k = 1.96, 95 % interval [13.39, 26.61]
132
+ Monte Carlo: y = 20.61, u = 3.843, 95 % interval [14.15, 28.12]
133
+
134
+ 3. Weighings only (no repeatability), r = 0.92 between weighings
135
+ treated as independent: u = 0.00114 %
136
+ with shared calibration: u = 0.00031 % (-72%)
137
+ ```
138
+
139
+ For the nearly linear moisture model the two 95 % intervals agree. Monte Carlo's u is larger
140
+ only because a 4-dof Type A input is sampled from a t-distribution; the GUM method puts the
141
+ same widening into k = 2.77. Dividing by an uncertain recovery (R = 0.60 ± 0.10) is
142
+ non-linear: the real distribution is skewed upwards, and the first-order interval is too low
143
+ at both ends. When the three weighings share one balance calibration, most of the offset
144
+ cancels, and the balance contribution falls by 72 %.
145
+
146
+ ```python
147
+ from labqc.uncertainty import Component, monte_carlo, propagate
148
+
149
+ inputs = {"a": Component("a", 0.1), "b": Component("b", 0.1)}
150
+ y, r = propagate(lambda a, b: a - b, {"a": 5.0, "b": 2.0}, inputs, correlation={("a", "b"): 0.8})
151
+ print(r.summary(relative=True)) # u_c, k, U and u_c/|y|, U/|y|
152
+ print(monte_carlo(lambda a, b: a / b, {"a": 5.0, "b": 2.0}, inputs, seed=1))
153
+ ```
154
+
155
+ ## New in 0.3: lab methods
156
+
157
+ ```python
158
+ import pandas as pd
159
+ from labqc.validation import intermediate_precision, linearity, trueness
160
+ from labqc.emissions import corrected_uncertainty
161
+
162
+ # weighted calibration with duplicate standards: lack-of-fit test included
163
+ cal = linearity(
164
+ [1, 1, 2, 2, 5, 5, 10, 10], [0.11, 0.10, 0.21, 0.19, 0.52, 0.49, 1.08, 0.97], weights="1/x"
165
+ )
166
+ print(cal.lack_of_fit.p_value) # 0.90: a straight line is adequate
167
+
168
+ # three days x three replicates: repeatability 0.100, intermediate precision 0.224
169
+ days = pd.DataFrame(
170
+ {
171
+ "day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
172
+ "value": [10.1, 10.3, 10.2, 10.6, 10.4, 10.5, 10.0, 10.2, 10.1],
173
+ }
174
+ )
175
+ ip = intermediate_precision(days, "value", "day")
176
+
177
+ # five results on a CRM certified at 50 with u = 0.2
178
+ print(trueness([50.4, 50.7, 49.1, 49.0, 51.1], crm_value=50, crm_u=0.2).passed) # True
179
+
180
+ # CO from Example 3 with u(C) = 8 mg/m3 and u(O2) = 0.2 %: 521 ± 34 mg/m3 (k = 2)
181
+ c_ref, r = corrected_uncertainty(387.4, 8, o2_measured=12.8, u_o2=0.2, k=2)
182
+ ```
183
+
184
+ `pt_history()` reviews a lab's z-scores across PT rounds, and `westgard_levels()`, `cusum()`
185
+ and `ewma()` cover two- and three-level QC and small shifts that Westgard rules miss.
186
+ <!-- --8<-- [end:examples] -->
187
+
188
+ ## Use it
189
+
190
+ ```bash
191
+ pip install labqc
192
+ ```
193
+
194
+ Full documentation, with the API reference for every module:
195
+ [mantas123456.github.io/lab-quality-toolkit](https://mantas123456.github.io/lab-quality-toolkit/).
196
+
197
+ ```python
198
+ from labqc.uncertainty import Component, combine, type_a
199
+ from labqc.proficiency import z_score, classify
200
+
201
+ budget = [
202
+ type_a([10.02, 10.05, 9.98, 10.01, 10.03]),
203
+ Component("Reference standard", 0.010, "normal", k=2),
204
+ Component("Temperature effect", 0.004, "rectangular"),
205
+ ]
206
+ print(combine(budget)) # u_c, v_eff, k, U
207
+
208
+ z = z_score(10.75, assigned=10.0, sigma_pt=0.3)
209
+ print(round(z, 2), classify(z)) # 2.5 questionable
210
+ ```
211
+
212
+ ## Develop
213
+
214
+ ```bash
215
+ pip install -e ".[dev]"
216
+ pytest
217
+ ruff check .
218
+
219
+ pip install -e ".[docs]"
220
+ mkdocs serve # documentation at http://127.0.0.1:8000
221
+ ```
222
+
223
+ Releases: push a tag `v*` (for example `v0.4.0`) that matches the version in
224
+ `pyproject.toml`; GitHub Actions builds the package and publishes it to PyPI.
225
+
226
+ ## Scope and limits
227
+
228
+ - `propagate()` uses first-order sensitivity coefficients. For strongly non-linear models,
229
+ use `monte_carlo()` (GUM Supplement 1) and compare.
230
+ - Monte Carlo handles correlation only between normal inputs with infinite degrees of
231
+ freedom. Welch–Satterthwaite is applied as for independent inputs, even when correlations
232
+ are given.
233
+ - Units are stored on each component but not checked.
234
+ - This is a calculation aid, not validated software for regulated use. Check results
235
+ against your own procedures.
236
+
237
+ ## How this was built
238
+
239
+ I designed the analysis and checked the results. I used Claude Code as
240
+ a coding assistant.
241
+
242
+ ---
243
+ Mantas Valantinavičius · measurement scientist, 14 years in ISO/IEC 17025 testing ·
244
+ [github.com/mantas123456](https://github.com/mantas123456)
labqc-0.4.0/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # labqc: laboratory quality calculations in Python
2
+
3
+ [![CI](https://github.com/mantas123456/lab-quality-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/mantas123456/lab-quality-toolkit/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/labqc)](https://pypi.org/project/labqc/)
5
+ [![Docs](https://img.shields.io/badge/docs-online-blue)](https://mantas123456.github.io/lab-quality-toolkit/)
6
+
7
+ The calculations an ISO/IEC 17025 laboratory does every week, usually in spreadsheets,
8
+ written as small, tested Python functions:
9
+
10
+ <!-- --8<-- [start:modules] -->
11
+ | Module | What it covers | Reference |
12
+ |---|---|---|
13
+ | `uncertainty` | GUM uncertainty budgets: Type A and B components, sensitivity coefficients (analytic or numerical), correlated inputs, Welch–Satterthwaite degrees of freedom, coverage factor, relative uncertainty; Monte Carlo propagation | JCGM 100:2008 (GUM), JCGM 101:2008 (GUM S1) |
14
+ | `validation` | Calibration linearity (ordinary or weighted) with confidence intervals and lack-of-fit test, LOD/LOQ, precision (RSD), intermediate precision by ANOVA, spike recovery, trueness against a CRM | ICH Q2, Eurachem guide, ERM Application Note 1 |
15
+ | `proficiency` | z, zeta and E<sub>n</sub> scores with interpretation; robust consensus mean (Algorithm A); z-score history across rounds | ISO 13528, ISO/IEC 17043 |
16
+ | `control_charts` | Shewhart limits; Westgard rules 1<sub>2s</sub>, 1<sub>3s</sub>, 2<sub>2s</sub>, R<sub>4s</sub>, 4<sub>1s</sub>, 10<sub>x</sub>, also across two or three control levels; CUSUM and EWMA charts | Westgard multirule QC; Montgomery, *Introduction to Statistical Quality Control* |
17
+ | `emissions` | ppm ↔ mg/m³ at standard conditions, correction to reference O₂ and its uncertainty, wet ↔ dry, user-defined gases | Stack-emission practice, e.g. EN 303-5 at 10 % O₂ |
18
+
19
+ Every function is tested against hand-calculated values or textbook worked examples (58 tests),
20
+ and the examples below run in CI.
21
+ <!-- --8<-- [end:modules] -->
22
+
23
+ <!-- --8<-- [start:examples] -->
24
+ ## Example 1: uncertainty of a moisture determination
25
+
26
+ Oven-dry moisture of a wood-pellet sample, `M = (m2 − m3) / (m2 − m1) × 100`, with balance
27
+ calibration and resolution for each weighing plus repeatability from five test portions.
28
+ Sensitivity coefficients are found numerically from the model function
29
+ ([`examples/moisture_uncertainty.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/moisture_uncertainty.py)).
30
+
31
+ ```text
32
+ component u_i c_i contribution dof share_of_variance
33
+ Repeatability (5 test portions) 0.0191 1 0.0191 4 0.996
34
+ Weighing m3 0.00104 -0.798 0.00083 inf 0.00188
35
+ Weighing m2 0.00104 0.742 0.000772 inf 0.00162
36
+ Weighing m1 0.00104 0.0556 5.79e-05 inf 9.12e-06
37
+
38
+ u_c = 0.01916, v_eff = 4.0, k = 2.77, U (95%) = 0.05306
39
+ Report: M = 6.97 % ± 0.05 % (k = 2.77, 95 %)
40
+ ```
41
+
42
+ Over 99 % of the variance comes from sample repeatability. A better balance would change
43
+ nothing; more test portions would. With only four degrees of freedom the coverage factor is
44
+ 2.77, not 2, which a fixed "k = 2" spreadsheet gets wrong.
45
+
46
+ ## Example 2: Westgard rules on daily QC
47
+
48
+ Twenty baseline days set the limits. A +1.4 mg/kg shift is introduced from day 45
49
+ ([`examples/westgard_iqc.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/westgard_iqc.py)).
50
+
51
+ ![Levey-Jennings chart](https://raw.githubusercontent.com/mantas123456/lab-quality-toolkit/main/examples/westgard_chart.png)
52
+
53
+ ```text
54
+ value z status rules
55
+ 27 47.99 -2.817 warning 1_2s
56
+ 45 52.49 4.385 reject 1_2s, 1_3s
57
+ 47 52.09 3.745 reject 1_2s, 1_3s
58
+ 48 51.50 2.798 reject 1_2s, 2_2s
59
+ 50 53.00 5.206 reject 1_2s, 1_3s, 4_1s
60
+ ```
61
+
62
+ Day 27 is a lone 1<sub>2s</sub> warning that needs no action. The shift is caught on its
63
+ first day, and the 2<sub>2s</sub> and 4<sub>1s</sub> rules confirm the error is systematic
64
+ (calibration), not random.
65
+
66
+ ## Example 3: boiler test emissions at reference oxygen
67
+
68
+ ```text
69
+ Measured O2 12.8 %, correction factor 1.346
70
+ CO 310.0 ppm -> 521.3 mg/m3 at 10 % O2 (104% of example limit)
71
+ NO2 118.0 ppm -> 325.9 mg/m3 at 10 % O2
72
+ C3H8 6.5 ppm -> 17.2 mg/m3 at 10 % O2
73
+ ```
74
+
75
+ At high excess air, a raw reading that looks comfortably low can exceed a limit once it is
76
+ corrected to 10 % O₂ ([`examples/boiler_emissions.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/boiler_emissions.py)).
77
+
78
+ ## Example 4: Monte Carlo and correlated weighings
79
+
80
+ Version 0.2 adds Monte Carlo propagation (GUM Supplement 1) and correlated inputs
81
+ ([`examples/monte_carlo_vs_gum.py`](https://github.com/mantas123456/lab-quality-toolkit/blob/main/examples/monte_carlo_vs_gum.py)).
82
+
83
+ ```text
84
+ 1. Moisture, M = (m2 - m3) / (m2 - m1) x 100 [%]
85
+ GUM (linear): y = 6.971, u = 0.01916, k = 2.77, 95 % interval [6.918, 7.025]
86
+ Monte Carlo: y = 6.971, u = 0.02704, 95 % interval [6.917, 7.024]
87
+
88
+ 2. Recovery-corrected result, C = C_meas / R [mg/kg]
89
+ GUM (linear): y = 20, u = 3.371, k = 1.96, 95 % interval [13.39, 26.61]
90
+ Monte Carlo: y = 20.61, u = 3.843, 95 % interval [14.15, 28.12]
91
+
92
+ 3. Weighings only (no repeatability), r = 0.92 between weighings
93
+ treated as independent: u = 0.00114 %
94
+ with shared calibration: u = 0.00031 % (-72%)
95
+ ```
96
+
97
+ For the nearly linear moisture model the two 95 % intervals agree. Monte Carlo's u is larger
98
+ only because a 4-dof Type A input is sampled from a t-distribution; the GUM method puts the
99
+ same widening into k = 2.77. Dividing by an uncertain recovery (R = 0.60 ± 0.10) is
100
+ non-linear: the real distribution is skewed upwards, and the first-order interval is too low
101
+ at both ends. When the three weighings share one balance calibration, most of the offset
102
+ cancels, and the balance contribution falls by 72 %.
103
+
104
+ ```python
105
+ from labqc.uncertainty import Component, monte_carlo, propagate
106
+
107
+ inputs = {"a": Component("a", 0.1), "b": Component("b", 0.1)}
108
+ y, r = propagate(lambda a, b: a - b, {"a": 5.0, "b": 2.0}, inputs, correlation={("a", "b"): 0.8})
109
+ print(r.summary(relative=True)) # u_c, k, U and u_c/|y|, U/|y|
110
+ print(monte_carlo(lambda a, b: a / b, {"a": 5.0, "b": 2.0}, inputs, seed=1))
111
+ ```
112
+
113
+ ## New in 0.3: lab methods
114
+
115
+ ```python
116
+ import pandas as pd
117
+ from labqc.validation import intermediate_precision, linearity, trueness
118
+ from labqc.emissions import corrected_uncertainty
119
+
120
+ # weighted calibration with duplicate standards: lack-of-fit test included
121
+ cal = linearity(
122
+ [1, 1, 2, 2, 5, 5, 10, 10], [0.11, 0.10, 0.21, 0.19, 0.52, 0.49, 1.08, 0.97], weights="1/x"
123
+ )
124
+ print(cal.lack_of_fit.p_value) # 0.90: a straight line is adequate
125
+
126
+ # three days x three replicates: repeatability 0.100, intermediate precision 0.224
127
+ days = pd.DataFrame(
128
+ {
129
+ "day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
130
+ "value": [10.1, 10.3, 10.2, 10.6, 10.4, 10.5, 10.0, 10.2, 10.1],
131
+ }
132
+ )
133
+ ip = intermediate_precision(days, "value", "day")
134
+
135
+ # five results on a CRM certified at 50 with u = 0.2
136
+ print(trueness([50.4, 50.7, 49.1, 49.0, 51.1], crm_value=50, crm_u=0.2).passed) # True
137
+
138
+ # CO from Example 3 with u(C) = 8 mg/m3 and u(O2) = 0.2 %: 521 ± 34 mg/m3 (k = 2)
139
+ c_ref, r = corrected_uncertainty(387.4, 8, o2_measured=12.8, u_o2=0.2, k=2)
140
+ ```
141
+
142
+ `pt_history()` reviews a lab's z-scores across PT rounds, and `westgard_levels()`, `cusum()`
143
+ and `ewma()` cover two- and three-level QC and small shifts that Westgard rules miss.
144
+ <!-- --8<-- [end:examples] -->
145
+
146
+ ## Use it
147
+
148
+ ```bash
149
+ pip install labqc
150
+ ```
151
+
152
+ Full documentation, with the API reference for every module:
153
+ [mantas123456.github.io/lab-quality-toolkit](https://mantas123456.github.io/lab-quality-toolkit/).
154
+
155
+ ```python
156
+ from labqc.uncertainty import Component, combine, type_a
157
+ from labqc.proficiency import z_score, classify
158
+
159
+ budget = [
160
+ type_a([10.02, 10.05, 9.98, 10.01, 10.03]),
161
+ Component("Reference standard", 0.010, "normal", k=2),
162
+ Component("Temperature effect", 0.004, "rectangular"),
163
+ ]
164
+ print(combine(budget)) # u_c, v_eff, k, U
165
+
166
+ z = z_score(10.75, assigned=10.0, sigma_pt=0.3)
167
+ print(round(z, 2), classify(z)) # 2.5 questionable
168
+ ```
169
+
170
+ ## Develop
171
+
172
+ ```bash
173
+ pip install -e ".[dev]"
174
+ pytest
175
+ ruff check .
176
+
177
+ pip install -e ".[docs]"
178
+ mkdocs serve # documentation at http://127.0.0.1:8000
179
+ ```
180
+
181
+ Releases: push a tag `v*` (for example `v0.4.0`) that matches the version in
182
+ `pyproject.toml`; GitHub Actions builds the package and publishes it to PyPI.
183
+
184
+ ## Scope and limits
185
+
186
+ - `propagate()` uses first-order sensitivity coefficients. For strongly non-linear models,
187
+ use `monte_carlo()` (GUM Supplement 1) and compare.
188
+ - Monte Carlo handles correlation only between normal inputs with infinite degrees of
189
+ freedom. Welch–Satterthwaite is applied as for independent inputs, even when correlations
190
+ are given.
191
+ - Units are stored on each component but not checked.
192
+ - This is a calculation aid, not validated software for regulated use. Check results
193
+ against your own procedures.
194
+
195
+ ## How this was built
196
+
197
+ I designed the analysis and checked the results. I used Claude Code as
198
+ a coding assistant.
199
+
200
+ ---
201
+ Mantas Valantinavičius · measurement scientist, 14 years in ISO/IEC 17025 testing ·
202
+ [github.com/mantas123456](https://github.com/mantas123456)
@@ -0,0 +1,67 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "labqc"
7
+ version = "0.4.0"
8
+ description = "Laboratory quality calculations: GUM uncertainty budgets, method validation, proficiency-test scores, Westgard rules and flue-gas emission conversions"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Mantas Valantinavičius" }]
14
+ keywords = [
15
+ "metrology",
16
+ "uncertainty",
17
+ "GUM",
18
+ "ISO 17025",
19
+ "quality control",
20
+ "Westgard",
21
+ "method validation",
22
+ "proficiency testing",
23
+ "emissions",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Science/Research",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3 :: Only",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Topic :: Scientific/Engineering",
36
+ "Topic :: Scientific/Engineering :: Chemistry",
37
+ "Typing :: Typed",
38
+ ]
39
+ dependencies = ["numpy>=1.26", "pandas>=2.1", "scipy>=1.11"]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/mantas123456/lab-quality-toolkit"
43
+ Documentation = "https://mantas123456.github.io/lab-quality-toolkit/"
44
+ Source = "https://github.com/mantas123456/lab-quality-toolkit"
45
+ Issues = "https://github.com/mantas123456/lab-quality-toolkit/issues"
46
+ Changelog = "https://github.com/mantas123456/lab-quality-toolkit/blob/main/CHANGELOG.md"
47
+
48
+ [project.optional-dependencies]
49
+ dev = ["pytest>=8", "ruff>=0.5", "matplotlib>=3.8", "build>=1.2", "twine>=6"]
50
+ docs = ["mkdocs>=1.6,<2", "mkdocs-material>=9.5", "mkdocstrings[python]>=0.26"]
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.setuptools.package-data]
56
+ labqc = ["py.typed"]
57
+
58
+ [tool.ruff]
59
+ line-length = 100
60
+ target-version = "py310"
61
+
62
+ [tool.ruff.lint]
63
+ select = ["E", "F", "I", "B", "UP"]
64
+
65
+ [tool.pytest.ini_options]
66
+ testpaths = ["tests"]
67
+ pythonpath = ["src"]
labqc-0.4.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """Calculations for laboratory quality work: uncertainty, validation, PT, IQC, emissions."""
2
+
3
+ from . import control_charts, emissions, proficiency, uncertainty, validation
4
+
5
+ __all__ = ["control_charts", "emissions", "proficiency", "uncertainty", "validation"]
6
+ __version__ = "0.4.0"