-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add centroid functionality #168
Conversation
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 12 +1
Lines 503 545 +42
=========================================
+ Hits 503 545 +42
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
For a cleaner history, could you squash all the |
Nice functionality! I added a few first comments after having a quick look. Do you have an idea, why the azure pipelines are failing? As it is implemented (with a sum), the function works for uniform data axes only! That should be documented/checked. Alternatively, implement a version for non-uniform axes? |
I have now added all your feedback. |
fix slicing fix test errors
modify tests fix documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In HyperSpy, there is a find_peak_ohaver
and I think that it would be useful to merge it with the function of this PR into a generic find_peak()
, where method could be center_of_mass
or ohaver
?
I am well aware of |
I'll try to find some time to test it on some data the next days. |
Thanks @jordiferrero for this great work. Just tried it on a sample dataset, which is as if it was made for this functionality. And it works both for wavelength and energy axis. When the Jacobian is deactivated, the results in wavelength and energy range agree, as they should. When the Jacobian is activated, there is a notable shift of the value in energy (when back-converted to wavelength). As for fitting, these kind of routines should be performed in the energy scale! And we should add a note to the user guide (by the way, we still have to write the corresponding paragraph in the fitting chapter of the user guide, it is still a todo-note). Apart from this note and the minor comments above (mainly about formatting in rest format and docstrings), this PR is ready to be merged in my view. I'm happy to do so once the last things are done. However, being at it we should also create a corresponding maximum function that finds the maximum of a peak - e.g. by taking the first derivative and then finding zero-crossings. |
I think both approaches are valid and subjective and in this kind of situation, I would favour the approach which provide the simplest and more consistent API. Once thing that I find inconvenient is to have functions or methods which does similar things because it makes the namespace more busy and quite often it is not obvious to figure out what are the difference between them. |
I am not so sure about this.
So I tend to opt for the separate implementation. Edit: One could call it |
|
||
Parameters | ||
------- | ||
slice : tuple (2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In HyperSpy this parameter is in fact called signal_range
, see e.g. remove_background, and we should be consistent there. HyperSpy allows for "interactive" slicing, which would be a worthwile addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the name of the parameter to match the standards.
However, adding an "interactive" functionality would require a significant amount of extra coding I don't think would be worth it. If you still think it is necessary, we can delay this PR more and I can attempt to add it in the future. I'd simply leave it as is and maybe add it in the future as an additional feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, lets keep it as a potential future feature. Just noticed that similar HyperSpy functions have that option - though I personally do not tend to use it much, I know some other people might appreciate.
I am fine with both approaches - I am just being annoying to keep namespace and API tidy! :) |
I have now implemented the small formatting you requested. I have also moved the documentation to the signals page. |
Thanks @jordiferrero for this nice feature. I corrected a little more formatting, mainly in the documentation before merging. |
Description of the change
Added a centroid/center of mass functionality to analyze spectra.
com
utilitycentroid
method in theLumiSpectrum
classProgress of the PR
Minimal example of the new feature