forked from spacetelescope/wiimatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spacetelescope#7 from mcara/add-unit-tests
Add unit tests
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
[run] | ||
branch = True | ||
source = wiimatch | ||
|
||
[report] | ||
exclude_lines = | ||
if self.debug: | ||
pragma: no cover | ||
raise NotImplementedError | ||
if __name__ == .__main__.: | ||
ignore_errors = True | ||
omit = | ||
conftest.py | ||
setup.py | ||
tests/* | ||
wiimatch/tests/* |
Empty file.
This file contains 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,78 @@ | ||
""" | ||
A module containing unit tests for the `wcsutil` module. | ||
Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
import pytest | ||
import numpy as np | ||
|
||
from wiimatch import match | ||
|
||
|
||
@pytest.mark.parametrize('solver', ['RLU', 'PINV']) | ||
def test_match_lsq_solver(solver): | ||
# simulate background image data: | ||
c = [1.32, 0.15, 0.62, 0, 0.74, 0, 0, 0] | ||
im1 = np.zeros((5, 5, 4), dtype=np.float) | ||
cbg = c[0] * np.ones_like(im1) # constand background level image | ||
|
||
# add slope: | ||
ind = np.indices(im1.shape, dtype=np.float) | ||
im3 = cbg + c[1] * ind[0] + c[2] * ind[1] + c[4] * ind[2] | ||
|
||
mask = np.ones_like(im1, dtype=np.int8) | ||
sigma = np.ones_like(im1, dtype=np.float) | ||
|
||
p = match.match_lsq( | ||
[im1, im3], [mask, mask], [sigma, sigma], | ||
degree=(1, 1, 1), center=(0, 0, 0), solver=solver | ||
) | ||
|
||
assert np.allclose(-p[0], p[1], rtol=1.e-8, atol=1.e-12) | ||
assert np.allclose(c, 2 * np.abs(p[0]), rtol=1.e-8, atol=1.e-12) | ||
|
||
|
||
def test_match_lsq_extended_return(): | ||
# simulate background image data: | ||
c = [1.32, 0.15, 0.62, 0, 0.74, 0, 0, 0] | ||
im1 = np.zeros((5, 5, 4), dtype=np.float) | ||
cbg = c[0] * np.ones_like(im1) # constand background level image | ||
|
||
# add slope: | ||
ind = np.indices(im1.shape, dtype=np.float) | ||
im3 = cbg + c[1] * ind[0] + c[2] * ind[1] + c[4] * ind[2] | ||
|
||
mask = np.ones_like(im1, dtype=np.int8) | ||
sigma = np.ones_like(im1, dtype=np.float) | ||
|
||
p, a, b, coord_arrays, eff_center, coord_system = match.match_lsq( | ||
[im1, im3], [mask, mask], [sigma, sigma], | ||
degree=1, center=(0, 0, 0), ext_return=True | ||
) | ||
|
||
assert np.allclose(-p[0], p[1], rtol=1.e-8, atol=1.e-12) | ||
assert np.allclose(c, 2 * np.abs(p[0]), rtol=1.e-8, atol=1.e-12) | ||
|
||
|
||
@pytest.mark.parametrize('degree', [1, (1, 1, 1)]) | ||
def test_match_lsq_num_degree(degree): | ||
# simulate background image data: | ||
c = [1.32, 0.15, 0.62, 0, 0.74, 0, 0, 0] | ||
im1 = np.zeros((5, 5, 4), dtype=np.float) | ||
cbg = c[0] * np.ones_like(im1) # constand background level image | ||
|
||
# add slope: | ||
ind = np.indices(im1.shape, dtype=np.float) | ||
im3 = cbg + c[1] * ind[0] + c[2] * ind[1] + c[4] * ind[2] | ||
|
||
mask = np.ones_like(im1, dtype=np.int8) | ||
sigma = np.ones_like(im1, dtype=np.float) | ||
|
||
p = match.match_lsq( | ||
[im1, im3], [mask, mask], [sigma, sigma], | ||
degree=degree, center=(0, 0, 0), solver='RLU', ext_return=False | ||
) | ||
|
||
assert np.allclose(-p[0], p[1], rtol=1.e-8, atol=1.e-12) | ||
assert np.allclose(c, 2 * np.abs(p[0]), rtol=1.e-8, atol=1.e-12) |
This file contains 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,32 @@ | ||
""" | ||
A module containing unit tests for the `wcsutil` module. | ||
Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
import pytest | ||
import numpy as np | ||
|
||
from wiimatch import utils | ||
|
||
|
||
def test_utils_coordinates(): | ||
image_shape = (3, 5, 4) | ||
center = (0, 0, 0) | ||
c = utils.create_coordinate_arrays(image_shape, center=center) | ||
ind = np.indices(image_shape, dtype=np.float)[::-1] | ||
|
||
assert np.allclose(c[0], ind, rtol=1.e-8, atol=1.e-12) | ||
assert np.allclose(c[1], center, rtol=1.e-8, atol=1.e-12) | ||
|
||
|
||
def test_utils_coordinates_no_center(): | ||
image_shape = (3, 5, 4) | ||
c = utils.create_coordinate_arrays(image_shape, center=None) | ||
ind = np.indices(image_shape, dtype=np.float)[::-1] | ||
|
||
center = tuple(i // 2 for i in image_shape) | ||
for orig, cc, i in zip(center, c[0], ind): | ||
assert(i - orig, cc) | ||
|
||
assert np.allclose(c[1], center, rtol=1.e-8, atol=1.e-12) |