curve_fit error bars: absolute_sigma, the t quantile, and p0=ones
Coverage check with SciPy 1.18.1 (a*exp(-b*x), 12 points, 4000 replicates). With the default absolute_sigma=False, pcov is rescaled by the residual variance, so the CI does not depend on the sigma scale you pass: 92.0% coverage at nominal 95% whether sigma was right, 10x too big or 10x too small. The missing 3% comes from using 1.96 with 10 residual dof: t.ppf(0.975, n-p)=2.228 gives 95.1%. With absolute_sigma=True the CI is right only if sigma is the true noise SD: 95.2% when correct, 100% when 10x too big, 15.8% when 10x too small. Use True only for calibrated measurement errors, and use the t quantile for small n. Also, p0 defaults to all ones: fitting a*sin(c*x) to sin(7x) returned c=1.127, a local minimum, with ier=1 and no warning. Pass a p0 for any oscillatory or exponential model.
Reproduced with SciPy 1.18.1 using my own parameters (the post does not give a, b, the x grid or the noise level): a = 2, b = 0.7, x = linspace(0, 4, 12), noise SD 0.05, 4000 replicates, CI for b. With absolute_sigma=False, coverage was identical for sigma scaled by 1, 10 and 0.1: 92.7% with 1.96 and 95.3% with t.ppf(0.975, 10). With absolute_sigma=True, coverage was 95.6% / 100% / 14.8% with 1.96. One refinement to the last recommendation: the t quantile belongs with absolute_sigma=False, where the variance is estimated from the residuals. With absolute_sigma=True and a correct sigma the variance is known, so 1.96 is right. Using t there over-covers: 97.8% instead of 95.6%. The p0 gotcha also reproduces. On x = linspace(0, 2π, 50), fitting a*sin(c*x) to sin(7x) with default p0 gave a = 0.045, c = 1.745 with ier = 1. The exact local minimum depends on the grid. p0 = [1, 6.8] recovers a = 1, c = 7.
Author: the refinement above is right and my last sentence was too broad. Same setup (a=2, b=0.7, x=linspace(0,4,12), SD 0.05, 4000 reps, default_rng(0), SciPy 1.18.1), CI for b: absolute_sigma=False 92.0% with 1.96, 95.0% with t(10)=2.228; absolute_sigma=True with the true sigma 95.2% with 1.96, 97.3% with t. Corrected rule: the t quantile goes with absolute_sigma=False (variance estimated from n-p residual dof). With absolute_sigma=True the variance is treated as known, so use the normal quantile.