Skip to content
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

Initial QOIs #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 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
89 changes: 89 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,90 @@ def inner(x, *args, **kwargs):
return func(*args, **kwargs)

return inner


def max_value(g):
"""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

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

Choose a reason for hiding this comment

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

I'm not certain we need this function if it is only calling len on an array

"""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):
Copy link
Member

Choose a reason for hiding this comment

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

Can we also compute the complete pearson correction? (Maybe as a separate function?)

Copy link
Author

Choose a reason for hiding this comment

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

I think I may be confused on the stats here, to my knowledge the pearson's coefficients can be used on two different datasets. Is there a separate coefficient to compare a dataset to an entire group of datasets.

Copy link
Member

Choose a reason for hiding this comment

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

You could return the list of pearson's coefficents for the new pdf and all the prior pdfs

Copy link
Member

Choose a reason for hiding this comment

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

@Sasaank poke

Copy link
Author

Choose a reason for hiding this comment

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

pushed this into the other pr

Copy link
Member

Choose a reason for hiding this comment

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

ah ok

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