Utilities and I/O

These helpers are part of the public surface for loading data, combining series, and propagating uncertainties.

Data loading helpers

labfit.io.load_csv(path, x_col='x', y_col='y', y_err_col=None, *, default_fraction: float = 0.05, error_mode: str = 'auto', label: str = '') DataSeries[source]
labfit.io.load_txt(path, x_col='x', y_col='y', y_err_col=None, *, default_fraction: float = 0.05, error_mode: str = 'auto', label: str = '') DataSeries[source]
labfit.io.combine_series(*series: DataSeries | Dataset | Iterable[DataSeries]) Dataset[source]

Uncertainty helpers

labfit.utils.propagate_errors(func: Callable, jacobian=None, covariance=None, **params)[source]

Propagate parameter uncertainties through a function.

Given a function func and its parameters with associated uncertainties, compute the output value and its propagated uncertainty using the standard first-order (linear) formula:

\[\sigma_y = \sqrt{\mathbf{J} \, \Sigma \, \mathbf{J}^T}\]

where \(\mathbf{J}\) is the Jacobian of func with respect to the parameters and \(\Sigma\) is their covariance matrix.

Parameters:
  • func (callable) – The function to evaluate. Called as func(**value_params) where value_params excludes any <name>_error / <name>_sigma keywords.

  • jacobian (callable, optional) – Function returning the partial derivatives of func with respect to each parameter, called as jacobian(**value_params). If omitted, a central-difference numerical Jacobian is used (requires covariance to be provided).

  • covariance (array-like, optional) – Full covariance matrix of the parameters. If omitted, a diagonal covariance is constructed from <name>_error or <name>_sigma keywords passed as **params.

  • **params – Parameter values and their uncertainties. For each parameter x, pass x=... and optionally x_error=... or x_sigma=....

Returns:

(value, uncertainty) – The function output and its propagated 1-σ uncertainty.

Return type:

tuple of float

Raises:

ValueError – If jacobian is None and covariance is None (cannot compute a numerical Jacobian without knowing the parameter count).

labfit.utils.effective_sigma(sigma=None, sigma_low=None, sigma_high=None, sigma_cov=None)[source]