Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion xpdtools/pipelines/qoi.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -29,3 +30,10 @@

pdf_argrelmax_kwargs = pdf_peaks.upstreams[0].kwargs
mean_argrelmax_kwargs = mean_peaks.upstreams[0].kwargs

Copy link
Member

Choose a reason for hiding this comment

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

This seems like a lot of extra lines, can we reduce it down to 1?







84 changes: 84 additions & 0 deletions xpdtools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -581,3 +583,85 @@ def inner(x, *args, **kwargs):
return func(*args, **kwargs)

return inner


def max_value(g, r):
Copy link
Member

Choose a reason for hiding this comment

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

Why does this take in r? It doesn't seem to be used.

"""Returns largest value
Copy link
Member

Choose a reason for hiding this comment

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

This is not so helpful. Bear in mind what the docstring is for. It is for a user to understand what this function is for and how it should be used. Also, the docstring shouldn't include the function name, which is effectively what your's does.

In other words, why do we (or rather a user) need this function (rather than just typing np.amax())?


Parameters
----------
g : ndarray g(r) of the pdf
Copy link
Member

Choose a reason for hiding this comment

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

ndarray and the description need to be on different lines eg

g : ndarray
    g(r) of the pdf

Copy link
Member

Choose a reason for hiding this comment

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

does this function only work for a PDF?

Copy link
Author

Choose a reason for hiding this comment

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

The functions should work for any 2 variable data. I assumed the inputs were pdfs because the end goal. Would it be better to make this more general (x,y instead of r,g)?

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 x, y would be better. You might identify x and y as independent and dependent variables.

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
Copy link
Member

Choose a reason for hiding this comment

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

This has too many indents. Parameters should be on the same indentation as the description line.

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