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

Plotting func/peak finder #31

Closed
wants to merge 10 commits into from
20 changes: 20 additions & 0 deletions cmeutils/plot_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import scipy.signal as signal


def find_peaks(data):
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
"""Finds peaks in 1-D data.
The peaks are any value greater than the average of all the data values. The data values are 1-D values (like x, y, or z) that you wish to find the peaks of.
Any points/values that excede the max height will be identified as peaks.

Parameters
----------
data : numpy.ndarray, shape (N,1)
Such as x, y, OR z.
Returns
----------
tuple
"""
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
total_peaks = signal.find_peaks(data)
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
avg_peaks = sum(data) / len(data)
peaks = signal.find_peaks(data, height=avg_peaks)
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
return peaks
2 changes: 1 addition & 1 deletion cmeutils/tests/test_dynamics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from cmeutils.tests.base_test import BaseTest
from base_test import BaseTest
from cmeutils.dynamics import msd_from_gsd

class TestDynamics(BaseTest):
Expand Down
17 changes: 17 additions & 0 deletions cmeutils/tests/test_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

import scipy.signal as signal
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import scipy.signal as signal

Here we don't need to import this function because we want to use your find peaks function

import numpy as np

from base_test import BaseTest

from cmeutils.plot_tools import find_peaks

class TestPlot(BaseTest):
def test_plot(self):
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
x = [1,2,3,4,5]
gwenwhite marked this conversation as resolved.
Show resolved Hide resolved
data = np.array(x)
peaks = signal.find_peaks(data)
assert isinstance(data, np.ndarray)
assert isinstance(peaks, tuple)

2 changes: 1 addition & 1 deletion cmeutils/tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import freud

from cmeutils.tests.base_test import BaseTest
Copy link
Member

Choose a reason for hiding this comment

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

Were the tests not working for you without this change? It might be because cmeutils is not installed in your environment or not installed in an editable way? (i.e., pip install -e .) Not sure.

from base_test import BaseTest

from cmeutils.structure import gsd_rdf, get_quaternions, order_parameter, all_atom_rdf, get_centers

Expand Down