From f30426e95d92ec8caa24549b754d68a2250ab230 Mon Sep 17 00:00:00 2001 From: rasmusthog Date: Mon, 10 Oct 2022 17:42:39 +0200 Subject: [PATCH] Add arctan fit function to pre-edge background --- nafuma/xanes/calib.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nafuma/xanes/calib.py b/nafuma/xanes/calib.py index 0e0ff33..cd1ce5d 100644 --- a/nafuma/xanes/calib.py +++ b/nafuma/xanes/calib.py @@ -1125,6 +1125,19 @@ def fit_pre_edge_feautre(data: dict, options={}) -> pd.DataFrame: ] + elif options['background_model'] == 'arctan': + + popt, pcov = curve_fit(arctan, peak_background['ZapEnergy']-data['e0_diff'][filename], peak_background[filename]) + + background = arctan(background_df['ZapEnergy']-data['e0_diff'][filename], *popt) + background_df.insert(1, filename, background) + + + removed_background_df.insert(1, filename, partial_data[filename]-background_df[filename]) + removed_background_df = removed_background_df.loc[(removed_background_df['ZapEnergy'] > options['background_limits'][0][1]) & + (removed_background_df['ZapEnergy'] < options['background_limits'][1][0]) + ] + # Fit Gaussian @@ -1206,6 +1219,10 @@ def fit_pre_edge_feautre(data: dict, options={}) -> pd.DataFrame: def gauss(x, A, mu, sigma): return (A/(sigma*np.sqrt(np.pi)))*np.exp(-(x-mu)**2/(2*sigma**2)) + + +def arctan(x,a,b,c,d): + return a*np.arctan(x*b+c) + d