diff --git a/xpdtools/pipelines/qoi.py b/xpdtools/pipelines/qoi.py index 71dea82..dd9adc1 100644 --- a/xpdtools/pipelines/qoi.py +++ b/xpdtools/pipelines/qoi.py @@ -1,6 +1,7 @@ import scipy.signal as sig - +import numpy as np from .raw_pipeline import mean, pdf, q +from bluesky.callbacks import LivePlot r = pdf.pluck(0) true_pdf = pdf.pluck(1) diff --git a/xpdtools/tools.py b/xpdtools/tools.py index 7f8a6f5..6dfdd3b 100644 --- a/xpdtools/tools.py +++ b/xpdtools/tools.py @@ -17,6 +17,8 @@ import numpy as np from scipy.integrate import simps +import scipy.stats as stats +import scipy.signal as sig 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 @@ -581,3 +583,90 @@ def inner(x, *args, **kwargs): return func(*args, **kwargs) return inner + + +def max_value(g): + """Returns largest value + + Parameters + ---------- + g : ndarray + g(r) of the pdf + + Returns + ------- + float : + Maximum g value + + """ + return np.amax(g) + + +def tallest_peak(g, r): + """Returns r,g(r) of the tallest peak + + Parameters + ---------- + g : ndarray + g(r) of the pdf + + r : ndarray + corresponding r values + + Returns + ------- + float : + r value of the tallest peak + float : + g(r) value of the tallest peak + + """ + peaks = sig.find_peaks(g) + height = [] + r_val = [] + for i in peaks[0]: + height.append(g[i]) + r_val.append(r[i]) + return r_val[np.argmax(height)], np.amax(height) + + +def total_counts(g): + """Returns total number of data points in graph + + Parameters + ---------- + g : ndarray + g(r) of the pdf + + Returns + ------- + int : + total number of data points + + """ + return len(g) + + +def average_pearson(group, g, r): + """Computes the average pearson of this PDF with the rest of the group + + Parameters + ---------- + g : ndarray + g(r) of the pdf + + r : ndarray + corresponding r values + group : ndarray + Group of PDFs (PDFs as tuples (g,r)) + Returns + ------- + float : + Average pearson's coefficient + + """ + val = 0 + for i in group: + r, p = stats.pearsonr((g, r), i) + val = val + r + return val/len(group)