From 930f7a77792d10024dd8847c6d7fda683f909121 Mon Sep 17 00:00:00 2001 From: Sasaank Bandi Date: Wed, 7 Nov 2018 11:59:58 -0500 Subject: [PATCH 1/3] Initial QOIs --- xpdtools/pipelines/qoi.py | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/xpdtools/pipelines/qoi.py b/xpdtools/pipelines/qoi.py index 71dea82..43be212 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) @@ -29,3 +30,44 @@ pdf_argrelmax_kwargs = pdf_peaks.upstreams[0].kwargs mean_argrelmax_kwargs = mean_peaks.upstreams[0].kwargs + + +def max_value(pdf): + return np.amax(pdf.pluck(1)) + + +def total_counts(pdf): + return len(pdf.pluck(0)) + + +def tallest_peak(pdf): + peaks = sig.find_peaks(pdf.pluck(1)) + height = [] + r_val = [] + for i in peaks[0]: + height.append(pdf.pluck(1)[i]) + r_val.append(pdf.pluck(0)[i]) + return np.amax(r_val), np.amax(height) + +#doesn't quite work yet +def oscillation_behavior(pdf): + def func(x, a, b, c): + return a * np.exp(-b * x) + c + for i in range(len(pdf.pluck(0))): + if pdf.pluck(1)[i] >= 20: + idx = i + break + peaks = sig.find_peaks(pdf.pluck(1)[idx:]) + height = [] + r_val = [] + for i in peaks[0]: + height.append(pdf.pluck(1)[i]) + r_val.append(pdf.pluck(0)[i]) + +highest_value_stream = pdf.map(max_value) +total_counts_stream = pdf.map(total_counts) +tallest_peak_height, tallest_peak_position = pdf.map(tallest_peak) + + + + From 89d011550e60e5c1cd0cc86b85cec48baddf62fb Mon Sep 17 00:00:00 2001 From: Sasaank Bandi Date: Fri, 30 Nov 2018 11:09:24 -0500 Subject: [PATCH 2/3] Initial QOIs --- xpdtools/pipelines/qoi.py | 34 ---------------- xpdtools/tools.py | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 34 deletions(-) diff --git a/xpdtools/pipelines/qoi.py b/xpdtools/pipelines/qoi.py index 43be212..ad7a3cb 100644 --- a/xpdtools/pipelines/qoi.py +++ b/xpdtools/pipelines/qoi.py @@ -32,42 +32,8 @@ mean_argrelmax_kwargs = mean_peaks.upstreams[0].kwargs -def max_value(pdf): - return np.amax(pdf.pluck(1)) -def total_counts(pdf): - return len(pdf.pluck(0)) - - -def tallest_peak(pdf): - peaks = sig.find_peaks(pdf.pluck(1)) - height = [] - r_val = [] - for i in peaks[0]: - height.append(pdf.pluck(1)[i]) - r_val.append(pdf.pluck(0)[i]) - return np.amax(r_val), np.amax(height) - -#doesn't quite work yet -def oscillation_behavior(pdf): - def func(x, a, b, c): - return a * np.exp(-b * x) + c - for i in range(len(pdf.pluck(0))): - if pdf.pluck(1)[i] >= 20: - idx = i - break - peaks = sig.find_peaks(pdf.pluck(1)[idx:]) - height = [] - r_val = [] - for i in peaks[0]: - height.append(pdf.pluck(1)[i]) - r_val.append(pdf.pluck(0)[i]) - -highest_value_stream = pdf.map(max_value) -total_counts_stream = pdf.map(total_counts) -tallest_peak_height, tallest_peak_position = pdf.map(tallest_peak) - diff --git a/xpdtools/tools.py b/xpdtools/tools.py index 7f8a6f5..4472fb2 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,85 @@ def inner(x, *args, **kwargs): return func(*args, **kwargs) return inner + + +def max_value(g, r): + """Returns largest value + + Parameters + ---------- + g : ndarray g(r) of the pdf + r : ndarray of corresponding r values + + 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 of 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,r): + """Returns total number of data points in graph + + Parameters + ---------- + g : ndarray g(r) of the pdf + r : ndarray of corresponding r values + + Returns + ------- + float : + 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 of corresponding r values + group : ndarray 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) From 794fa545ce5f2828b31e9c33253b2570c7b98528 Mon Sep 17 00:00:00 2001 From: Sasaank Bandi Date: Fri, 30 Nov 2018 11:57:54 -0500 Subject: [PATCH 3/3] Initial QOIs-fixed docstring issues --- xpdtools/pipelines/qoi.py | 7 ----- xpdtools/tools.py | 65 +++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/xpdtools/pipelines/qoi.py b/xpdtools/pipelines/qoi.py index ad7a3cb..dd9adc1 100644 --- a/xpdtools/pipelines/qoi.py +++ b/xpdtools/pipelines/qoi.py @@ -30,10 +30,3 @@ pdf_argrelmax_kwargs = pdf_peaks.upstreams[0].kwargs mean_argrelmax_kwargs = mean_peaks.upstreams[0].kwargs - - - - - - - diff --git a/xpdtools/tools.py b/xpdtools/tools.py index 4472fb2..6dfdd3b 100644 --- a/xpdtools/tools.py +++ b/xpdtools/tools.py @@ -585,13 +585,13 @@ def inner(x, *args, **kwargs): return inner -def max_value(g, r): +def max_value(g): """Returns largest value Parameters ---------- - g : ndarray g(r) of the pdf - r : ndarray of corresponding r values + g : ndarray + g(r) of the pdf Returns ------- @@ -602,13 +602,16 @@ def max_value(g, r): return np.amax(g) -def tallest_peak(g,r): +def tallest_peak(g, r): """Returns r,g(r) of the tallest peak Parameters ---------- - g : ndarray g(r) of the pdf - r : ndarray of corresponding r values + g : ndarray + g(r) of the pdf + + r : ndarray + corresponding r values Returns ------- @@ -617,7 +620,7 @@ def tallest_peak(g,r): float : g(r) value of the tallest peak - """ + """ peaks = sig.find_peaks(g) height = [] r_val = [] @@ -627,41 +630,43 @@ def tallest_peak(g,r): return r_val[np.argmax(height)], np.amax(height) -def total_counts(g,r): +def total_counts(g): """Returns total number of data points in graph - Parameters - ---------- - g : ndarray g(r) of the pdf - r : ndarray of corresponding r values - - Returns - ------- - float : - total number of data points + Parameters + ---------- + g : ndarray + g(r) of the pdf + Returns + ------- + int : + total number of data points - """ + """ return len(g) -def average_pearson(group, g,r): +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 of corresponding r values - group : ndarray of PDFs (PDFs as tuples (g,r)) - Returns - ------- - float : - Average pearson's coefficient + 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) + r, p = stats.pearsonr((g, r), i) val = val + r return val/len(group)