diff --git a/notebook/Effect of pre-smoothing.ipynb b/notebook/Effect of pre-smoothing.ipynb index a7ad7ad627fa884b0e5a108e0161f158a0858fdf..bf4e1adb351de8177c2b04bde3114dcbd4bf7ecb 100644 --- a/notebook/Effect of pre-smoothing.ipynb +++ b/notebook/Effect of pre-smoothing.ipynb @@ -3746,7 +3746,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/notebook/Toy resolution.ipynb b/notebook/Toy resolution.ipynb index 63cea2bba69e4e7491d4276d2ee4a1905917216a..1c04c6058c9262105d1ca21468f1efa8310040fa 100644 --- a/notebook/Toy resolution.ipynb +++ b/notebook/Toy resolution.ipynb @@ -2680,7 +2680,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.10.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/pes_to_spec/model.py b/pes_to_spec/model.py index 88f3d7822fd6ba5cb5cd53b57e9b2ddc5ef90d82..f28740905aebffa41c7215fb7973e5a823d3942a 100644 --- a/pes_to_spec/model.py +++ b/pes_to_spec/model.py @@ -263,8 +263,13 @@ def get_resolution(y: np.ndarray, y_hat: np.ndarray, e: np.ndarray, results["e_axis"] = e_axis results["fwhm"] = fwhm(e_axis, results["h"]) results["std"] = np.sqrt(np.sum(results["h"]*e_axis**2)/np.sum(results["h"])) - results["fit"] = fit_gaussian(e_axis, results["h"]) - results["fit_success"] = results["fit"].covar is not None + results["fit"] = None + results["fit_success"] = False + try: + results["fit"] = fit_gaussian(e_axis, results["h"]) + results["fit_success"] = results["fit"].covar is not None + except ValueError: + pass return results class PromptNotFoundError(Exception): @@ -1167,7 +1172,6 @@ class Model(TransformerMixin, BaseEstimator): # get average resolution result = get_resolution(y, y_hat, e) - #self.resolution = np.exp(result["fit"].best_values["log_sigma"])*2.355 if result["fit_success"] else -1.0 self.resolution = result["fwhm"] self.snr = result["snr"] print(f"Resolution = {self.resolution:.2f} eV, S/R = {self.snr:.2f}") @@ -1218,8 +1222,8 @@ class Model(TransformerMixin, BaseEstimator): width += [np.exp(result["fit"].best_values["log_sigma"])*2.355] width_unc += [np.sqrt(result["fit"].covar[2,2])*2.355] else: - width += [np.nan] - width_unc += [np.nan] + width += [result["fwhm"]] + width_unc += [0] width = np.array(width) width_unc = np.array(width_unc) self.resolution_per_energy = width