oscarbranson / latools

Tools for the reproducible reduction of LA-ICPMS data.
http://latools.readthedocs.io
MIT License
15 stars 10 forks source link

`helpers.unitpicker` runs forever when you put zeros #41

Closed sunwillrise closed 5 years ago

sunwillrise commented 5 years ago

Hello.

Sometimes your data arrays only contains only zeros, for various reasons. For example, in my case, there was one part looked like this;

'Te125': array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan, nan,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0., nan, nan, nan, nan, nan, nan, nan, nan, nan,
       nan, nan])

This kind of thing causes trouble for the latools.helpers.helpers.unitpicker() because in its code it says

a = abs(a)
n = 0
if a < llim:
    while a < llim:
        a *= 1000
        n += 1

If a is zero, this loops forever and it doesn't stop. To avoid this, you can change this to

a = abs(a)
n = 0
if a == 0:
    raise ValueError("The value is zero.")
elif a < llim:
    while a < llim:
        a *= 1000
        n += 1

I hope it helps.

sunwillrise commented 5 years ago

You can automatically remove the elements which mean value is 0 by adding this to the code;

self.get_focus(filt=filt, samples=samples, subset=subset)
for a in analytes:
    if np.nanmean(self.focus[a] == 0):
        analytes.remove(a)
        print(a, " removed.")
oscarbranson commented 5 years ago

Hi @sunwillrise,

Thanks for all your useful comments and suggestions. I'll incorporate them all into the next release.

Oscar.