-
Notifications
You must be signed in to change notification settings - Fork 10
Fluctuations at High Q values #70
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
base: master
Are you sure you want to change the base?
Changes from all commits
deb2798
a32c3e9
c0f796c
f0d6283
2c72f54
721e492
eb28081
ed1f308
7ca4c8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import numpy as np | ||
|
|
||
| from streamz import collect | ||
| from toolz import get | ||
|
|
||
| from xpdtools.tools import avg_curvature,group_pearson,complete_pearson | ||
|
|
||
| def max_intensity_mean(mean, q, **kwargs): | ||
| q_at_mean_max = ( | ||
|
|
@@ -21,6 +21,13 @@ def max_gr_mean(pdf, **kwargs): | |
| return locals() | ||
|
|
||
|
|
||
| def fluc_high_q(iq_comp, high_q_val=45, **kwargs): | ||
| q = iq_comp.pluck(0) | ||
| iq = iq_comp.pluck(1) | ||
| high_q_fluc = avg_curvature(iq, q, high_q_val) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might use the |
||
| return locals() | ||
|
|
||
|
|
||
| """ | ||
| r = pdf.pluck(0) | ||
| true_pdf = pdf.pluck(1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| import numpy as np | ||
| from scipy.integrate import simps | ||
| import scipy.stats as stats | ||
| from skbeam.core.accumulators.binned_statistic import BinnedStatistic1D | ||
| from skbeam.core.mask import margin | ||
| from xpdtools.jit_tools import mask_ring_median, mask_ring_mean, ring_zscore | ||
|
|
@@ -580,3 +581,81 @@ def inner(x, *args, **kwargs): | |
| return func(*args, **kwargs) | ||
|
|
||
| return inner | ||
|
|
||
|
|
||
| def avg_curvature(y, x, high_val): | ||
| """Computes the average of the curvature of a given signal beyond a | ||
| (currently) user provided high Q value, this will be used as the scalar | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't say what this will be used for. If it is just for that qoi it shouldn't be a separate function. If it has more broad application, it should be its own function but the docstring should just describe what it does. |
||
| representation for fluctuations at high Q values. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| y : ndarray | ||
| Dependent variable of a given signal | ||
| x : ndarray | ||
| Independent variable of a given signal | ||
| high_val : float | ||
| User-defined value start point of analysis. This should remain constant | ||
| over a scan. | ||
|
|
||
| Returns | ||
| ------- | ||
| float : | ||
| The average of curvature beyond a given high_val | ||
|
|
||
| """ | ||
| idx = np.abs(x - high_val).argmin() | ||
| first_der = np.gradient(y[idx:], x[idx:]) | ||
| sec_der = np.gradient(first_der, x[idx:]) | ||
| return np.average(np.abs(sec_der)/(1+first_der**2)**(3/2)) | ||
|
|
||
|
|
||
| def complete_pearson(group, y): | ||
| """ Computes a array of scalars representing the similarity of a given | ||
| dataset to others in a group. This function returns an array of Pearson | ||
| Product-Moment Correlation coefficients corresponding to the inputed dataset | ||
| and every member of the inputed group. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| y : ndarray | ||
| data that is to be compared to rest of the group. | ||
|
|
||
| group : ndarray | ||
| group of data to be compared to. | ||
| Returns | ||
| ------- | ||
| ndarray : | ||
| Array of Pearson's Correlation coefficients, index corresponds to | ||
| the index of group member. | ||
|
|
||
| """ | ||
| pearsons = [] | ||
| for i in group: | ||
| r, p = stats.pearsonr(y, i) | ||
| pearsons.append(r) | ||
| pearsons = np.asarray(pearsons) | ||
| return pearsons | ||
|
|
||
|
|
||
| def group_pearson(group): | ||
| """ This function returns an array of an array of Pearson Product-Moment | ||
| Correlation coefficients corresponding the similarity between members in the | ||
| group. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| group : ndarray | ||
| group of data to be compared. | ||
| Returns | ||
| ------- | ||
| ndarray : | ||
| Array of arrays Pearson's Correlation coefficients, index corresponds to | ||
| index of group member. | ||
|
|
||
| """ | ||
| pearson_list = [] | ||
| for i, x in enumerate(group): | ||
| pearson_list.append(complete_pearson(group, x)) | ||
| pearson_list = np.asarray(pearson_list) | ||
| return pearson_list | ||
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 think this need docstrings.