Closed redoxmatlab closed 8 years ago
That method is working on my end. Can you try the following:
import hyperspy.api as hs
import numpy as np
step = 1E-4
s = hs.signals.Spectrum(np.sin(np.arange(0, 2*np.pi, step)))
s.axes_manager[0].scale = step
s_int = s.integrate_in_range(signal_range=(0, np.pi))
print(s_int.data)
On my system, this returns 2.
, as expected. Is yours doing something different?
As mentioned in the documentation, integrate_in_range
returns a new Signal
instance, so to get the value of it, you need to access its data
field.
Hello, Thanks for your reply. Yes this works fine for me and I get the same result as you. However, I am looking at EELS data., so I need to calculate the area under two peaks of interest. I tried the following:
s1.axes_manager[0].scale = step
s1_int = s1.integrate_in_range(signal_range=(704, 715))
s2_int = s1.integrate_in_range(signal_range=(720, 728))
print(s1_int.data/s2.int.data)
but the result is not right. I wonder what the first line exactly means? Thanks
s1.axes_manager[0].scale = step
was just for my example. Doing this on your data will change the scale of the axis on your data, which I don't think you would want. Furthermore, I don't think that you're taking the range you think you are.
Again, looking at the documentation of the function, it says:
Selecting a range in the axis units, by specifying the signal range with floats.
s_int = s.integrate_in_range(signal_range=(560.,590.))
Selecting a range using the index, by specifying the signal range with integers.s_int = s.integrate_in_range(signal_range=(100,120))
I assume that you want to integrate the Fe-L edges? Since you want to reference your spectrum by eV units, you need to specify signal_range
with floats instead of integer values. Doing so with integers will integrate only from channels 704 to 715, rather than from 704 to 715 eV. Make sense?
I don't mean to offend, but I'll reiterate, this is a pretty basic aspect of HyperSpy, and from #907 it sounds as though you haven't really done a thorough reading of the User's guide. GitHub issues are not the place to ask these sorts of questions, especially since the documentation is there. The folks on the hyperspy-users group are very friendly and will be happy to answer questions there.
Not to worry. I am an absolute beginner in Hyperspy but will forward my future questions to the mailing list instead. Your answer if very helpful, lots of hanks again.
Not a problem! Just want to make sure you're asking your questions in the right place so the right people see them. Since it sounds like this issue and #907 are not development issues, could you please close them (by clicking the 'Close' button to the left of the 'Comment' button below)?
What is the syntax for integrate_simpson()? How to define range? Currently the old s1.integrate_in_range(signal_range=(min, max)) does not work.