|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | + |
| 4 | +import os |
| 5 | + |
| 6 | +import numpy |
| 7 | +import pytest |
| 8 | + |
| 9 | +from diffpy.pdfmorph.morphs.morphshift import MorphShift |
| 10 | + |
| 11 | +# useful variables |
| 12 | +thisfile = locals().get("__file__", "file.py") |
| 13 | +tests_dir = os.path.dirname(os.path.abspath(thisfile)) |
| 14 | +# testdata_dir = os.path.join(tests_dir, 'testdata') |
| 15 | + |
| 16 | + |
| 17 | +class TestMorphShift: |
| 18 | + @pytest.fixture |
| 19 | + def setup(self): |
| 20 | + self.hshift = 2.0 |
| 21 | + self.vshift = 3.0 |
| 22 | + |
| 23 | + # Original dataset goes from 0.1 to 5.0 |
| 24 | + self.x_morph = numpy.arange(0.01, 5 + self.hshift, 0.01) |
| 25 | + self.y_morph = numpy.arange(0.01, 5 + self.hshift, 0.01) |
| 26 | + |
| 27 | + # New dataset is moved to the right by 2.0 and upward by 3.0 |
| 28 | + self.x_target = numpy.arange(0.01 + self.hshift, 5 + self.hshift, 0.01) |
| 29 | + self.y_target = numpy.arange(0.01 + self.vshift, 5 + self.vshift, 0.01) |
| 30 | + return |
| 31 | + |
| 32 | + def test_morph(self, setup): |
| 33 | + """check MorphScale.morph()""" |
| 34 | + config = {"hshift": self.hshift, "vshift": self.vshift} |
| 35 | + morph = MorphShift(config) |
| 36 | + |
| 37 | + x_morph, y_morph, x_target, y_target = morph(self.x_morph, self.y_morph, self.x_target, self.y_target) |
| 38 | + |
| 39 | + # Only care about the shifted data past the shift |
| 40 | + # Everything to left of shift is outside our input data domain |
| 41 | + assert numpy.allclose(y_morph[x_morph > self.hshift], y_target) |
| 42 | + assert numpy.allclose(self.x_target, x_target) |
| 43 | + assert numpy.allclose(self.y_target, y_target) |
| 44 | + return |
| 45 | + |
| 46 | + |
| 47 | +# End of class TestMorphScale |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + TestMorphShift() |
| 51 | + |
| 52 | +# End of file |
0 commit comments