Re: [hyperspy-users] Quantification of elements (Cl method) erroring with IndexError: too many indices for array

37 views
Skip to first unread message

Josh Taillon

unread,
Feb 20, 2019, 2:08:48 PM2/20/19
to hypersp...@googlegroups.com
Hi,

If I had to take a quick guess from looking at your code, it looks like the problem is that you calculate line intensities off of the signal computed by `s.sum()`, meaning that your intensity signals have no navigation dimensions. You then call the quantification method on `s`, which means that `s` and `i` will have differing numbers of navigation dimensions, which I think is leading to the error. Either try calculating the intensity maps on just `s` (instead of `s.sum()`), or quantify the signal `s.sum()` to ensure that the dimensions match.

Good luck,
Josh

On Wed, Feb 20, 2019 at 2:02 PM SSQ <sqsha...@gmail.com> wrote:
I'm running in a jupyter notebook (hyperspy 1.4.1) for calculating atomic percent of Mo and S in my sample:

file=folder+'/site 2.rpl' 
s=hs.load(file).as_signal1D(0)

s.axes_manager[-1].name = 'Energy'
s.axes_manager['Energy'].units = 'keV'
s.axes_manager['Energy'].scale = 0.01
s.axes_manager['Energy'].offset = -0.2

s.set_signal_type('EDS_TEM')
s.set_elements(['Mo','S',])
s.set_lines(['Mo_La','S_Ka',])

kf = [2.459, 1.042]              # k-factors for Mo and S
bw = s.estimate_background_windows(line_width=[1.5, 2.0])
i = s.sum().get_lines_intensity(background_windows=bw)
atomic_percent = s.quantification(intensities=i, method='CL',factors=kf)

The error showing below appeared when I ran the last line. Not sure where this error happened and how to correct.  Any insight would be appreciated!

Thanks,

SSQ

  ---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-41-49ec6032779a> in <module>()
      2 bw = s.estimate_background_windows(line_width=[1.5, 2.0])
      3 i = s.sum().get_lines_intensity(background_windows=bw)
----> 4 atomic_percent = s.quantification(intensities=i, method='CL',factors=kf)

C:\Anaconda3\lib\site-packages\hyperspy\_signals\eds_tem.py in quantification(self, intensities, method, factors, composition_units, navigation_mask, closing, plot_result, **kwargs)
    363             composition.data = utils_eds.quantification_cliff_lorimer(
    364                 composition.data, kfactors=factors,
--> 365                 mask=navigation_mask) * 100.
    366         elif method == 'zeta':
    367             results = utils_eds.quantification_zeta_factor(

C:\Anaconda3\lib\site-packages\hyperspy\misc\eds\utils.py in quantification_cliff_lorimer(intensities, kfactors, mask)
    393         if mask is not None:
    394             for i in range(dim[0]):
--> 395                 intens[i][mask] = 0
    396         return intens
    397     else:

IndexError: too many indices for array
 

 
Any insight would be appreciated!

Thanks,

Zack

--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Joshua Taillon

SSQ

unread,
Feb 20, 2019, 2:21:13 PM2/20/19
to hyperspy-users
Hi Josh,

Thanks for your reply!

I tries calculate the intensity just only on 's' and then it gave me an error:

kf = [2.459, 1.042]
bw = s.estimate_background_windows(line_width=[1.5, 2.0])
i = s.get_lines_intensity(background_windows=bw)
atomic_percent = s.quantification(intensities=i, method='CL',factors=kf)

C:\Anaconda3\lib\site-packages\hyperspy\misc\material.py:42: RuntimeWarning: invalid value encountered in true_divide
  atomic_percent[i] /= sum_weight

Here the 'i' is:
[<BaseSignal, title: X-ray line intensity of inter-New-MoS2-2: Mo_La at 2.29 keV, dimensions: (133, 139|)>, <BaseSignal, title: X-ray line intensity of inter-New-MoS2-2: S_Ka at 2.31 keV, dimensions: (133, 139|)>]

Appreciate your suggestion!

Thanks

SSQ

Josh Taillon

unread,
Feb 20, 2019, 3:06:58 PM2/20/19
to hypersp...@googlegroups.com
That looks like a warning, rather than an error. Does your `atomic_percent` contain anything after running those lines of code? My guess is that there's a divide by zero happening somewhere in there that's causing issues. Are there some pixels in your maps that are completely empty, or perhaps the entire map is empty? The methods should be able to handle those situations, but perhaps you're running into a bug. I would try running the quantification on the summed map (`s.sum()`) to see if it works.

Shouqi Shao

unread,
Feb 21, 2019, 7:21:43 AM2/21/19
to hypersp...@googlegroups.com
Hi,

There are few pixels are empty in my map and I tried to select an area without any empty pixel. No errors reported that is good. But I still did not obtain the value of atomic_percent which should be two arrays with dimension:(1|) for Mo and S. What I obtained the atomic_percent are two large arrays: Mo dimensions: (13,31|) ; S dimensions: (13,31|). Both arrays include 403(=13x31) reasonable Mo and S atomic_percent values, i.e. it gives me the atomic_percents for each pixel on the map. Think I could get the atmoic_percent by averaging 403 values in each array for Mo and S. But I would like to know why I can't get that atomic_percent directly?

Thanks for your answers.

SSQ

Josh Taillon

unread,
Feb 21, 2019, 10:12:37 AM2/21/19
to hypersp...@googlegroups.com
If you're looking to get the total quantification over the entire map as one value, you can indeed do as you said (i.e. average over the array), but it might be better to sum the entire map over the navigation dimensions first. I'm not sure what your original dimensions are, but if they're something like (13,31|1000), then you would do something similar to:

file=folder+'/site 2.rpl' 
s=hs.load(file).as_signal1D(0)

s.axes_manager[-1].name = 'Energy'
s.axes_manager['Energy'].units = 'keV'
s.axes_manager['Energy'].scale = 0.01
s.axes_manager['Energy'].offset = -0.2

s.set_signal_type('EDS_TEM')
s.set_elements(['Mo','S',])
s.set_lines(['Mo_La','S_Ka',])

kf = [2.459, 1.042]              # k-factors for Mo and S
s_sum = s.sum((0,1))   # this command sums the original map over the two navigation dimensions 
                                     #so you end up with a one-dimensional (in the energy dimension) spectrum

# do the following quantification commands on the summed spectrum:
bw = s_sum.estimate_background_windows(line_width=[1.5, 2.0])
i = s_sum.get_lines_intensity(background_windows=bw)
atomic_percent = s_sum.quantification(intensities=i, method='CL',factors=kf)

This should give you an atomic_percent list with signals of dimension (|1) (i.e. single-valued). BTW, I would not use a variable named file in your first line. `file` is a keyword in Python, and so overwriting it with a local variable is not considered good practice.

Shouqi Shao

unread,
Feb 21, 2019, 11:00:04 AM2/21/19
to hypersp...@googlegroups.com
Hi Josh,

Thank you so much for days help!

Best regards,
SSQ
Reply all
Reply to author
Forward
0 new messages