From 1cf9c6ddc8579bdd01b4d0fdaaed780242c0fc60 Mon Sep 17 00:00:00 2001 From: Rolf Verberg Date: Thu, 12 Dec 2024 13:39:17 -0500 Subject: [PATCH] fix: error in fit error msg when using scipy instead of lmfit --- CHAP/edd/processor.py | 3 --- CHAP/utils/fit.py | 8 +++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHAP/edd/processor.py b/CHAP/edd/processor.py index 603c1fd..49fa557 100755 --- a/CHAP/edd/processor.py +++ b/CHAP/edd/processor.py @@ -2362,15 +2362,12 @@ def cost_function_combined( axs[1,1].set_ylabel('Energy (keV)') if calibration_method in ('fix_tth_to_tth_init', 'iterate_tth'): e_fit = e_bragg_fit - e_unconstrained = e_bragg_unconstrained if quadratic_energy_calibration: label = 'Unconstrained: quadratic fit' else: label = 'Unconstrained: linear fit' else: e_fit = np.concatenate((e_xrf, e_bragg_fit)) - e_unconstrained = np.concatenate( - (e_xrf, e_bragg_unconstrained)) if quadratic_energy_calibration: label = 'Quadratic fit' else: diff --git a/CHAP/utils/fit.py b/CHAP/utils/fit.py index 800ec06..4686ce3 100755 --- a/CHAP/utils/fit.py +++ b/CHAP/utils/fit.py @@ -2435,6 +2435,7 @@ def fit(self, config=None, **kwargs): 'maximum allowed number of processors, num_proc reduced to ' f'{num_proc_max}') num_proc = num_proc_max + logger.debug(f'Using {num_proc} processors to fit the data') self._redchi_cutoff *= self._y_range**2 # Setup the fit @@ -2799,7 +2800,12 @@ def _fit(self, n, current_best_values, return_result=False, **kwargs): if par.vary: current_best_values[par.name] = par.value else: - logger.warning(f'Fit for n = {n} failed: {result.lmdif_message}') + errortxt = f'Fit for n = {n} failed' + if hasattr(result, 'lmdif_message'): + errortxt += f'\n\t{result.lmdif_message}' + if hasattr(result, 'message'): + errortxt += f'\n\t{result.message}' + logger.warning(f'{errortxt}') # Renormalize the data and results self._renormalize(n, result)