-
Notifications
You must be signed in to change notification settings - Fork 21
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
Gaussian Fitting Tool #116
Conversation
… distribution and fits to three different guassian distributions then returns the fit params in a dictionary
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.
Move fitting tool and test directly into data_analysis.
offset = initial_guess.pop("offset", np.mean(y[-10:])) | ||
amplitude = initial_guess.pop("amplitude", y.max() - offset) | ||
mu = initial_guess.pop("mu", np.argmax(y)) | ||
sigma = initial_guess.pop("sigma", y.shape[0] / 5) |
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.
Maybe reconsider dividing by 5 there
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.
At the moment I don't have a more mathematical approach to determine sigma but it is something I have been thinking about.
@staticmethod | ||
def gaussian_with_linear_background(x, amp, mu, sig, offset, slope): | ||
return ( | ||
amp * np.exp(-np.power(x - mu, 2.0) / (2 * np.power(sig, 2.0))) |
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.
repeated code?
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 the pydantic model version, I was going to make a model the gaussian functions. It would simply this. I can also just edit this code for the initial PR
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.
ok so this will get updated in the next PR?
) + offset | ||
|
||
@staticmethod | ||
def two_dim_gaussian(x, y, A, x0, y0, sigma_x, sigma_y): |
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.
add comment here about possible use with images
tests/unit_tests/lcls_tools/common/data_analysis/fitting/test_fit_gauss.py
Outdated
Show resolved
Hide resolved
tests/unit_tests/lcls_tools/common/data_analysis/fitting/test_fit_gauss.py
Outdated
Show resolved
Hide resolved
@nneveu and I discussed today and I think we should change this to use scipy.minimize instead of scipy.curve_fit before this PR is accepted. @phys-cgarnier let me know if you need help w making this change |
Hi all,
Sorry I was on vacation but was unable to update my status or sign into my email until just now. I will be at the meeting today if that works for everyone.
Best,
Chris.
From: Ryan Roussel ***@***.***>
Date: Monday, November 27, 2023 at 1:57 PM
To: slaclab/lcls-tools ***@***.***>
Cc: Garnier, Chris ***@***.***>, Mention ***@***.***>
Subject: Re: [slaclab/lcls-tools] Gaussian Fitting Tool (PR #116)
@nneveu<https://github.com/nneveu> and I discussed today and I think we should change this to use scipy.minimize instead of scipy.curve_fit before this PR is accepted. @phys-cgarnier<https://github.com/phys-cgarnier> let me know if you need help w making this change
—
Reply to this email directly, view it on GitHub<#116 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A4D45PBXN45ZLTZAPTYUMFLYGUEBZAVCNFSM6AAAAAA7O6PPDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYGY4DKNJXGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@phys-cgarnier I think the load issue might be with the test. If you run the test locally does it load sklearn ok? You might need to import it in the test as well. |
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 wonder if we can use scipy.stats in some places here.
https://docs.scipy.org/doc/scipy/tutorial/stats.html
General comments for next PR, let's try to have fewer inputs without names/dicts and a few more comments.
Thanks for working on this @phys-cgarnier !
param_names = method.__code__.co_varnames | ||
param_names = list(param_names) | ||
for i in range(len(param_names)): | ||
if param_names[i] == "x": |
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.
Why the 'x' here in these two functions?
* initial commit of fitting tool * initial submission of gaussian fit tool, this tool takes a normalized distribution and fits to three different guassian distributions then returns the fit params in a dictionary * reformatted scripts with black * did more reformatting then used black for final check * updated for pr * fixed flake8 errors * fixed flake8 * attempt to fix flake8 errors * hopefully last flake8 fix.... * added sklearn to requirements.txt * changed sklearn to scikit-learn * black on fitting_tool.py --------- Co-authored-by: Nicole <nneveu@stanford.edu>
Initial pull request of gaussian fit tool, this tool receives an array of normalized data and attempts to fit it to three different methods: standard gaussian, super gaussian, and double gaussian. Then returns the fit parameters in a dictionary