uncertainty-and-units

Propagate measurement uncertainty and validate physical units in scientific calculations using pint and uncertainties.

41.1k|3.8k|Updated Oct 19, 2025
One-click install
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills --skill uncertainty-and-units
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: uncertainty-and-units
Source: https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/uncertainty-and-units
Command: npx skills add https://github.com/K-Dense-AI/scientific-agent-skills --skill uncertainty-and-units

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pint, uncertainties, numpy, scipy, and includes scripts (resource) and references (resource) components.

What problem does it solve?

Scientific calculations silently produce wrong results when units are stripped mid-computation, correlations between inputs are discarded, or uncertainty is propagated through a linearization that was never validated. This Skill enforces correct unit handling and GUM-compliant uncertainty propagation so reported numbers carry defensible error bars.

Core Features & Use Cases

  • Uncertainty Propagation: Runs both the GUM linear framework and Monte Carlo simulation on the same measurement model, applying the JCGM 101 clause 8 validation test to decide which result may be reported.
  • GUM Uncertainty Budgets: Combines Type A and Type B components with correct distribution divisors, Welch-Satterthwaite effective degrees of freedom, and t-distribution coverage factors.
  • Unit Conversion with Context: Converts between units including spectroscopy and chemistry contexts (wavelength to photon energy, mass to moles), carrying uncertainty through reciprocal conversions.
  • Static Code Auditing: Scans Python analysis code for silent defects like stripped .magnitude calls, curve_fit without absolute_sigma=True, and destroyed correlations.
  • Physical Plausibility Checks: Evaluates 14 dimensionless groups (Reynolds, Peclet, Biot, Womersley) and compares quantities against curated observed magnitude bands.
  • Use Case: A researcher measuring density from mass, diameter, and height inputs gets a full uncertainty budget with sensitivity coefficients, effective degrees of freedom, coverage factor, and a Monte Carlo cross-check in one command.

Quick Start

Ask the agent to propagate uncertainty for a density calculation with mass 250.0 ± 0.05 g, diameter 20.0 ± 0.02 mm, and height 40.0 ± 0.05 mm, and report the result with a 95% expanded uncertainty.

Frequently Asked Questions about uncertainty-and-units

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I propagate uncertainty through a calculation in Python?

Use the uncertainties package to define inputs with ufloat and let it apply linear error propagation automatically. For nonlinear models or large relative uncertainties, run Monte Carlo propagation alongside and apply the JCGM 101 clause 8 comparison to decide which result to report.

How do I convert units with pint in Python?

Create a UnitRegistry, attach units to values, and convert with .to() or .m_as(). For conversions needing physical context like wavelength to photon energy, use pint contexts such as spectroscopy, and never extract raw numbers with .magnitude without naming the target unit.

When should I use Monte Carlo instead of the GUM uncertainty framework?

Use Monte Carlo when the model is nonlinear across ±2 standard uncertainties of an input, when relative uncertainty exceeds about 20%, when inputs follow rectangular or other non-normal distributions, or when the output is bounded below like a squared quantity or variance.

Why does curve_fit give wrong parameter uncertainties in SciPy?

scipy.optimize.curve_fit rescales the covariance matrix by the reduced chi-square unless you pass absolute_sigma=True. When sigma contains real standard uncertainties rather than relative weights, omitting absolute_sigma=True silently inflates or deflates parameter uncertainties.

What coverage factor should I use for expanded uncertainty?

Choose k from the effective degrees of freedom computed with the Welch-Satterthwaite formula, using the Student-t distribution at your coverage probability. The habitual k = 2 is only defensible when effective degrees of freedom are large; small dof requires a larger k.

Does this Skill require network access or external services?

No, all bundled command-line tools run entirely offline with local files only. They reject URLs and symlinks, bound input sizes, and physical constants come from scipy.constants at run time rather than any remote service.