Skip to content

Commit

Permalink
fix: error in fit error msg when using scipy instead of lmfit
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfverberg committed Dec 12, 2024
1 parent 8ff4554 commit 1cf9c6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 0 additions & 3 deletions CHAP/edd/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion CHAP/utils/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1cf9c6d

Please sign in to comment.