Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion xpdtools/pipelines/qoi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from toolz import get

from xpdtools.tools import avg_curvature

def max_intensity_mean(mean, q, **kwargs):
q_at_mean_max = (
Expand All @@ -21,6 +21,13 @@ def max_gr_mean(pdf, **kwargs):
return locals()


def fluc_high_q(iq_comp, high_q_val=45, **kwargs):
Copy link
Member

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.

q = iq_comp.pluck(0)
iq = iq_comp.pluck(1)
high_q_fluc = avg_curvature(iq, q, high_q_val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might use the q and mean and combine them, see: https://github.com/xpdAcq/xpdtools/blob/master/xpdtools/pipelines/raw_pipeline.py#L340
This needs to run through a starmap.

return locals()


"""
r = pdf.pluck(0)
true_pdf = pdf.pluck(1)
Expand Down
11 changes: 11 additions & 0 deletions xpdtools/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
generate_map_bin,
generate_binner,
move_center,
avg_curvature,
)
from xpdtools.jit_tools import mask_ring_median, mask_ring_mean

Expand Down Expand Up @@ -131,3 +132,13 @@ def test_move_center():
g2 = move_center(m, geo)
for mm, n in zip(m, ["poni1", "poni2"]):
assert getattr(g2, n) == getattr(geo, n) + mm


def test_avg_curvature():
t = np.linspace(0,20*np.pi, 100)

def damp_sin(t, damp_coef):
return 5 * np.sin(t)*np.e**(-damp_coef*t)

assert avg_curvature(damp_sin(t, .05), t, 40) \
< avg_curvature(damp_sin(t, .03), t, 40)
27 changes: 27 additions & 0 deletions xpdtools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,30 @@ 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 past a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

past -> beyond

(currently) user provided high Q value, this will be used as the scalar
Copy link
Member

Choose a reason for hiding this comment

The 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))