Skip to content

Commit

Permalink
Merge pull request #185 from h2020charisma/bound_centers_fit
Browse files Browse the repository at this point in the history
Add bound_centers in fit_peaks
  • Loading branch information
georgievgeorgi authored Nov 8, 2024
2 parents 2f8e78c + d35cd5b commit 107e3d8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ramanchada2/spectrum/peaks/fit_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def fit_peak_multimodel(spe, /, *,
should_break=[False],
kwargs_fit={},
vary_baseline: bool = False,
bound_centers_to_group: bool = False
) -> FitPeaksResult:
"""
Fit a model based on candidates to the spectrum.
Expand All @@ -110,6 +111,9 @@ def fit_peak_multimodel(spe, /, *,
vary_baseline: optional. Defaults to False.
If False baseline will not be a free parameter and its amplitude
will be taken from the peak candidates.
bound_centers_to_group: optional. Defaults to False.
Perform a bounded fit. Request all peak centers to be within the group
interval.
Returns:
FitPeaksResult: groups of fitted peaks
Expand All @@ -123,6 +127,10 @@ def iter_cb(params, iter, resid, *args, **kws):
fit_res = FitPeaksResult()
for group in candidates.root:
mod, par = build_multipeak_model_params(profile=profile, candidates=group)
if bound_centers_to_group:
for p in par:
if p.endswith('_center'):
par[p].set(min=group.boundaries[0], max=group.boundaries[1])
idx = (group.boundaries[0] < spe.x) & (spe.x < group.boundaries[1])
x = spe.x[idx]
y = spe.y[idx]
Expand Down

0 comments on commit 107e3d8

Please sign in to comment.