Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CL Quant Error #2681

Merged
merged 7 commits into from Mar 17, 2021
Merged

Conversation

k8macarthur
Copy link
Contributor

Previously the following code would produce different composition values in the EDX quantification.

import hyperspy.api as hs
import numpy as np
def get_composition(intensities, xray_lines, kfactors, thickness):
    spc = hs.signals.EDSTEMSpectrum(np.array([0]))
    signals = []
    for index, intensity in enumerate(intensities):
        signal = hs.signals.BaseSignal(np.array([intensity]))
        signal.metadata.add_node('Sample')
        xray_line = xray_lines[index]
        element = xray_line[:-3]
        signal.metadata.Sample.elements = [element]
        signal.metadata.Sample.xray_lines = [xray_line]
        signals.append(signal)
        
    results = spc.quantification(intensities=signals, method='CL', factors=kfactors, absorption_correction=True, thickness=thickness)
    atomic_percents = [result.data[0] for result in results[0]]
    return atomic_percents

get_composition([1000, 180], ['Al_Ka', 'N_Ka'], [1.040, 2.547], 100)

get_composition([180, 1000], ['N_Ka', 'Al_Ka'], [2.547, 1.040], 100)

This pull request aims to fix that and add a unit test to check for this error in the future.

@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #2681 (0d0ee4c) into RELEASE_next_patch (4d6e0ed) will increase coverage by 0.35%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                  Coverage Diff                   @@
##           RELEASE_next_patch    #2681      +/-   ##
======================================================
+ Coverage               76.30%   76.66%   +0.35%     
======================================================
  Files                     202      201       -1     
  Lines                   29641    29666      +25     
  Branches                 6473     6495      +22     
======================================================
+ Hits                    22619    22743     +124     
+ Misses                   5238     5168      -70     
+ Partials                 1784     1755      -29     
Impacted Files Coverage Δ
hyperspy/misc/eds/utils.py 86.09% <100.00%> (ø)
hyperspy/_components/skew_normal.py 88.77% <0.00%> (-0.95%) ⬇️
hyperspy/misc/test_utils.py 88.13% <0.00%> (-0.38%) ⬇️
hyperspy/_components/lorentzian.py 97.05% <0.00%> (-0.35%) ⬇️
hyperspy/_components/gaussian.py 97.10% <0.00%> (-0.27%) ⬇️
hyperspy/misc/eels/tools.py 41.61% <0.00%> (-0.25%) ⬇️
hyperspy/io_plugins/protochips.py 95.34% <0.00%> (-0.08%) ⬇️
hyperspy/model.py 80.33% <0.00%> (ø)
hyperspy/samfire.py 64.10% <0.00%> (ø)
hyperspy/component.py 85.02% <0.00%> (ø)
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d6e0ed...0d0ee4c. Read the comment docs.

Copy link
Member

@ericpre ericpre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix! This looks good, except one comment. It would be good to add a test covering the line highlighted by the codecov annotation.

hyperspy/misc/eds/utils.py Outdated Show resolved Hide resolved
@ericpre ericpre merged commit d4d3dcb into hyperspy:RELEASE_next_patch Mar 17, 2021
@ericpre
Copy link
Member

ericpre commented Mar 17, 2021

Corresponding discussion on https://gitter.im/hyperspy/hyperspy?at=60509e66e8267a46f21b103b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants