hyperspy / exspy

EDS and EELS data analysis with HyperSpy
https://hyperspy.org/exspy
GNU General Public License v3.0
11 stars 10 forks source link

`fit_background` fixes #76

Closed ericpre closed 2 months ago

ericpre commented 3 months ago

Fitting the background in EDS model doesn't work with linear fitting, because the twin lines are disactivated properly when running linear fitting.

import exspy

s = exspy.data.EDS_SEM_TM002()
m = s.isig[5.0:15.0].create_model()
m.plot()
m.fit_background(optimizer="lstsq")

which will raise the following error:

    m.fit_background(optimizer="lstsq")

  File ~\Dev\exspy\exspy\models\edsmodel.py:394 in fit_background
    self.fit(**kwargs)

  File ~\Dev\hyperspy\hyperspy\model.py:1797 in fit
    fit_output = self._linear_fit(

  File ~\Dev\hyperspy\hyperspy\model.py:1217 in _linear_fit
    index = parameters.index(p)

ValueError: <Parameter A of Cu_Ka component> is not in list

Progress of the PR

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.69%. Comparing base (75ca046) to head (88949ab). Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
exspy/models/edsmodel.py 86.95% 1 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #76 +/- ## ========================================== + Coverage 88.62% 88.69% +0.06% ========================================== Files 76 76 Lines 7411 7439 +28 Branches 1192 1197 +5 ========================================== + Hits 6568 6598 +30 + Misses 574 572 -2 Partials 269 269 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.