-
Notifications
You must be signed in to change notification settings - Fork 21
Improve wsinterp
docstrings and test function
#221
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ec44dc
Rename Diffraction_objects to DiffractionObject in README
bobleesj 4fa614f
Import numpy as np, remove end of line, improve docstring
bobleesj f737a13
Add a period to docstring
bobleesj 83a0c30
Add citation to wsint, remove empty line, add 'the' in docstrings
bobleesj a2f244d
Reword from generating to generate in comment
bobleesj 91594ed
Rerun CI
bobleesj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,3 @@ | |
|
||
# silence the pyflakes syntax checker | ||
assert __version__ or True | ||
|
||
# End of file | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,3 @@ | |
|
||
"""Various utilities related to data parsing and manipulation. | ||
""" | ||
|
||
# End of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,3 @@ def isfloat(s): | |
except ValueError: | ||
pass | ||
return False | ||
|
||
|
||
# End of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,3 @@ | |
from importlib.metadata import version | ||
|
||
__version__ = version("diffpy.utils") | ||
|
||
# End of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,3 @@ | |
|
||
"""Utilities related wx Python GUIs. | ||
""" | ||
|
||
# End of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,3 @@ def _indicesToBlocks(indices): | |
i0 = i | ||
rv = [tuple(ij) for ij in rngs] | ||
return rv | ||
|
||
|
||
# End of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import random | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from diffpy.utils.resampler import wsinterp | ||
|
||
|
||
def test_wsinterp(): | ||
import random | ||
|
||
# Check known points are unchanged by interpolation | ||
# FIXME: if another SW interp function exists, run comparisons for interpolated points | ||
|
||
# Sampling rate | ||
ssr = 44100**-1 # Standard sampling rate for human-hearable frequencies | ||
t = ssr | ||
|
||
# Creating a symmetric set of sample points around zero. | ||
n = 5 | ||
xp = np.array([i * t for i in range(-n, n + 1, 1)]) | ||
x = np.array([i * t for i in range(-n - 1, n + 2, 1)]) | ||
xp = np.array([i * ssr for i in range(-n, n + 1, 1)]) | ||
x = np.array([i * ssr for i in range(-n - 1, n + 2, 1)]) | ||
assert len(xp) == 11 and len(x) == 13 | ||
|
||
# Interpolate a few random datasets | ||
# Generate a new set of fp values across 10 trial runs | ||
trials = 10 | ||
for trial in range(trials): | ||
fp = np.array([random.random() * ssr for i in range(-n, n + 1, 1)]) | ||
|
||
for _ in range(trials): | ||
# Create random function values (fp) at the points defined in xp above | ||
fp = np.array([random.random() * ssr for _ in range(-n, n + 1, 1)]) | ||
fp_at_x = wsinterp(x, xp, fp) | ||
|
||
# Check that the known points are unchanged by interpolation | ||
assert np.allclose(fp_at_x[1:-1], fp) | ||
for i in range(len(x)): | ||
assert fp_at_x[i] == pytest.approx(wsinterp(x[i], xp, fp)) | ||
|
||
|
||
if __name__ == "__main__": | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test_wsinterp() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.