From 4319f4e394c91677343467a9f53f8841e91fd24d Mon Sep 17 00:00:00 2001 From: Marco Cammarata Date: Fri, 27 Jan 2017 15:40:26 +0100 Subject: [PATCH] added errorbar weighting and filter for nans and inf --- xray/peaks.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xray/peaks.py b/xray/peaks.py index 3e8224a..a1f42ad 100644 --- a/xray/peaks.py +++ b/xray/peaks.py @@ -1,9 +1,21 @@ import lmfit import numpy as np +import logging as log pv = lmfit.models.PseudoVoigtModel() -def fitPeak(x,y,autorange=False): +def fitPeak(x,y,err=1,autorange=False): + if isinstance(err,np.ndarray): + if np.all(err==0): + err = 1 + log.warn("Asked to fit peak but all errors are zero, forcing them to 1") + elif np.isfinite(err).sum() != len(err): + idx = np.isfinite(err) + x = x[idx] + y = y[idx] + err = err[idx] + log.warn("Asked to fit peak but some errorbars are infinite or nans,\ + excluding those points") if autorange: # find fwhm idx = np.ravel(np.argwhere( y