-
Notifications
You must be signed in to change notification settings - Fork 18
Add shifting morph #155
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
Add shifting morph #155
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**Added:** | ||
|
||
* Shifting morph for vertical and horizontal shifts. | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
|
||
|
||
import os | ||
|
||
import numpy | ||
import pytest | ||
|
||
from diffpy.pdfmorph.morphs.morphshift import MorphShift | ||
|
||
# useful variables | ||
thisfile = locals().get("__file__", "file.py") | ||
tests_dir = os.path.dirname(os.path.abspath(thisfile)) | ||
# testdata_dir = os.path.join(tests_dir, 'testdata') | ||
|
||
|
||
class TestMorphShift: | ||
@pytest.fixture | ||
def setup(self): | ||
self.hshift = 2.0 | ||
self.vshift = 3.0 | ||
|
||
# Original dataset goes from 0.1 to 5.0 | ||
self.x_morph = numpy.arange(0.01, 5 + self.hshift, 0.01) | ||
self.y_morph = numpy.arange(0.01, 5 + self.hshift, 0.01) | ||
|
||
# New dataset is moved to the right by 2.0 and upward by 3.0 | ||
self.x_target = numpy.arange(0.01 + self.hshift, 5 + self.hshift, 0.01) | ||
self.y_target = numpy.arange(0.01 + self.vshift, 5 + self.vshift, 0.01) | ||
return | ||
|
||
def test_morph(self, setup): | ||
"""check MorphScale.morph()""" | ||
config = {"hshift": self.hshift, "vshift": self.vshift} | ||
morph = MorphShift(config) | ||
|
||
x_morph, y_morph, x_target, y_target = morph(self.x_morph, self.y_morph, self.x_target, self.y_target) | ||
|
||
# Only care about the shifted data past the shift | ||
# Everything to left of shift is outside our input data domain | ||
assert numpy.allclose(y_morph[x_morph > self.hshift], y_target) | ||
assert numpy.allclose(self.x_target, x_target) | ||
assert numpy.allclose(self.y_target, y_target) | ||
return | ||
|
||
|
||
# End of class TestMorphScale | ||
|
||
if __name__ == "__main__": | ||
TestMorphShift() | ||
|
||
# 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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code ensures that the vertical/horizontal shifts can be done independent of each other. We can also create two classes: MorphHShift and MorphVShift, but I feel that is overkill.